Open gaara100 opened 7 years ago
@gaara100 Could you be using tensorflow backend with "image_dim_ordering": "th" ?
I have the same error.
ValueError: Negative dimension size caused by subtracting 2 from 1 for 'block2_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,800,128].
keras.json seems to be Ok:
{
"image_dim_ordering": "tf",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
In method preprocess_image the ordering is transposed for theano (depth, rows, columns), but the MaxPooling layer expects (because of your keras.json) an ordering for tensorflow (rows, columns, depth). Change the "image_dim_ordering" to "th" and it should work.
It doesn't help: no matter which image_dim_ordering I'm using ("th" or "tf"), error is the same:
ValueError: Negative dimension size caused by subtracting 2 from 1 for 'block2_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,800,128]. I've tried to change line 87 of deep_dream.py to
img = img.transpose((0, 1, 2)).astype('float64')
with a same result.
And only iff I change my backend to Theano, it starts working, but I run into another error after 5 serconds:
Traceback (most recent call last): File "deep_dream.py", line 220, in
loss_and_grads = create_loss_function(dream, settings, model, img_shape) File "deep_dream.py", line 115, in create_loss_function assert layer_name in layer_dict.keys(), 'Layer ' + layer_name + ' not found in model.' AssertionError: Layer conv5_1 not found in model.
I'm not sure, that my Theano setup is Ok (never used it or Keras before), but my Tensorflow working for sure — I can work with a Tensorflow example of Deepdream.
The problem you are facing now is because conv5_1 is part of a different graph (model) than the one you selected.
btw with these settings { "image_dim_ordering": "th", "epsilon": 1e-07, "floatx": "float32", "backend": "tensorflow" }
everything worked fine for me
I can't seem to get this to work. I am running a VM Ubuntu with the latest keras and tensorflow CPU.
When I run it: deeplearning@deep-learning-virtual-machine:~/Desktop$ python3 deep_dream.py vgg16 jesse.png dream
I get the following: Using TensorFlow backend. (1080, 1620, 4) (900, 1350, 4) (750, 1125, 4) Starting octave 0 with dimensions 1125 x 750 Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py", line 671, in _call_cpp_shape_fn_impl input_tensors_as_shapes, status) File "/usr/lib/python3.5/contextlib.py", line 66, in exit next(self.gen) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 2 from 1 for 'block2_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,375,128].
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "deep_dream.py", line 198, in
model = vgg16.VGG16(include_top=False, input_tensor=dream)
File "/home/deeplearning/Desktop/deep_learning_models/vgg16.py", line 119, in VGG16
x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 554, in call
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/layers/pooling.py", line 154, in call
data_format=self.data_format)
File "/usr/local/lib/python3.5/dist-packages/keras/layers/pooling.py", line 217, in _pooling_function
pool_mode='max')
File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 3012, in pool2d
x = tf.nn.max_pool(x, pool_size, strides, padding=padding)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/nn_ops.py", line 1793, in max_pool
name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 1598, in _max_pool
data_format=data_format, name=name)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
op_def=op_def)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2329, in create_op
set_shapes_for_outputs(ret)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1717, in set_shapes_for_outputs
shapes = shape_func(op)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1667, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
debug_python_shape_fn, require_shape_fn)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 2 from 1 for 'block2_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,375,128].
Am I doing something wrong? This looks like great work, I might just be a noob. Thanks