Problem description: Recently, when using yolov5 to run a target detection model, and then train() to train my own model, an error occurred: "UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 424: illegal multibyte sequence" . Here I am using the Windows 11 operating system.
Cause analysis: This problem occurs because the default encoding method in python is "gbk", while the default encoding method for files in Windows is "utf-8", so the python compiler cannot successfully read or write the file content. .
solution:
1. Find all open() operations for reading files in the code. Taking my own project as an example, there are 6 in total.
2. Add encoding="utf-8" to all open() operations found in the first step , that is
Add code as shown in the following code block:
with open(xxx,ggg,ddddd,encoding="utf-8")
At this point, problem solved! ! !