diff --git a/README.md b/README.md index 345ce6b..1b21e0a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,23 @@ Currently Support Formats: - YOLO - VOC +This version fix color order changes from BGR to RGB introduced in version 0.1.12 (or at least after 0.1.9). +This version also fix infinite loop in Annotation.coco() thank's to george-gca work. (cherry-pick george-gca fix). +Also note that v0.1.12 is actually the official imantics pip version, but this version is buggous. +Stay on master branch to benefit from unreleased 0.1.13 version that fix problems (except color order change and infinite loop) + +so instead of +``` +pip install imantics +``` +prefer +``` +pip install imantics==0.1.9 + +or better, get version with my fixes +pip install git+https://github.com/SixK/imantics.git +``` +

Join our growing discord community of ML practitioner

diff --git a/imantics/annotation.py b/imantics/annotation.py index 38369bd..a4ed6fc 100644 --- a/imantics/annotation.py +++ b/imantics/annotation.py @@ -204,6 +204,9 @@ def index(self, image, dataset=None): annotation_index[self.id] = self # Category indexing should be case insenstive + if self.category == None: + print('WARNING - Category is None for Annotation', flush=True) + return category_name = self.category.name.lower() # Check if category exists @@ -284,6 +287,7 @@ def coco(self, include=True): if len(annotation['segmentation'][i]) == 2: # discard segmentation that is only a point annotation['segmentation'].pop(i) + i -= 1 elif len(annotation['segmentation'][i]) == 4: # create another point in the middle of segmentation to # avoid bug when using pycocotools, which thinks that a @@ -304,7 +308,8 @@ def coco(self, include=True): new_segmentation = polygon[:2] + [x, y] + polygon[2:] annotation['segmentation'][i] = new_segmentation - i += 1 + + i += 1 if include: image = category = {} diff --git a/imantics/image.py b/imantics/image.py index 3f4bb3d..5009ceb 100644 --- a/imantics/image.py +++ b/imantics/image.py @@ -184,13 +184,21 @@ def draw(self, bbox=True, outline=True, mask=True, text=True, thickness=3, \ temp_image = cv2.imread(self.path) + temp_image = cv2.cvtColor(temp_image, cv2.COLOR_BGR2RGB) + if temp_image is None: temp_image = np.zeros((self.height,self.width,3)).astype(np.uint8) temp_image.setflags(write=True) for annotation in self.iter_annotations(): + if color_by_category and annotation.category is None: + continue category = annotation.category if (categories is None) or (category in categories): + if category == None : + print('WARNING - Category is None for Image', flush=True) + return + color = category.color if color_by_category else annotation.color if mask: