1. YOLOv5 source code outputs prediction results in multiple formats
Functions - passing in parameters
Functions - Save Print
The write result part of the loop that processes each image:
We can see that the following code snippet is the code that outputs the prediction in a different format
2.YOLOv5 to .txt format output prediction results
1. Execute the following code can be obtained in .txt format output prediction results
python --weights runs/exp1/weights/ --source inference/images/ --save-txt --save-conf
–save-txt save results to *.txt #projectedbounding boxsave as (a file)txtfile
–save-conf save confidences in --save-txt labels #Probability of category
Each txt generates a line of information about one target, the information includes the category serial number, the next four are the bbox position (xcenter ycenter w h), and the last is the probability of the category
2. Output format:
3.YOLOv5 to .json format output prediction results
1. Need to add a piece of code in the source code The first step
Add in this position
save_json = True,# Output json file save results to *.json content_json = [],
second step
Below this position add
# Output json file if save_json: # used under windows num += 1 file_name = save_path.split('\\') # Used under Linux # file_name = save_path.split('/') content_dic = { "name": file_name[len(file_name) - 1], "num": num, "category": (names[int(cls)]), "bbox": (xyxy).view(1, 4).view(-1).tolist(), "score": () } content_json.append(content_dic)
2. Output format
summarize
To this article on YOLOv5 txt or json format output prediction results of the article is introduced to this, more related YOLOv5 txt or json output prediction results of the contents of the search for my previous posts or continue to browse the following articles hope that you will support me in the future!