warped warped - 1 year ago 521
Python Question

Unknown layer type (crop) in Caffe for windows

I want to use the following convolutional neural network:


with caffe built from https://github.com/BVLC/caffe/tree/windows

for windows 10 with visual studio 2013, CUDA 7.5, cudNN 4 and python support.

Now, when i call either of the two networks supplied with

net = caffe.Net('xyz.prototxt', 'xyz.caffemodel', caffe.TEST)

I get the following error:

Error parsing text-format caffe.NetParameter: 43:85: Unknown enumeration value of "CROP" for field "type".

Line 43 of the network looks as follows:

layers { bottom: 'd3c' bottom: 'u3a' top: 'd3cc' name: 'crop_d3c-d3cc' type: CROP }

I have looked online and some people seem to encounter the same error message. I could not find any solutions, however.

My question now is: how do I get rid of this error?

Help is greatly appreciated!


Changing the .prototxt as suggested by Dale Song eliminated this error, but led to another one:

[libprotobuf ERROR ..\src\google\protobuf\text_format.cc:274] Error parsing text-format caffe.NetParameter: 10:102: Message type "caffe.LayerParameter" has no field named "blobs_lr".

I fixed this by replacing

blobs_lr: 1 weight_decay: 1 blobs_lr: 2 weight_decay: 0


param {lr_mult: 1 decay_mult: 1} param {lr_mult: 2 decay_mult: 0}

in the .prototxt, as suggested here.


Answer Source


You should modify net.prototxt from:

layers { ... type: CROP }


layer { ... type: "Crop" }

and meanwhile, other layers' parameter in the prototxt should also be modified similarly to:

layer { ... type: "TypeString" },

and the TypeString can be found from:

  1. The line REGISTER_LAYER_CLASS(some_layer_name) in related some_layer_name_layer.cpp file. For example, REGISTER_LAYER_CLASS(Data) in data_layer.cpp means the TypeString should be Data when writing a data layer in net.prototxt.
  2. REGISTER_LAYER_CREATOR(some_layer_name, GetSomeLayer) in layer_factory.cpp. For example, REGISTER_LAYER_CREATOR(Convolution, GetConvolutionLayer) means the TypeString should be Convolution when writing a convolution layer in net.prototxt.


The reason for your problem is: you used an old layer parameter format

layers { ... type: SOMELAYERNAME }.

and this format coming from V1LayerParameter in caffe.proto doesn't support some newer layer type including the crop layer. You can confirm this by checking that enum LayerType of V1LayerParameter doesn't include layer type CROP.

To avoid this probelm, you can always use the newest format:

layer { ... type: "TypeString" }

in which the TypeString can be found in the 2 places mentioned above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download