Darknet: How to detect all images in a specific folder

Created on 27 Mar 2018  Â·  11Comments  Â·  Source: AlexeyAB/darknet

Hi, all

First, I can use below command to detect a single images.
./darknet detector test ...

But I want to detect all the images in a specific folder. For example, detect the N images of test set folder.

The following is my solution, but I think it is not good.

Use the loop to execute many times the 'detector test' command and rename 'predictions.jpg'.

Run Python script:

python detect_multi_images.py [specific folder]

Python Code: detect_multi_images.py

import os
import sys

if __name__ == '__main__':
    imgdir = sys.argv[1]
    for img in os.listdir(imgdir):
        os.system('./darknet detector test obj.data yolo-voc.2.0.cfg yolo-voc_final.weights ***filename(Ignore here - because too long - don't care)*** -dont_show')
        os.system('mv predictions.jpg ' + img)

The performance of this solution is slow.

I am searching for a long time on Issues of darknet. But no use.

Please help or try to give some ideas how to achieve this.

Thanks in advance.

question

Most helpful comment

@SiNcSaD Hi,

Try to do on Linux:

  • put your images to the directory /darknet/pic and exit from /pic to /darknet

  • ls -d "$PWD"/pic/* > filelist.txt

  • ./darknet detector test obj.data yolo-voc.2.0.cfg yolo-voc_final.weights -dont_show < filelist.txt > result.txt

You will see results in the file result.txt

All 11 comments

@SiNcSaD Hi,

Try to do on Linux:

  • put your images to the directory /darknet/pic and exit from /pic to /darknet

  • ls -d "$PWD"/pic/* > filelist.txt

  • ./darknet detector test obj.data yolo-voc.2.0.cfg yolo-voc_final.weights -dont_show < filelist.txt > result.txt

You will see results in the file result.txt

@AlexeyAB, Hi

According to your solution I successfully completed. Then performance of detection is very good!

Get the content of 'results.txt':

seen 32 
Enter Image Path: pic/000001.jpg: Predicted in 0.012083 seconds.
ship: 90%
Enter Image Path: pic/000002.jpg: Predicted in 0.011978 seconds.
ship: 89%
Enter Image Path: pic/000003.jpg: Predicted in 0.010273 seconds.
ship: 90%
Enter Image Path: pic/000004.jpg: Predicted in 0.010057 seconds.
ship: 87%
Enter Image Path: pic/000005.jpg: Predicted in 0.010159 seconds.
ship: 89%
Enter Image Path: pic/000006.jpg: Predicted in 0.010014 seconds.
ship: 92%
ship: 87%
ship: 80%
Enter Image Path: pic/000007.jpg: Predicted in 0.010259 seconds.
ship: 85%
Enter Image Path: pic/000008.jpg: Predicted in 0.010238 seconds.
ship: 87%
Enter Image Path: pic/000009.jpg: Predicted in 0.010003 seconds.
ship: 88%
Enter Image Path: pic/000010.jpg: Predicted in 0.010041 seconds.
ship: 88%
.
.
.

However, I modified the code of the function 'test_detector()' to support saving the result image of the detection. (Dynamic image name)

comment

Thanks you.

Hi ,How to detect all images in a specific folder and save all the result images at the same time?the mothod of @SiNcSaD doesn't works in my computer. @AlexeyAB thanks.

@XP-CHRC What error do you get? Do you use Linux and can you get file filelist.txt as described above?

@AlexeyAB it works, thank you! you are so good!

hi, I modified the code of the function 'test_detector()' like you, but there are nothing under the folder results, so what's wrong with me probably? thanks. @SiNcSaD

@XP-CHRC
Use this command ./darknet detector test obj.data yolo-voc.2.0.cfg yolo-voc_final.weights -dont_show < filelist.txt > result.txt

And see file result.txt right here, not in the folder results.

@AlexeyAB i know this ,but i want to detect all images in a specific folder and save the result images at the same time, and i wrote a ugly shell:
a=1
while read line
do
./darknet detector test cfg/coco.data cfg/yolov2-tiny.cfg yolov2-tiny.weights $line -thresh 0.28
mv predictions.jpg results/$a.jpg;
(( a++ ));
done < filelist.txt
this is time waste. hahhaha....
And thank your help, you are a good man.

@XP-CHRC Hi,

First, do you see results in your result.txt?

What is the input variable in your test_detector() function?

Can you show the modified code? Let me help you.

@AlexeyAB @SiNcSaD ,

How do i save the all the results to a specific folder (say result) instead of one prediction.jpg overwriting itself over and over again?

@abeyang00 I assume you can do https://github.com/AlexeyAB/darknet/issues/125#issuecomment-320373088 to achieve what you want

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cipusha picture Cipusha  Â·  3Comments

HilmiK picture HilmiK  Â·  3Comments

Jacky3213 picture Jacky3213  Â·  3Comments

louisondumont picture louisondumont  Â·  3Comments

qianyunw picture qianyunw  Â·  3Comments