welfred
welfred

Reputation: 11

Caffe: variable input-image size for vgg network

I am trying to use caffe to extract features of the convolution layer rather than FC layer from VGG network.The theoretical input image size may be arbitrary in this situation. But it seams that VGG network was trained on images cropped to the size 224x224 pixel. So I define an input data layer in the deploy.prototext:

layers{
  name: "data"
  type: MEMORY_DATA
  top: "data"
  top: "label"
  transform_param{
    mirror: false
    crop_size:224
    mean_value:129.1863
    mean_value:104.7624
    mean_value:93.5940
  }
  memory_data_param{
    batch_size:1
    channels:3
    width:224
    height:224
  }
}

I tried to modify the width = 500\height = 500\crop_size = 500 but failed. Caffe throws some errors:“ Cannot copy param 0 weights from layer 'fc6'; shape mismatch. Source param shape is 1 1 4096 25088 (102760448); target param shape is 4096 131072 (536870912). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.”

How is it possible that I can run on images which are too big for the input layer without cropping?

Upvotes: 1

Views: 1419

Answers (2)

Matthieu Brucher
Matthieu Brucher

Reputation: 22023

Either you use exactly the same size for the image, either you retrain the dense layers for your new image size.

You can reuse the convolutional kernels, but you cannot reuse the dense layer for a different image size.

Upvotes: 0

yihui.dev
yihui.dev

Reputation: 602

you should resize your image to 224x224 first, since VGG is trained on that resolution. It makes no sense to extract feature on higher resolution. For resizing and cropping, you can use my specialized ImageData layer: https://github.com/yihui-he/caffe-pro

Upvotes: 0

Related Questions