-
Notifications
You must be signed in to change notification settings - Fork 3
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
Help to change the first convolution #5
Comments
Ok, in tensorflow this is not as straightforward as in pytroch. Not sure exacly how to do it. |
Ok I just need to change rgb/resnet_v1_50/conv1/weights:0 (float32_ref 7x7x3x64) to rgb/resnet_v1_50/conv1/weights:0 (float32_ref 7x7x4x64)... conv1 is: so I can do something with:
|
Well maybe best option is to create a local copy of from the slim resnet_v1 file. |
Ok but what will be your methodology to do that: how can I change the first convolution of a local copy of the resnet_v1 file ? I really dont know how to make the 3 become a 4... |
Ok, maybe you do not need to modify the network but only the placeholder, which is the way the computational graph gets his input (4d instead of 3d). Then the problem will be in loading the checkpoint. You can load the checkpoint and assign values to variables excluding conv1 variables (similarly as done already for logits). The assignment for conv1 should be done manually because of size mismatch. |
Ok so self.images = tf.placeholder(tf.float32, [None, 224, 224, 4], modality + '_images') effectively change the 3 to a 4: rgb/resnet_v1_50/conv1/weights:0 (float32_ref 7x7x4x64) [12544, bytes: 50176] but like you said the problem is with the checkpoint now: tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both so according to what you said previously I have to change the code in the def single_stream like you did with logits ? But what you mean by conv1 should be done manually because of size mismatch how can I do that? |
For exemple when I do that:
I got the following error ValueError: Trying to share variable rgb/resnet_v1_50/conv1/weights, but specified shape (7, 7, 64, 64) and found shape (7, 7, 4, 64)...it's because /resnet_v1_50/conv1 give 64 filters but how can I initialize it with 4 as the value when it's the first convolution of the network...the input of the first convolution is the image so it's 4...but when I do :
I got tensorflow.python.framework.errors_impl.NotFoundError: Key rgb/resnet_v1_50/conv1/biases not found in checkpoint [[{{node save/RestoreV2}}]]. So I'm clearly doing something wrong and to be frank I don't really know what I'm doing, I just tried all the day and nothing is working. |
No. The computational graph for the net is ok. So you must not modify the file |
Yep this is working thanks a lot, what do you suggest to normalize the depth channel a value of 122.5 (for the mean)? |
Be careful. It is working but conv1 is randomly initialized at the moment. |
Do you have any idea of why when I train_rgb with the 4th channel all at zero (so basicaly its just RGB), I got after like 10 epochs: rgb train acc [0.9378] rgb test acc [0.2549]...? Is it because of the weights randomly initialized ? |
Yes, I think so. |
Hi I need to change the first convolution of the model from rgb/resnet_v1_50/conv1/weights:0 (float32_ref 7x7x3x64) to rgb/resnet_v1_50/conv1/weights:0 (float32_ref 7x7x4x64), so basicaly augmenting the number of filter form 3 to 4 to accept 4 channels images but keeping the pretrained weight elsewhere (just the additional channel initialize ramdonly).
Do you have an idea of how to do that in Tensorflow (I'm more of a PyTorch guy...) ?
InPyTorch I do:
Thanks a lot for your help!
The text was updated successfully, but these errors were encountered: