Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify names of a YOLOv5 trained #3577

Closed
GiorgioSgl opened this issue Jun 10, 2021 · 2 comments
Closed

How to modify names of a YOLOv5 trained #3577

GiorgioSgl opened this issue Jun 10, 2021 · 2 comments
Labels
question Further information is requested

Comments

@GiorgioSgl
Copy link

GiorgioSgl commented Jun 10, 2021

❔Question

I run the command
python3 detect.py --source image.jpg --weights runs/train/exp5/last.pt

The problem is that I mismatch some name of the classes and I have to change it, but seems impossible.

How can I change it??
I need it asap, that I have to submit my thesis :)

Additional context

I try already changing the array in the .yaml file but no success :(

@GiorgioSgl GiorgioSgl added the question Further information is requested label Jun 10, 2021
@GiorgioSgl
Copy link
Author

Just solve in a hard way, I don't know if there are smoother solutions

Actually here

names = model.module.names if hasattr(model, 'module') else model.names # get class names

You have to modify in the following way

names = ["myfirstclass","my second class",..,"last class"]

Hope it help and if there are better solution, just let me know

@bkbilly
Copy link

bkbilly commented Apr 5, 2022

I had the same question, but I solved in a similar way like this:
After loading the model:

model = attempt_load(weights, map_location=device) # load FP32 model

I replaced the dictionary like so:

model.names[0] = 'first_class'
model.names[1] = 'second_class'
model.names[2] = 'third_class'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants