ethereon / caffe-tensorflow

Caffe models in TensorFlow
Other
2.8k stars 1.04k forks source link

Problems with using different converted caffemodels to finetune mnist data #48

Open gesuwen opened 8 years ago

gesuwen commented 8 years ago

Hi,

I modified the finetune_mnist.py by importing the .npy model as well as the corresponding weight converted from several caffemodels(including VGG16, AlexNet, GoogLenet, etc.) using convert.py. However, all of the coverted models except the original LeNet generate a traceback error like follow(The following used AlexNet model):

Traceback (most recent call last): File "finetune_mnist.py", line 34, in net = MyNet({'data': images}) File "/home/username/Documents/caffe-tensorflow/examples/mnist/kaffe/tensorflow/network.py", line 43, in init self.setup() File "/home/username/Documents/caffe-tensorflow/examples/mnist/mynet.py", line 10, in setup .conv(5, 5, 256, 1, 1, group=2, name='conv2') File "/home/username/Documents/caffe-tensorflow/examples/mnist/kaffe/tensorflow/network.py", line 21, in layer_decorated layer_output = op(self, layer_input, _args, *_kwargs) File "/home/username/Documents/caffe-tensorflow/examples/mnist/kaffe/tensorflow/network.py", line 131, in conv output_groups = [convolve(i, k) for i, k in zip(input_groups, kernel_groups)] File "/home/username/Documents/caffe-tensorflow/examples/mnist/kaffe/tensorflow/network.py", line 121, in convolve = lambda i, k: tf.nn.conv2d(i, k, [1, s_h, s_w, 1], padding=padding) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 394, in conv2d data_format=data_format, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 704, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2262, in create_op set_shapes_for_outputs(ret) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1702, in set_shapes_for_outputs shapes = shape_func(op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/common_shapes.py", line 246, in conv2d_shape padding) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/common_shapes.py", line 184, in get2d_conv_output_size (row_stride, col_stride), padding_type) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/common_shapes.py", line 149, in get_conv_output_size "Filter: %r Input: %r" % (filter_size, input_size)) ValueError: Filter must not be larger than the input: Filter: (5, 5) Input: (2, 2)

where the coverted AlexNet.py tensorflow code is as follow:

class AlexNet(Network): def setup(self): (self.feed('data') .conv(11, 11, 96, 4, 4, padding='VALID', name='conv1') .lrn(2, 2e-05, 0.75, name='norm1') .max_pool(3, 3, 2, 2, padding='VALID', name='pool1') .conv(5, 5, 256, 1, 1, group=2, name='conv2') .lrn(2, 2e-05, 0.75, name='norm2') .max_pool(3, 3, 2, 2, padding='VALID', name='pool2') .conv(3, 3, 384, 1, 1, name='conv3') .conv(3, 3, 384, 1, 1, group=2, name='conv4') .conv(3, 3, 256, 1, 1, group=2, name='conv5') .max_pool(3, 3, 2, 2, padding='VALID', name='pool5') .fc(4096, name='fc6') .fc(4096, name='fc7') .fc(1000, relu=False, name='fc8') .softmax(name='prob'))

I would like to know what might be the possible reason causing this common 'filter larger than input size' error and how could I fix it?

Thanks!

ethereon commented 8 years ago

A bit late, but: it appears that the input is too small for the model and is getting downsampled beyond the kernel size.