I want to run yolo on a bunch of images that i got from a video and i want to save the results as result.json file. The only place i found something about .json file is in test.py. But how do i use it on my images?
Hello @SamiurRahman1, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , Docker Image, and Google Cloud Quickstart Guide for example environments.
If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.
If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com.
@SamiurRahman1 you can create a coco style json file using test.py:
python test.py --save-json
You can save text labels using detect.py:
python detect.py --save-txt
@SamiurRahman1 you can create a coco style json file using test.py:
python test.py --save-jsonYou can save text labels using detect.py:
python detect.py --save-txt
Thank you for your reply. But if i am using test.py, how do i give the input image files to the script?
@SamiurRahman1 the same way it's currently used.
@SamiurRahman1 the same way it's currently used.
Would you mind elaborating a bit? i am very new to yolo. I ran the following code:
python test.py --save-json --data /home/sam/Downloads/processed_images2/2/300_4_3.jpg
and i get this error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
@SamiurRahman1 start from the tutorials https://github.com/ultralytics/yolov5#tutorials
So, as much as i understand, i need a .yaml file of my dataset to use test.py. For that, i need to train using my dataset. Am i on the right track?
@SamiurRahman1 yes you want a data.yaml file that shows training and testing image folders. Then you just point test.py to it, it will evaluate all val images.
https://github.com/ultralytics/yolov5/blob/90e7bfdf7561b52433ae2974445c4eaec22ad536/data/coco128.yaml#L10-L13
python test.py --data coco128.yaml
@SamiurRahman1 yes you want a data.yaml file that shows training and testing image folders. Then you just point test.py to it, it will evaluate all val images.
python test.py --data coco128.yaml
Ok thank you. I got it now. But what if i don't want to train, just test my dataset with a pre-trained model and want to save the results as .json file? is there anyway to do that?
+1 for this if it not possible right now. With Darknet Yolo, I use the generate result.json to analyse the detections further. The save-txt argument seems to just make labels for every picture in a seperate file. I would like to have all detections in one json (or something comparable) file.
@SamiurRahman1 yes of course it's possible. You just follow the steps I already explained to you.
@Denizzje follow the directions I explained already above.
@SamiurRahman1 yes of course it's possible. You just follow the steps I already explained to you.
when i try to run the script without training, it asks for a cache file, which i assume i only get when i train?
@SamiurRahman1 no
ok.. never mind. i got my json file using yolov3. this wasn't helpful for me and i think it is better if i leave it at that. thank you for your replies.
FYI, i changed the yaml file with where my image files are:
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: /home/sam/Downloads/SIT/darknet-master/data/list1.txt # 128 images
val: /home/sam/Downloads/SIT/darknet-master/data/list1.txt # 128 images
The file is surely there and the content of the file is full path for my images.
/home/sam/Downloads/SIT/KevalDoshi/ori_images/2/10000.jpg
/home/sam/Downloads/SIT/KevalDoshi/ori_images/2/1000.jpg
and so on. This is the error i get as i mentioned. It is looking for a .cache file.
line 215, in __init__
super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: '/home/sam/Downloads/SIT/KevalDoshi/ori_labels/2.cache'
@SamiurRahman1 this should be easy to do. Just point your coco128.yaml to your folder
val: inference/images/ # images
And run python test.py --save-json:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco128.yaml', device='', img_size=640, iou_thres=0.65, merge=False, save_json=False, save_txt=False, single_cls=False, task='val', verbose=False, weights='yolov5s.pt')
Using CPU
Fusing layers... Model Summary: 140 layers, 7.45958e+06 parameters, 7.45958e+06 gradients, 17.5 GFLOPS
Scanning images: 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 2/2 [00:00<00:00, 137.05it/s]
Scanning labels inference/labels.cache (0 found, 0 missing, 2 empty, 0 duplicate, for 2 images): 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 2/2 [00:00<00:00, 12557.80it/s]
WARNING: No labels found in inference/labels/. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
Class Images Targets P R [email protected] [email protected]:.95: 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1/1 [00:01<00:00, 1.14s/it]
all 2 0 0 0 0 0
Speed: 445.9/5.2/451.2 ms inference/NMS/total per 640x640 image at batch-size 32
Process finished with exit code 0
@SamiurRahman1 this should be easy to do. Just point your coco128.yaml to your folder
val: inference/images/ # imagesAnd run
python test.py --save-json:Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco128.yaml', device='', img_size=640, iou_thres=0.65, merge=False, save_json=False, save_txt=False, single_cls=False, task='val', verbose=False, weights='yolov5s.pt') Using CPU Fusing layers... Model Summary: 140 layers, 7.45958e+06 parameters, 7.45958e+06 gradients, 17.5 GFLOPS Scanning images: 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 2/2 [00:00<00:00, 137.05it/s] Scanning labels inference/labels.cache (0 found, 0 missing, 2 empty, 0 duplicate, for 2 images): 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 2/2 [00:00<00:00, 12557.80it/s] WARNING: No labels found in inference/labels/. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data Class Images Targets P R [email protected] [email protected]:.95: 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 1/1 [00:01<00:00, 1.14s/it] all 2 0 0 0 0 0 Speed: 445.9/5.2/451.2 ms inference/NMS/total per 640x640 image at batch-size 32 Process finished with exit code 0
Thank you for the reply. This should be noted that the script only works when the images are in inference/images folder.
Hopefully one last question, i assume that it worked since i got the txt result files after running the following command:
python test.py --save-json --save-txt
So, where exactly is my .json file saved? I searched for any .json file in the folder, but didn't find anything. I got the following output on the terminal:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco128.yaml', device='', img_size=640, iou_thres=0.65, merge=False, save_json=True, save_txt=True, single_cls=False, task='val', verbose=False, weights='yolov5s.pt')
Using CPU
Fusing layers... Model Summary: 140 layers, 7.45958e+06 parameters, 7.45958e+06 gradients
Scanning labels /home/sam/Downloads/SIT/yolov5-master/inference/labels.cache (0
WARNING: No labels found in /home/sam/Downloads/SIT/yolov5-master/inference/labels/. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
Class Images Targets P R [email protected]
all 2.68e+03 0 0 0 0 0
Speed: 141.7/4.2/145.9 ms inference/NMS/total per 640x640 image at batch-size 32
@glenn-jocher Hi, after i output the result.json weird that it has many FP cases, is this file the final result with nms and confidence_score filter result already, btw thanks for this repo, nice work!!!
@DINOUS11 this is a pycocotools format json
pycocotools format
@glenn-jocher Is that means it is given all prediction with nms and confident threshold filter?
yes
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.