stark-t / PAI

Pollination_Artificial_Intelligence
5 stars 1 forks source link

YOLOv4 prediction issues #53

Closed stark-t closed 1 year ago

stark-t commented 1 year ago

Due to #51 and #52 here is the shell code I used for the YOLOv4 prediction. The code only return the images but not a single prediction. I'm not sure if there is an error in my code.

YOLOv5 threshold grid search

for i in $(LC_ALL=en_US.UTF-8 seq 0.1 0.1 0.5); do for j in $(LC_ALL=en_US.UTF-8 seq 0.1 0.1 0.5); do "C:\ProgramData\miniforge3\envs\pytorch_cuda113_PAI\Scripts\python.exe" "C:\Users\star_th\PycharmProjects\PAI\detectors\yolov5\detect.py" \ --weights "F:\202105_PAI\data\P1_models\YOLOv5s\3211389_yolov5_s6_b8_e300_hyp_custom\weights\best.pt" \ --source "F:\202105_PAI\data\P1_Data_sampled\test\images" \ --conf-thres $i \ --iou-thres $j \ --save-txt \ --nosave \ --project "F:\202105_PAI\data\P1_results" \ --device "cpu" \ --name "yolov5_s6_b8_e300_iou"$j"_conf"$i; done done

YOLOv4

"C:\ProgramData\miniforge3\envs\pytorch_cuda113_PAI\Scripts\python.exe" "C:\Users\star_th\PycharmProjects\PAI\detectors\yolov4\detect.py" \ --weights "F:\202105_PAI\data\P1_models\YOLOv4s_640_300epochs\3217130_yolov4_pacsp_s_b8_e300_img640_hyp_custom\weights\best.pt" \ --cfg "C:\Users\star_th\PycharmProjects\PAI\detectors\yolov4\cfg\yolov4-pacsp-s.cfg" \ --source "F:\202105_PAI\data\P1_Data_sampled\test\images" \ --conf-thres 0.1 \ --iou-thres 0.1 \ --save-txt \ --output "F:\202105_PAI\data\P1_results\yolov4_pacsp_s_b8_e300_confthres25_iouthres45" \ --classes 1 2 3 4 5 6 7 8 \ --names "C:\Users\star_th\PycharmProjects\PAI\scripts\pai.names" \ --device "cpu"

valentinitnelav commented 1 year ago

I also do not see anything strange for now.

Here was my bash script that I managed to test for detect.py for yolov4: https://github.com/stark-t/PAI/blob/dev_cluster/scripts/cluster/yolov4_detect_pacsp_s_640_rtx.sh

For yolov7, I have the one below running right now, and based on this one and the one above I will try a loop for the yolov4 detct.py later and give you more feedback.

# This will create a folder in ~/PAI/detectors/yolov7/runs/detect with the name given in the --project argument.
# In that folder there will be several otehr folders containing the label files.
# The names of these folders are created via the --name argument.
for conf in $(seq 0.1 0.1 0.9)
do
    for iou in $(seq 0.1 0.1 0.9)
    do
        python detect.py \
        --weights ~/PAI/detectors/yolov7/runs/train/3219805_yolov7_img640_b8_e300_hyp_custom/weights/best.pt \
        --source /home/sc.uni-leipzig.de/sv127qyji/datasets/P1_Data_sampled/test/images \
        --img-size 640 \
        --conf-thres "$conf" \
        --iou-thres "$iou" \
        --save-txt \
        --save-conf \
        --nosave \
        --project runs/detect/job_"$SLURM_JOB_ID"_loop_detect_on_3219805_yolov7_img640_b8_e300_hyp_custom \
        --name results_at_conf_"$conf"_iou_"$iou"
    done
done

I didn't see in yours the argument --img-size. Perhaps that is optional, but check what the default is from case to case so that it matches what we used for training. I think 640 is the default and this might work, so not sure if that is the issue.

I however used a different --cfg file. I used cfg/yolov4-csp-s-leaky.cfg. If you get the weights and their corresponding cfg files from https://github.com/WongKinYiu/PyTorch_YOLOv4, you will see that yolov4-csp-s-leaky.cfg corresponds to yolov4-csp-s-leaky.weights pre-trained weights which I used for training.

Also, for yolov4 I will switch from using best_overall.pt to best.pt as we agreed here https://github.com/stark-t/PAI/issues/50#issuecomment-1231526134

stark-t commented 1 year ago

@valentinitnelav yes i check that 640px is the default image size for all three versions

valentinitnelav commented 1 year ago

By the way, in my case, for YOLOv4 the images and label files are saved in the same folder in ~/PAI/detectors/PyTorch_YOLOv4/runs/detect/.

I will push the cluster scripts for loop detection for YOLOv4 & 7 on GitHub in few moments.

valentinitnelav commented 1 year ago

I think the loop job will take at 4-5 hours to run for the 9*9 possible values (0.1 to 0.9 with a step of 0.1) for conf and IoU. The folder structure of the output will be similar for yolov7 & 5, but yolov4 breaks a bit that pattern with having the image files saved (there is no argument to stop that) and image and label files in the same output folder.

I will write a loop script for YOLOv5 as well, just realized I didn't do that :D. So far I have for YOLOv7 & 4.

stark-t commented 1 year ago

@valentinitnelav So I'm currently running the 9*9 grids but the results are really bad. Could it be that we don't have the same test dataset? Could you send me your test dataset, because there 90% missing detections.

valentinitnelav commented 1 year ago

@stark-t

Hi Tommi, now I realize that most probably we have different train, test, val datasets because of how the seed is set/works differently on your Windows PC and on the Linux cluster that I use (even on the cluster might depend on the environments set at run time).

I am downloading right now the test dataset from the cluster and uploading it on a Dropbox link. Will send it to you via an email as soon as the link is operational.

stark-t commented 1 year ago

@valentinitnelav evaluate script