Merge two model on one

I have make two training on image classification.
First training on type of glass
Second on type of clothes
So I have two files: glass.pth and clothes.pth
I would like now merge this two files on one.
Do you know how it is possible to do this ?

Thank you

You could use this approach, but would need to check, if just averaging different parameters is the right approach.
E.g. if both models converged to a completely different set of parameters, I would assume that the average of these models could perform badly.

Thank you.
Second question, how get the labels name when we predict image.
For load the model I used :


image_tensor = transforms(image).float()
image_tensor = image_tensor.unsqueeze_(0)
input = image_tensor
input =
output = model(input)
index =

You could use a mapping between the class indices and the label names, e.g. via a dict, where the keys could be the class indices and the values the class names.

Yes, but it’s impossible to save this label in the model ?

You can assign any attribute to the model, but note that only parameters and buffers would show up in the state_dict. If you want to store it, you could add the mapping to the checkpoint manually and save it in a similar way as e.g. the epoch argument is stored in the ImageNet example.

Thanks you, I try this