Update toCOCO.py
This commit is contained in:
		
							parent
							
								
									5678f61bc6
								
							
						
					
					
						commit
						8c6f189d59
					
				@ -40,6 +40,7 @@ class TOCOCO(QThread):
 | 
				
			|||||||
        coco_anno['categories'] = []
 | 
					        coco_anno['categories'] = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        categories_dict = {}
 | 
					        categories_dict = {}
 | 
				
			||||||
 | 
					        uncontained_dict = {}
 | 
				
			||||||
        # categories_dict from isat.yaml, https://github.com/yatengLG/ISAT_with_segment_anything/issues/36
 | 
					        # categories_dict from isat.yaml, https://github.com/yatengLG/ISAT_with_segment_anything/issues/36
 | 
				
			||||||
        yaml_path = os.path.join(self.isat_json_root, 'isat.yaml')
 | 
					        yaml_path = os.path.join(self.isat_json_root, 'isat.yaml')
 | 
				
			||||||
        if os.path.exists(yaml_path):
 | 
					        if os.path.exists(yaml_path):
 | 
				
			||||||
@ -95,6 +96,7 @@ class TOCOCO(QThread):
 | 
				
			|||||||
                        for cat in cats:
 | 
					                        for cat in cats:
 | 
				
			||||||
                            if cat not in categories_dict:
 | 
					                            if cat not in categories_dict:
 | 
				
			||||||
                                categories_dict[cat] = len(categories_dict)
 | 
					                                categories_dict[cat] = len(categories_dict)
 | 
				
			||||||
 | 
					                                uncontained_dict[cat] = len(categories_dict)
 | 
				
			||||||
                            category_index = categories_dict.get(cat)
 | 
					                            category_index = categories_dict.get(cat)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            objs_with_cat = [obj for obj in objs_with_group if obj.get('category', 0) == cat]
 | 
					                            objs_with_cat = [obj for obj in objs_with_group if obj.get('category', 0) == cat]
 | 
				
			||||||
@ -162,6 +164,10 @@ class TOCOCO(QThread):
 | 
				
			|||||||
            except Exception as e:
 | 
					            except Exception as e:
 | 
				
			||||||
                self.message.emit(None, None, 'Error: {}'.format(e))
 | 
					                self.message.emit(None, None, 'Error: {}'.format(e))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if uncontained_dict:
 | 
				
			||||||
 | 
					            for k,i in uncontained_dict.items():
 | 
				
			||||||
 | 
					                self.message.emit(None, None, 'Warning!!! The category [{}] is not contained in isat.yaml. Add it by id {}.'.format(k, i))
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        self.message.emit(None, None, '*** Finished! ***')
 | 
					        self.message.emit(None, None, '*** Finished! ***')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __del__(self):
 | 
					    def __del__(self):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user