SKU110K_CVPR19 shelf target detection and reproduction details (including independent image test)

Source code: https://github.com/eg4000/SKU110K_CVPR19
Paper address: https://arxiv.org/pdf/1904.00853.pdf

1. Preliminary preparation

1. Operating environment

Keras == 2.2.5
keras-retinanet == 0.5.1
tensorflow-gpu == 1.15.4
numpy == 1.19.2
opencv-python == 3.1.0.5
tqdm == 4.50.2
pandas == 0.23.4
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

2. Dataset

There is a data set download address in the source code, which contains image and annotation
insert image description here

2. Code modification

1. Copy files

Put the train.py file and class_mappings.csv in the main folder for easy operation

cp ./object_detector_retinanet/keras_retinanet/bin/train.py class_mappings.csv  ./

insert image description here

2. Modify the path where the dataset is located

Modify the root_dir function in the ./object_detector_retinanet/utils.py file
insert image description here

3. Add code

Add two lines to lines 24-25 in the ./object_detector_retinanet/utils/image.py file to avoid error reporting

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

insert image description here

3. Start training

1. train.py

Specification of relevant parameters
insert image description here
If not trained, then:

python -u ./train.py csv           

specified gpu

python -u ./train.py --gpu 1 csv           

If it has been trained, you can continue training with the most recently saved h5 model

python -u ./train.py --snapshot "SKU110K/snapshot/Thu_Feb_25_16_18_58_2021/resnet50_csv_03.h5" csv

Successful case:
insert image description here
insert image description here

2. train_iou.py

Also put train_iou.py into the main folder for easy training

cp ./object_detector_retinanet/keras_retinanet/bin/train_iou.py ./

start training iou

python -u ./train_iou.py --weights snapshot/Tue_May_26_08_17_14_2020/resnet50_csv_05.h5 csv

4. Start the test (test in the SKU dataset)

1. predict.py

Also put predict.py into the main folder

cp ./object_detector_retinanet/keras_retinanet_bin/predict.py to ./

2. Test

python -u ./predict.py csv  "./SKU110K/snapshot/Thu_May_28_02:36:24_2020/iou_resnet50_csv_01.h5" --hard_score_rate=0.5 

A certain result:
insert image description here
The folder where the result exists:insert image description here

5. Test your own pictures (no csv)

1. Code modification

a. Copy predict.py and rename it to predict_test_demo.py

b. Copy predict_iou.py and rename it to predict_iou_test.py

c. Modify predict_test_demo.py

  1. Comment out the reference to predict_iou and change it to predict_iou_test
    insert image description here

  2. Comment out all the parts containing args in the main function, because if you have args, you must enter data types such as csv/coco, and we only have the image path
    insert image description here
    insert image description here

  3. model loaded directly
    insert image description here

  4. In the predict function, the generator is replaced with the image folder path, and the corresponding parameters are also modified
    insert image description here

d. Modify predict_iou_test.py

  1. Add related functions to be used later: preprocess_image, resize_image
    insert image description here
  2. Modify the predict function:
    modify the parameters, comment out the code related to csv, and add the code to read the pictures under the folder
    insert image description here
  3. Save
    and comment out the code related to csv, and comment out the code that draws the annotation frame
    insert image description here

2. A picture of running your own tests

python -u ./predict_test_demo.py 

result:
insert image description here
insert image description here

insert image description here
The effect is good!

Reference blog: https://blog.csdn.net/qq_35975447/article/details/106349912

Guess you like

Origin blog.csdn.net/poppyty/article/details/114322554