deep_sort_pytorch
deep_sort_pytorch copied to clipboard
size mismatch for classifier.4.weight: copying a param with shape torch.Size([751, 256]) from checkpoint, the shape in current model is torch.Size([1, 256]).
I still do not understand why we need 751 classes for just extractor feature of persons?
~/Desktop/deep_sort_pytorch/deep_sort/deep$ python train.py --resume
Loading from checkpoint/ckpt.t7
Traceback (most recent call last):
File "train.py", line 61, in <module>
net.load_state_dict(net_dict)
File "/home/alex/.pyenv/versions/3.7.0/lib/python3.7/site-packages/torch/nn/modules/module.py", line 847, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Net:
size mismatch for classifier.4.weight: copying a param with shape torch.Size([751, 256]) from checkpoint, the shape in current model is torch.Size([1, 256]).
size mismatch for classifier.4.bias: copying a param with shape torch.Size([751]) from checkpoint, the shape in current model is torch.Size([1]).
Same here. Also didnt understand the whole "classifier" block too.
Me too
751 classes is because model was trained using Market1501 which has 751 classes. When training model, classifier block is used to classify images in training batch into the 751 different people in Market1501. When conducting reid, no classifying is done. Instead you'd just get the feature embeddings of the images in the form of an array, then conduct cosine distancing between images you want to compare.
To get array of features, you got to initialize the model with reid=True
@khayliang thank you, khayliang
Could you tell me how I can get the data for another object like 'Car' with 751 classes to train for 'Car' objects.
You'd first want to train your model on some car reid dataset like VeRi, with 776 different vehicles, or classes.
Once you got your weights you can get the feature embeddings of a car by just calling FeatureExtractor
class with your image.
751 classes is because model was trained using Market1501 which has 751 classes. When training model, classifier block is used to classify images in training batch into the 751 different people in Market1501. When conducting reid, no classifying is done. Instead you'd just get the feature embeddings of the images in the form of an array, then conduct cosine distancing between images you want to compare.
To get array of features, you got to initialize the model with
reid=True
I changed the Net class to force reid=True, but still not working. Im trying to train my custom model, with my custom dataset at Market1501 format.
def __init__(self, num_classes, reid=True):
Error:
size mismatch for classifier.4.weight: copying a param with shape torch.Size([751, 256]) from checkpoint, the shape in current model is torch.Size([128, 256]). size mismatch for classifier.4.bias: copying a param with shape torch.Size([751]) from checkpoint, the shape in current model is torch.Size([128]).
751 classes is because model was trained using Market1501 which has 751 classes. When training model, classifier block is used to classify images in training batch into the 751 different people in Market1501. When conducting reid, no classifying is done. Instead you'd just get the feature embeddings of the images in the form of an array, then conduct cosine distancing between images you want to compare. To get array of features, you got to initialize the model with
reid=True
I changed the Net class to force reid=True, but still not working. Im trying to train my custom model, with my custom dataset at Market1501 format.
def __init__(self, num_classes, reid=True):
Error:
size mismatch for classifier.4.weight: copying a param with shape torch.Size([751, 256]) from checkpoint, the shape in current model is torch.Size([128, 256]). size mismatch for classifier.4.bias: copying a param with shape torch.Size([751]) from checkpoint, the shape in current model is torch.Size([128]).
did you find a solution to the problem?
Make sure your training model saves the ckpt.t7 file, then Try to modify this file
# deep_sort/deep/model.py
def __init__(self, num_classes=1, reid=False)
I have encountered the same problem. Has anyone solved it?
This solved for me: in deep_sort/deep/feature_extractor.py, inialize the model with your network's number of classes
def __init__(self, model_path, use_cuda=True):
self.net = Net(num_classes=NUM_CLASSES, reid=True)
I have changed the class_num, but it doesn't work