-
Notifications
You must be signed in to change notification settings - Fork 214
Closed
Labels
Description
Describe the bug
Sometimes it is important to have empty tiles without any annotations in train data (to show to the retinanet that this is not what should be detected). But it seems to be not supported in DeepForest.
To Reproduce
Steps to reproduce the behavior:
all_annotations = pd.DataFrame(columns=['image_path', 'xmin', 'ymin', 'xmax', 'ymax', 'label'])
empty_tile_name = "empty_tile.jpg"
empty_tile = np.zeros((400, 400, 3), np.uint8)
empty_tile[:, :, :] = 255
cv2.imwrite(empty_tile_name, empty_tile)
all_annotations = all_annotations.append({'image_path': empty_tile_name, 'xmin': '', 'ymin': '', 'xmax': '', 'ymax': '', 'label': ''}, ignore_index=True)
...
all_annotations.to_csv(annotations_file, header=True, index=False)
trainer = Trainer(max_epochs=20, gpus=1, auto_select_gpus=True)
train_ds = m.load_dataset(annotations_file, root_dir=os.path.dirname(annotations_file))
trainer.fit(self.m, train_ds)
This leads to
File "/.../python/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/.../python/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/.../python/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/.../python/lib/python3.8/site-packages/deepforest/dataset.py", line 81, in __getitem__
targets["labels"] = image_annotations.label.apply(
File "/.../python/lib/python3.8/site-packages/pandas/core/series.py", line 4356, in apply
return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
File "/.../python/lib/python3.8/site-packages/pandas/core/apply.py", line 1036, in apply
return self.apply_standard()
File "/.../python/lib/python3.8/site-packages/pandas/core/apply.py", line 1092, in apply_standard
mapped = lib.map_infer(
File "pandas/_libs/lib.pyx", line 2859, in pandas._libs.lib.map_infer
File "/.../python/lib/python3.8/site-packages/deepforest/dataset.py", line 82, in <lambda>
lambda x: self.label_dict[x]).values.astype(int)
Additional context
While I see also this check:
DeepForest/deepforest/dataset.py
Line 96 in c2b57e2
raise ValueError("Blank annotations are not allowed in retinanets. Check data augmentation for image {} with shape {}, no overlapping boxes found".format(self.image_names[idx], image.shape)) |
In my opinion this is important option, and it seems to be supported in retinanets - see: