shape mismatch while copy weights from trained net

85 views
Skip to first unread message

unit....@gmail.com

unread,
Jul 15, 2016, 5:37:46 AM7/15/16
to Caffe Users
Hello,
I get shape mismatch error on FC-layer when try to load trained net in C++.
My input layer in TRAIN/TEST phase (differ only by source and batch size, some params are omitted):

layer {
    type
: "ImageData"
    image_data_param
{
        batch_size
: 8
        new_height
: 256
        new_width
: 256
   
}
    transform_param
{
        crop_size
: 227
   
}
}

Input layer for the regular use:

layer {
    type
: "Input"
    input_param
{ shape: { dim: 1 dim: 3 dim: 256 dim: 256 }}
}

Error:

Cannot copy param 0 weights from layer 'fc4'; shape mismatch. Source param shape is 8 26912 (215296); target param shape is 8 32768 (262144).

// stack: caffe::Net<>::CopyTrainedLayersFrom()


Could you shed some light on this?

Daniel Moodie

unread,
Jul 15, 2016, 11:57:00 AM7/15/16
to Caffe Users
It looks like during training you load a 256 by 256 then crop it to 227.  Thus the shape output from your ImageData layer is 227.
Then when in regular use you are inputting an image of size 256x256.  Set your input_param shape to 227x227.

unit....@gmail.com

unread,
Jul 18, 2016, 6:51:30 AM7/18/16
to Caffe Users
Thanks for the answer, Daniel. I don't understand crop_size param of input layers. Official tutorial says: random cropping can be done as simple data augmentation. And I thought it's something like random crop & scale with peserving main size (256).
1) Why then need the new_height and new_width parameters?
2)
If I change my input_param shape to 227 during deploy, I get Network should have exactly one input error. Is it because of new input size of the model?

пятница, 15 июля 2016 г., 18:57:00 UTC+3 пользователь Daniel Moodie написал:
Reply all
Reply to author
Forward
0 new messages