hnarayanan / artistic-style-transfer

Convolutional neural networks for artistic style transfer.
https://harishnarayanan.org/writing/artistic-style-transfer/
354 stars 79 forks source link

Error on 6th notebook #1

Closed JohnReid closed 7 years ago

JohnReid commented 7 years ago

I followed the instructions but I get this error when running step 8 of the 6th notebook. Any ideas what might be wrong? Looking forward to tomorrow.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-2dbcbeeb6bc8> in <module>()
      1 model = VGG16(input_tensor=input_tensor, weights='imagenet',
----> 2               include_top=False)

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/applications/vgg16.pyc in VGG16(include_top, weights, input_tensor, input_shape, classes)
     94     x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv1')(x)
     95     x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv2')(x)
---> 96     x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)
     97 
     98     # Block 3

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in __call__(self, x, mask)
    570         if inbound_layers:
    571             # This will call layer.build() if necessary.
--> 572             self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
    573             # Outputs were already computed when calling self.add_inbound_node.
    574             outputs = self.inbound_nodes[-1].output_tensors

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)
    633         # creating the node automatically updates self.inbound_nodes
    634         # as well as outbound_nodes on inbound layers.
--> 635         Node.create_node(self, inbound_layers, node_indices, tensor_indices)
    636 
    637     def get_output_shape_for(self, input_shape):

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)
    164 
    165         if len(input_tensors) == 1:
--> 166             output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
    167             output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0]))
    168             # TODO: try to auto-infer shape

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/layers/pooling.pyc in call(self, x, mask)
    158                                         strides=self.strides,
    159                                         border_mode=self.border_mode,
--> 160                                         dim_ordering=self.dim_ordering)
    161         return output
    162 

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/layers/pooling.pyc in _pooling_function(self, inputs, pool_size, strides, border_mode, dim_ordering)
    208         output = K.pool2d(inputs, pool_size, strides,
    209                           border_mode, dim_ordering,
--> 210                           pool_mode='max')
    211         return output
    212 

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in pool2d(x, pool_size, strides, border_mode, dim_ordering, pool_mode)
   2864 
   2865     if pool_mode == 'max':
-> 2866         x = tf.nn.max_pool(x, pool_size, strides, padding=padding)
   2867     elif pool_mode == 'avg':
   2868         x = tf.nn.avg_pool(x, pool_size, strides, padding=padding)

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.pyc in max_pool(value, ksize, strides, padding, data_format, name)
   1791                                 padding=padding,
   1792                                 data_format=data_format,
-> 1793                                 name=name)
   1794 
   1795 

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.pyc in _max_pool(input, ksize, strides, padding, data_format, name)
   1596   result = _op_def_lib.apply_op("MaxPool", input=input, ksize=ksize,
   1597                                 strides=strides, padding=padding,
-> 1598                                 data_format=data_format, name=name)
   1599   return result
   1600 

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.pyc in apply_op(self, op_type_name, name, **keywords)
    761         op = g.create_op(op_type_name, inputs, output_types, name=scope,
    762                          input_types=input_types, attrs=attr_protos,
--> 763                          op_def=op_def)
    764         if output_structure:
    765           outputs = op.outputs

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
   2395                     original_op=self._default_original_op, op_def=op_def)
   2396     if compute_shapes:
-> 2397       set_shapes_for_outputs(ret)
   2398     self._add_op(ret)
   2399     self._record_op_seen_by_control_dependencies(ret)

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in set_shapes_for_outputs(op)
   1755       shape_func = _call_cpp_shape_fn_and_require_op
   1756 
-> 1757   shapes = shape_func(op)
   1758   if shapes is None:
   1759     raise RuntimeError(

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in call_with_requiring(op)
   1705 
   1706   def call_with_requiring(op):
-> 1707     return call_cpp_shape_fn(op, require_shape_fn=True)
   1708 
   1709   _call_cpp_shape_fn_and_require_op = call_with_requiring

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.pyc in call_cpp_shape_fn(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
    608     res = _call_cpp_shape_fn_impl(op, input_tensors_needed,
    609                                   input_tensors_as_shapes_needed,
--> 610                                   debug_python_shape_fn, require_shape_fn)
    611     if not isinstance(res, dict):
    612       # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).

/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.pyc in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
    673       missing_shape_fn = True
    674     else:
--> 675       raise ValueError(err.message)
    676 
    677   if missing_shape_fn:

ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') with input shapes: [3,256,1,128].
hnarayanan commented 7 years ago

I am not sure, will check and write back as soon as I find something!

LukasMosser commented 7 years ago

@JohnReid Can you also post which version of Keras you are running, Tensorflow or Theano backend? Linux, Mac or Windows?

hnarayanan commented 7 years ago

@JohnReid: I too suspect that you might be using the Theano backend assuming you've installed versions of packages as mentioned in this repository's requirements.txt.

Could you make your~/.keras/keras.json look like the following and see if the problem goes away?

{
    "image_dim_ordering": "tf", 
    "epsilon": 1e-07, 
    "floatx": "float32", 
    "backend": "tensorflow"
}
JohnReid commented 7 years ago

That works now when I change the image_dim_ordering from th to tf. Thanks for your help. It might be nice to set these options in the code to avoid anyone else having this problem...

hnarayanan commented 7 years ago

Did you set it in the keras config file or somewhere in the notebook code? And if you did it in the notebook code, could you share a snippet?

JohnReid commented 7 years ago

No I did it in the config file but I don't like changing that as I have other code that relies on those settings. I think the calls to set the relevant config are documented here: https://keras.io/backend/

hnarayanan commented 7 years ago

I see, thanks. I have, for now, added the config file notes to the README. Perhaps someone else will point this out tomorrow with a more notebook-specific fix. :)