hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

strange ground truth values for save_dataset_for_mAP when not loading dataset each time its run #38

Closed flugenheimer closed 3 years ago

flugenheimer commented 3 years ago

I managed to find a strange behaviour with the save_dataset_for_mAP function. you have to reload the dataset each time you want to use the function save_dataset_for_mAP, otherwise a strange multiplication (or something else) is happening to the ground truth values being outputted into the "mAP/input/ground-truth" folder:

test_data_set = yolo.load_dataset(
    "/content/cats/test.txt",
    dataset_type="yolo"
)
yolo.save_dataset_for_mAP("/content/mAP/", test_data_set)
yolo.save_dataset_for_mAP("/content/mAP/", test_data_set)
yolo.save_dataset_for_mAP("/content/mAP/", test_data_set)

first time: cat_head 479 199 808 516 second time: cat_head 486440 203929 820469 529350 third time: cat_head 493737435 208823994 832776689 542054400 and so on...

This might seems like an artificial scenario, but it will introduce an error when using Google Colab and having loaded the dataset in one cell and try to call save in another cell multiple times.

if the dataset is loaded before each call to the save_dataset_for_mAP, this is not an issue

test_data_set = yolo.load_dataset(
    "/content/cats/test.txt",
    dataset_type="yolo"
)
yolo.save_dataset_for_mAP("/content/mAP/", test_data_set)

test_data_set = yolo.load_dataset(
    "/content/cats/test.txt",
    dataset_type="yolo"
)
yolo.save_dataset_for_mAP("/content/mAP/", test_data_set)
hhk7734 commented 3 years ago

Before saving the ground_truth, removes <mAP path>/input directory first. https://github.com/hhk7734/tensorflow-yolov4/blob/25e802f1e0b95a5719920e40e98fdac1d0a9bfb2/py_src/yolov4/tf/__init__.py#L303-L305

And there is no need to reload the dataset. The reason for reloading the dataset is that somebody is confused about where the data set was obtained. :)

flugenheimer commented 3 years ago

But why am i getting this behavior then ?

hhk7734 commented 3 years ago

https://github.com/hhk7734/tensorflow-yolov4/blob/25e802f1e0b95a5719920e40e98fdac1d0a9bfb2/py_src/yolov4/tf/__init__.py#L323

https://github.com/hhk7734/tensorflow-yolov4/blob/25e802f1e0b95a5719920e40e98fdac1d0a9bfb2/py_src/yolov4/tf/__init__.py#L333-L335

Maybe this part causes the problem.

hhk7734 commented 3 years ago

Fixing it with _dataset = data_set.dataset[i % max_dataset_size].copy() may fix the problem. If possible, please do PR after correction and testing.