fcn import vgg16 weights error

1,044 views
Skip to first unread message

David Pickup

unread,
Jul 6, 2016, 7:49:34 AM7/6/16
to Caffe Users
I'm new to Caffe and am trying to run the Berkeley FCN Semantic Segmentation code. When trying to copy the pre-trained weights from vgg16fc.caffemodel the code errors with the below output. Can anyone help with solving this problem?

Cannot copy param 0 weights from layer 'fc6'; shape mismatch.  Source param shape is 1 1 4096 25088 (102760448); target param shape is 4096 512 7 7 (102760448). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.

Tudor Achim

unread,
Jul 24, 2016, 10:17:05 PM7/24/16
to Caffe Users
I'm also seeing this.

Vic Genty

unread,
Jul 24, 2016, 10:28:14 PM7/24/16
to Caffe Users
I haven't tried out the pre-trained weights for FCN but the fc6 layer in the caffemodel doesn't match what's in the prototxt (hence the dimension complaint when copying weights to memory)

Evan Shelhamer

unread,
Jul 25, 2016, 5:12:51 PM7/25/16
to Vic Genty, Caffe Users
The weights of this fc6 in the original, fully connected and new, fully convolutional net are actually identical in values but differ in their dimension bookkeeping, as Caffe is complaining about:

Source param shape is 1 1 4096 25088 (102760448); target param shape is 4096 512 7 7 (102760448)

​Caffe is cautious of incompatible shapes by default to help catch mistakes. However, in this case we do want to coerce the transfer of weight​s. This is the purpose of the `surgery.transplant()` method included in the reference code: https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/surgery.py#L5-L19

​If you are working from the original VGG-16 weights, and not a fully convolutionalized version, then swap the weight copying line https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/voc-fcn32s/solve.py#L17​ with

base_net = caffe.Net('vgg16.prototxt', 'vgg16.caffemodel', caffe.TEST)
surgery.transplant(solver.net, base_net)
del base_net

​Hope that helps,​


Evan Shelhamer





--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/bd9522b1-9350-4458-acd5-27e91a42fc6f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages