The py file that saves the model and the py file that calls the model are in the same directory. The main reason is that the relative directory is saved when the model is saved. If it is called from another directory, this problem will occur.
method,
parser.add_argument('--project', default='/data/redyolov5/runs/train', help='save to project/name')
Change the path of yolov5 to an absolute path and save it again.
If it doesn’t work, add it to the path
import os,sys root_path = os.getcwd() sys.path.insert(0,"/data/yolov5")
Reason: The file serialization.py literally means serialization and deserialization.
Since python is an interpreted language, the "namespace" saved in the serialized file starts from the root directory of /data/yolov5 .