Search code examples
python-3.xmachine-learningpytorchobject-detectionyolo

how to rename classes of trained model in Pytorch


I've trained my object detection model based on YOLOV7 and YOLOV5. Now, for some reason i need to change name of classes.

Is it possible to change classes names and save it again as Pytorch ML model file (.pt) I've searched but there is no clear solution for this.

For example: If i load the model like this;

model = torch.load('model file path', map_location=map_location)

and then set the new class names;

model.names = ['face', 'head', 'helmet']

after that how can i save this new model with it's class names as best.pt file.


Solution

  • I've solved the issue in a very unexpected way;

    To solve the proble follow these steps;

    1. Extract .pt file(it's actually a zip file) to a directory
    2. Use some data file reader application(i.e, Hex Editor Neo, HxD Hex Editor) in HexaDecimal format to change data.pkl file which class names are in.
    3. Find your class names by searching in the application.
    4. Be carefull!(If you change wrong place, you may damage the file) Change only the corresponding characters to your class names.
    5. Save it
    6. Zip the files back, together with file you changed, which you extracted
    7. Change the file extension back as .pt
    8. That's it!