We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
Looking for info on how to train SSD MobileNetv2 model with negative samples. How is 'BACKGROUND' label handled for negative samples.
Here is my annotation xml for pascal voc dataset for one negative sample
<annotation> <folder>negative_samples</folder> <filename>image1.jpg</filename> <size> <width>640</width> <height>480</height> <depth>3</depth> </size> <segmented>0</segmented> <!-- No object tags --> </annotation>
The text was updated successfully, but these errors were encountered:
in vision/datasets/voc_dataset.py create new method
def _gen_random_background(self): return (np.array([[10, 30, 40, 50]], dtype=np.float32), np.array([0], dtype=np.int64), np.array([0], dtype=np.uint8))
change method def _get_annotation(self, image_id): loaed anotation, before return add
if len(boxes) == 0: return self._gen_random_background()
this should be the result
def _get_annotation(self, image_id): annotation_file = self.root / f"Annotations/{image_id}.xml" objects = ET.parse(annotation_file).findall("object") if len(objects) == 0: return self._gen_random_background() raise Exception(f"xml sem box {annotation_file}") boxes = [] labels = [] is_difficult = [] for object in objects: class_name = object.find("name").text.lower().strip() # we're only concerned with clases in our list if class_name in self.class_dict: bbox = object.find("bndbox") # VOC dataset format follows Matlab, in which indexes start from 0 x1 = float(bbox.find("xmin").text) - 1 y1 = float(bbox.find("ymin").text) - 1 x2 = float(bbox.find("xmax").text) - 1 y2 = float(bbox.find("ymax").text) - 1 boxes.append([x1, y1, x2, y2]) labels.append(self.class_dict[class_name]) is_difficult_str = object.find("difficult").text is_difficult.append(int(is_difficult_str) if is_difficult_str else 0) if len(boxes) == 0: return self._gen_random_background() return (np.array(boxes, dtype=np.float32), np.array(labels, dtype=np.int64), np.array(is_difficult, dtype=np.uint8)) def _gen_random_background(self): return (np.array([[10, 30, 40, 50]], dtype=np.float32), np.array([0], dtype=np.int64), np.array([0], dtype=np.uint8))
This works for training with background image, let me know if your model improved with this
Sorry, something went wrong.
No branches or pull requests
Hello,
Looking for info on how to train SSD MobileNetv2 model with negative samples. How is 'BACKGROUND' label handled for negative samples.
Here is my annotation xml for pascal voc dataset for one negative sample
The text was updated successfully, but these errors were encountered: