sovit-123 / fasterrcnn-pytorch-training-pipeline

PyTorch Faster R-CNN Object Detection on Custom Dataset
MIT License
223 stars 77 forks source link

Background image for Faster RCNN #142

Closed ycuskun closed 6 months ago

ycuskun commented 6 months ago

Hello, How do we add background images to the data set while training? More precisely, what do we write in the label content of the background images? Can you give an example?

Thank you.

sovit-123 commented 6 months ago

Hi. Yes, the information needs to be added. I will update the README within 1-2 days. In short, you can just keep the XML file empty.

ycuskun commented 6 months ago

When I keep the XML file empty and start the training, I get an error.

Traceback (most recent call last): File "train.py", line 571, in <module> main(args) File "train.py", line 411, in main batch_loss_rpn_list = train_one_epoch( File "D:\Faster R-CNN\fasterrcnn-pytorch-training-pipeline-main\torch_utils\engine.py", line 45, in train_one_epoch for images, targets in metric_logger.log_every(data_loader, print_freq, header): File "D:\Faster R-CNN\fasterrcnn-pytorch-training-pipeline-main\torch_utils\utils.py", line 173, in log_every for obj in iterable: File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\dataloader.py", line 634, in __next__ data = self._next_data() File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\dataloader.py", line 1346, in _next_data return self._process_data(data) File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\dataloader.py", line 1372, in _process_data data.reraise() File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\_utils.py", line 644, in reraise raise exception File "<string>", line None xml.etree.ElementTree.ParseError: Caught ParseError in DataLoader worker process 0. Original Traceback (most recent call last): File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\_utils\worker.py", line 308, in _worker_loop data = fetcher.fetch(index) File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\Faster R-CNN\fasterrcnn-pytorch-training-pipeline-main\datasets.py", line 293, in __getitem__ labels, area, iscrowd, dims = self.load_image_and_labels( File "D:\Faster R-CNN\fasterrcnn-pytorch-training-pipeline-main\datasets.py", line 102, in load_image_and_labels tree = et.parse(annot_file_path) File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\xml\etree\ElementTree.py", line 1202, in parse tree.parse(source, parser) File "C:\Users\YASIN\anaconda3\envs\tensorrt_torch\lib\xml\etree\ElementTree.py", line 595, in parse self._root = parser._parse_whole(source) File "<string>", line None xml.etree.ElementTree.ParseError: no element found: line 1, column 0

sovit-123 commented 6 months ago

I will check it.

ycuskun commented 6 months ago

Hello again, Were you able to check? Any progress?

sovit-123 commented 6 months ago

Hi. Earlier, I stated it wrongly actually. An empty XML file indeed throws an error. To be used as a background image, the XML file needs to have empty annotation tags, like the following:

<annotation>
</annotation>

I understand that this is not very ideal. I will try to fix this in the near future. Let me know if I can mark close this issue for now.

ycuskun commented 6 months ago

It worked when I did it this way.

Thank you.

sovit-123 commented 6 months ago

No problem. I am closing the issue for now.