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
MoviNet: Can not assign pretrained weighted because of the difference between pretrained and defined model #10463
Comments
I am facing the same issue. @t2kien Can you tell more about how to rename keys from "base->b" and "layer->l"? |
It shows error: "KeyError: 'b0/l0/bneck/expansion/conv2d/conv2d/kernel:0'" |
@t2kien @ItsCRC I see you are using the v1 model version. Can you try to use the current (v3) version which has the updated weight names? So for example you should do https://tfhub.dev/tensorflow/movinet/a0/base/kinetics-600/classification/3 for a0 instead of https://tfhub.dev/tensorflow/movinet/a0/base/kinetics-600/classification/1 |
Actually, I just rename the keys of defined model's weight dictionary as below and it works
@Hyperparticle : i am going to try with different versions again. I remember that I've tried with both v1 and v3 but no luck. I've also tested with stream version of both predefined and defined model, and they are different. |
@Hyperparticle: I've tested again with model v3 and dumped both pretrained model and declared model as below:
A dump of pretrained model's weight is displayed:
and declared model's weight dumps:
|
I see, we might have renamed the weights after we exported the TF Hub modules. I will make a note and make sure to update the weight names once we release the next version (v4). For now you can manually rename the weights |
@t2kien thanks, it worked. However, it needs to be fixed as it does not work on any version @Hyperparticle. |
Any tutorial or guide for fine-tuning a stream model? I actually tried with movienet as backbone and movinet classifier with my own number of classes. It resulted in error: layer movienet-classifier-11 expects 125 input(s), but it received input tensors. ( following READ.MD , I changed params for movienet.Movinet(... ) |
This issue has still not been fixed. Pretty much all examples fail. The code and the pre-trained models provided do not match. |
Prerequisites
Please answer the following questions for yourself before submitting an issue.
1. The entire URL of the file you are using
https://github.com/tensorflow/models/tree/master/official/projects/movinet
2. Describe the bug
It seems that the when using pretrained movinet model (base version), the layer name of pretrained model and defined model is different. It show "Key Error" error when assign value of model.
3. Steps to reproduce
Steps to reproduce the behavior.
I declare a new movinet with
backbone = movinet.Movinet(
model_id=model_id)
model = movinet_model.MovinetClassifier(
backbone=backbone,
num_classes=600)
model.build([batch_size, num_frames, resolution, resolution, 3])
Then, download pretrained model from
movinet_hub_url = f'https://tfhub.dev/tensorflow/movinet/{model_id}/base/kinetics-600/classification/1'
movinet_hub_model = hub.KerasLayer(movinet_hub_url, trainable=True)
and assign pretrained weighted to my model
pretrained_weights = {w.name: w for w in movinet_hub_model.weights}
model_weights = {w.name: w for w in model.weights}
for name in pretrained_weights:
model_weights[name].assign(pretrained_weights[name])
It shows error: "KeyError: 'b0/l0/bneck/expansion/conv2d/conv2d/kernel:0'"
4. Expected behavior
5. Additional context
I fixed it temporarily by renaming keys of defined model as follows: " base -> b" and "layer ->l"
6. System information
The text was updated successfully, but these errors were encountered: