nixingyang / AdaptiveL2Regularization

[ICPR 2020] Adaptive L2 Regularization in Person Re-Identification
https://ieeexplore.ieee.org/document/9412481
MIT License
64 stars 23 forks source link

Custom dataset #6

Closed Roberto7766 closed 3 years ago

Roberto7766 commented 3 years ago

Hi, I'm trying to use a custom dataset to see how it works. The dataset is very small (4 identities) and 50 query images. My idea is to use pre-trained net and calculate embeddings and distance only on this small dataset. I added another dataset loader called personal.py that is similar to Market1501.py since I used the same naming convention. I used the parameters --identity_num_per_batch 4 --image_num_per_identity 2 otherwise the code is forever trapped into self.image_file_path_list = next(self.image_file_path_list_generator). Everything looks fine until I get: "ValueError: Shapes (2048, 4) and (2048, 751) are incompatible" from: File "solution.py", line 1031, in main training_model.load_weights(pretrained_model_file_path)

How can I move forward? Thank you

nixingyang commented 3 years ago

This error is expected. You could set skip_mismatch to True when using load_weights. If you only need to extract features without additional training, please check https://github.com/nixingyang/AdaptiveL2Regularization/issues/5#issuecomment-717423297 to see how to perform it.

Roberto7766 commented 3 years ago

Thanks for the help. I added "by_name=True, skip_mismatch=True" and I used the suggested code and it works. The result are quite good on my dataset (>80% Rank1).

I have a question: due to the skip_mismatch I have the following warnings: WARNING:tensorflow:Skipping loading of weights for layer dense due to mismatch in shape ((2048, 8) vs (2048, 1041)). W1201 13:57:58.421483 140339802146624 hdf5_format.py:778] Skipping loading of weights for layer dense due to mismatch in shape ((2048, 8) vs (2048, 1041)). WARNING:tensorflow:Skipping loading of weights for layer dense_1 due to mismatch in shape ((1024, 8) vs (1024, 1041)). W1201 13:57:58.424212 140339802146624 hdf5_format.py:778] Skipping loading of weights for layer dense_1 due to mismatch in shape ((1024, 8) vs (1024, 1041)). WARNING:tensorflow:Skipping loading of weights for layer dense_2 due to mismatch in shape ((1024, 8) vs (1024, 1041)). W1201 13:57:58.426242 140339802146624 hdf5_format.py:778] Skipping loading of weights for layer dense_2 due to mismatch in shape ((1024, 8) vs (1024, 1041)).

Does it mean that 3 dense layers have random values? Or do they have Resnet pretrained values? Is there a way to train also those layers?

Thank you

nixingyang commented 3 years ago

It's glad to hear that you obtained satisfactory results. Those warnings are expected, and the parameters inside the dense layers have random values. The pre-trained weights on other datasets can't be loaded in these dense layers because the shapes of tensors are different. You could optimize the dense layers, just like what has been done in the current script, i.e., specifying the skip_mismatch argument and adding the data set. Note that the dense layers are not used in the inference procedure anyway. If your own dataset is relatively small, retraining the model may lead to over-fitting.