Skip to content
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

Vgg16: Problems of Loading Pretrained Weights without fcs #34

Closed
LynnHo opened this issue Nov 25, 2018 · 7 comments
Closed

Vgg16: Problems of Loading Pretrained Weights without fcs #34

LynnHo opened this issue Nov 25, 2018 · 7 comments

Comments

@LynnHo
Copy link

LynnHo commented Nov 25, 2018

@taehoonlee I tried to use sess.run(net.pretrained()) for vgg16, but it failed because of shape mismatch (I did not use the default input size). I read the source code and I am confused by line 320 in tensornets/utils.py,
image
is the code at line 321 designed for tackling the shape mismatch of fcs? If yes, I think it has a problem on vgg16 because it has three fc and this code seems to be only suitable for networks with 1 fc.

@taehoonlee
Copy link
Owner

Thank you for trying TensorNets, @LynnHo. Can you share a TensorNets version and your snippets to reproduce the error? The different input shape is not related to the weight shape mismatching. Maybe, I guess that you use different classes. And the lines 321-324 are to handle the different classes as you expected.

@LynnHo
Copy link
Author

LynnHo commented Nov 29, 2018

@taehoonlee I use a code like below,

import tensorflow as tf
import tensornets as nets

input_256 = tf.placeholder(dtype=tf.float32, shape=[None, 256, 256, 3])
network = nets.VGG16(input_256)
sess = tf.Session()

sess.run(network.pretrained())

and the error is,

ValueError: Dimension 0 in both shapes must be equal, but are 32768 and 25088. Shapes are [32768,4096] and [25088,4096]. for 'Assign_26' (op: 'Assign') with input shapes: [32768,4096], [25088,4096].

If the shape is [None, 224, 224, 3], the code works.

@taehoonlee
Copy link
Owner

@LynnHo, I see. I misunderstood the problem. The VGG16 and the VGG19 accept only a size of 224x224 because the fc6 layer produces a 4096-dimensional vector from a 25088(=77512)-dim vector. The error is from VGG's non-flexible architecture (accepting only fixed input sizes), not the line 320.

@LynnHo
Copy link
Author

LynnHo commented Nov 29, 2018

@taehoonlee But if I just want to load the pretrained weights of Convs ignoring the FCs‘, line 320 is unsuitable. I modified the code at line 320-324 to blow, it works for me

ops = []
for w, v in zip(weights, values):
    if w.shape != v.shape:
        ops.append(w.initializer)
    else:
        ops.append(w.assign(v))

@taehoonlee
Copy link
Owner

@LynnHo, Thank you for the idea. But the proposed one will load all the weights except the middle layer fc6. I think it is error-prone. For the users who want to exploit all the weights, I think it is better to show the mismatch error rather than a silent error due to the random middle layer fc6.

@LynnHo
Copy link
Author

LynnHo commented Nov 29, 2018

@taehoonlee You are right, the shape mismatch should be shown. Or an argument to control the ignoring of the shape mismatch would be better. Anyway, thanks a lot!

@LynnHo LynnHo closed this as completed Dec 6, 2018
@taehoonlee
Copy link
Owner

@LynnHo, Yes I will considering the argument to control the shape mismatch. Thank you for the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants