Darknet: test many images

Created on 2 Feb 2019  路  16Comments  路  Source: AlexeyAB/darknet

I would like to test if my detection is successful with many images in my trained model.
Is there a way to test all the images in the folder with a single command with image detection?

I want to check only the image of the detection result by using the image without box attached.

want enhancement

Most helpful comment

@AlexeyAB
Can we also save the predictions.jpg file for each image as well as saving the bounding box coordinates using save_labels?

All 16 comments

What do you want to get as result?

  • one txt file for all detections
  • txt file with detections for each image
  • jpg files with detected bboxes
  • jpg files with cropped detected objects
  • ....

You can run Pseudo-lableing:

  • darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -thresh 0.25 -dont_show -save_labels < data/new_train.txt

  • and then check result labels by using Yolo_mark: https://github.com/AlexeyAB/Yolo_mark


Also you can try to do these changes: https://github.com/AlexeyAB/darknet/issues/2263#issuecomment-456062613
Create folder /result_img/
And run this command:
darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -dont_show -ext_output < data/train.txt > result.txt

You will get:

  1. Images for each cropped objects
  2. result.txt with results of detections

https://github.com/AlexeyAB/darknet#how-to-use

  • To process a list of images data/train.txt and save results of detection to result.txt use:
    darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -dont_show -ext_output < data/train.txt > result.txt

  • Pseudo-lableing - to process a list of images data/new_train.txt and save results of detection in Yolo training format for each image as label <image_name>.txt (in this way you can increase the amount of training data) use:
    darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -thresh 0.25 -dont_show -save_labels < data/new_train.txt

jpg files with detected bboxes

@AlexeyAB
I also have a question about testing multiple images. I'd like to get one text/csv file per test image. For example, if I test 10 images, I want to get 10 different text/csv files with classes and coordinates.
Right now I edited the image.c file to output the classes and coordinates into a csv file. Here is what I edited:

/darknet/src/image.c:

Line 242: FILE *fp = fopen("results.csv","a"); // Opens csv file
Line 287: fprintf(fp, "%s;%f;%f;%f;%f;\n", names[class], b.x*im.w, b.y*im.h, b.w*im.w, b.h*im.h); // prints coordinates to open csv file
Line 315: fclose(fp); // closes csv file

Currently, this is working, but I need to run ./darknet detector test ... for each image. How can I test a folder of images and output one text/csv file for each?

Thanks.

@daylanc

Just use this command:
./darknet detector test cfg/coco.data yolov3.cfg yolov3.weights -thresh 0.25 -dont_show -save_labels < data/new_train.txt

and you will get txt-files for each jpg-file with detected objects in Yolo-training format.

data/new_train.txt - should contain paths to images which you want to test.

@AlexeyAB
What tags can I add to print the class and bounding box coordinates for a single image? Also, what do the tags mean?
-thresh 0.25?
-dont_show?
-save_labels?
-ext_output?
I want to test a single image first, but in the future I'm gonna have to test multiple images. Just want to clarify what tags to use and in what order. Not sure if there's documentation that exists about this elsewhere.
Thanks.

@daylanc
-thresh 0.25 - confidence threshold
-dont_show - don't show window with detection, so it will not wait for press-key if you use many images
-save_labels - save detection in Yolo label format (the same format as for training)
-ext_output - show class name, confidence and coordinates of detected objects (without it - only class name and confidence will be showed)

@AlexeyAB
I used the -ext_output tag to get the class name, confidence, and coordinates. I need to get that information into a python pandas dataframe to do some analysis on, but am having a hard time due to the format of the output .txt or .csv file. Is there a way I could edit the output of the -ext_output tag to just output the class, x_center, and y_center values (or the important values)?

Current Output:
have

Format I need:
want

If there's a file I could take a look at to edit this output or a way I could get each value in a separate cell or column that would be great.
Thanks!

@daylanc

If you want to create separate txt file for each image, then you should use flag -save_labels and change this line: https://github.com/AlexeyAB/darknet/blob/285088adc4a2da0d9c9715bb33ad5b086eb2dbee/src/detector.c#L1336

It isn't related to the -ext_output

@AlexeyAB
Ahhhh okay I see how it works now! Thank you!

@AlexeyAB
Can we also save the predictions.jpg file for each image as well as saving the bounding box coordinates using save_labels?

@AlexeyAB i dont get it..

i have new images , i want to get the coordinates in yolo format but when i run pseudo labeling i get

Enter Image Path: ../google68_0.jpg: Predicted in 173.189000 milli-seconds.
E: 46%
V: 83%
N: 50%
C: 59%
C: 41%
4: 95%
5: 71%
6: 38%
6: 92%
Enter Image Path: ...

thats not yolo format!

@Favi0

  • look at the file ../google68_0.txt that was created
  • what command do you use?

@AlexeyAB
Can we also save the predictions.jpg file for each image as well as saving the bounding box coordinates using save_labels?

I wonder also whether we can save all images with bounding boxes and annotations for predictions during detecting of the set of images? thank you in advance

@rrrtype hi, Have you solve the problem? I just want to save the jpg files detected in a folder. Can you tell me how deal?

@AlexeyAB hi锛孖 just want to get jpg files with detected bboxes. How can I get? Thank you so much.

What do you want to get as result?

  • one txt file for all detections
  • txt file with detections for each image
  • jpg files with detected bboxes
  • jpg files with cropped detected objects
  • ....

You can run Pseudo-lableing:

  • darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -thresh 0.25 -dont_show -save_labels < data/new_train.txt
  • and then check result labels by using Yolo_mark: https://github.com/AlexeyAB/Yolo_mark

Also you can try to do these changes: #2263 (comment)
Create folder /result_img/
And run this command:
darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -dont_show -ext_output < data/train.txt > result.txt

You will get:

  1. Images for each cropped objects
  2. result.txt with results of detections

https://github.com/AlexeyAB/darknet#how-to-use

  • To process a list of images data/train.txt and save results of detection to result.txt use:
    darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -dont_show -ext_output < data/train.txt > result.txt
  • Pseudo-lableing - to process a list of images data/new_train.txt and save results of detection in Yolo training format for each image as label <image_name>.txt (in this way you can increase the amount of training data) use:
    darknet.exe detector test cfg/coco.data yolov3.cfg yolov3.weights -thresh 0.25 -dont_show -save_labels < data/new_train.txt

Hi,
It replace the predictions.jpg everytime. so there is only one prediction.jpg at end. I am running on 10 jpg images and want to save 10 jpg predictions. How to do it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yumin-Sun-00 picture Yumin-Sun-00  路  3Comments

louisondumont picture louisondumont  路  3Comments

rezaabdullah picture rezaabdullah  路  3Comments

HilmiK picture HilmiK  路  3Comments

shootingliu picture shootingliu  路  3Comments