Hyperspectral icon indicating copy to clipboard operation
Hyperspectral copied to clipboard

Error in the 'Conv2D' op in IndianPinesCNN class

Open sayantanghosh opened this issue 7 years ago • 12 comments

Hello, I just noticed a strange error while running the Decoder Spatial CNN notebook before getting into the code. I am running it with python3.5 and tensorflow 1.4. Just thought of bringing it to your notice. Specifically, the IndianPinesCNN.inference(), execution of line 70:

z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='VALID')

raised the error:

InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'conv_1/Conv2D' (op: 'Conv2D') with input shapes: [1,1,1,220], [3,3,220,500]

Here is the output when I run the decoder():


InvalidArgumentError Traceback (most recent call last) /usr/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 653 graph_def_version, node_def_str, input_shapes, input_tensors, --> 654 input_tensors_as_shapes, status) 655 except errors.InvalidArgumentError as err:

/usr/lib64/python3.5/contextlib.py in exit(self, type, value, traceback) 65 try: ---> 66 next(self.gen) 67 except StopIteration:

/usr/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py in raise_exception_on_not_ok_status() 465 compat.as_text(pywrap_tensorflow.TF_Message(status)), --> 466 pywrap_tensorflow.TF_GetCode(status)) 467 finally:

InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'conv_1/Conv2D' (op: 'Conv2D') with input shapes: [1,1,1,220], [3,3,220,500].

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) in () ----> 1 predicted_image,predicted_results = decoder()

in decoder() 11 conv2, 12 fc1, ---> 13 fc2) 14 15 eval_correct = IndianPinesCNN.evaluation(logits, labels_placeholder)

/home/Hyperspectral-master/IndianPinesCNN.py in inference(images, conv1_channels, conv2_channels, fc1_units, fc2_units) 68 # Flattening the 3D image into a 1D array 69 x_image = tf.reshape(images, [-1,IMAGE_SIZE,IMAGE_SIZE,CHANNELS]) ---> 70 z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='VALID') 71 print (z) 72 h_conv1 = tf.nn.relu(z+biases, name=scope.name)

/usr/lib/python3.5/site-packages/tensorflow/python/ops/gen_nn_ops.py in conv2d(input, filter, strides, padding, use_cudnn_on_gpu, data_format, name) 395 strides=strides, padding=padding, 396 use_cudnn_on_gpu=use_cudnn_on_gpu, --> 397 data_format=data_format, name=name) 398 return result 399

/usr/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords) 765 op = g.create_op(op_type_name, inputs, output_types, name=scope, 766 input_types=input_types, attrs=attr_protos, --> 767 op_def=op_def) 768 if output_structure: 769 outputs = op.outputs

/usr/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device) 2630 original_op=self._default_original_op, op_def=op_def) 2631 if compute_shapes: -> 2632 set_shapes_for_outputs(ret) 2633 self._add_op(ret) 2634 self._record_op_seen_by_control_dependencies(ret)

/usr/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in set_shapes_for_outputs(op) 1909 shape_func = _call_cpp_shape_fn_and_require_op 1910 -> 1911 shapes = shape_func(op) 1912 if shapes is None: 1913 raise RuntimeError(

/usr/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in call_with_requiring(op) 1859 1860 def call_with_requiring(op): -> 1861 return call_cpp_shape_fn(op, require_shape_fn=True) 1862 1863 _call_cpp_shape_fn_and_require_op = call_with_requiring

/usr/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in call_cpp_shape_fn(op, require_shape_fn) 593 res = _call_cpp_shape_fn_impl(op, input_tensors_needed, 594 input_tensors_as_shapes_needed, --> 595 require_shape_fn) 596 if not isinstance(res, dict): 597 # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).

/usr/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, require_shape_fn) 657 missing_shape_fn = True 658 else: --> 659 raise ValueError(err.message) 660 661 if missing_shape_fn:

ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv_1/Conv2D' (op: 'Conv2D') with input shapes: [1,1,1,220], [3,3,220,500].

sayantanghosh avatar Nov 03 '17 18:11 sayantanghosh

I have the same question @sayantanghosh , how did you solve it?

ghost avatar Jan 22 '18 12:01 ghost

@Hatinennshiro: I rewrote the code with the same parameters and architecture, but also with tensorboard support. The tensorboard visualisation is a little rough around the edges though.

sayantanghosh avatar Jan 22 '18 12:01 sayantanghosh

@Hatinennshiro did you solve it?

HKCaesar avatar May 04 '18 16:05 HKCaesar

Did anyone get to a solution for this? I'm getting the same error, albeit with different dimensions:

InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1 for 'conv_1/Conv2D' (op: 'Conv2D') with input shapes: [100,1,1,220], [3,3,220,500].

ariasfx avatar Jun 10 '18 17:06 ariasfx

@sayantanghosh do you mind sharing the code for how you solved the issue? I'm still running into this error

sidbala2310 avatar Jun 29 '18 20:06 sidbala2310

@sidbala2310 I suggest that you follow the tf API documentation and rewrite the code with the more recent tf.estimator module.

sayantanghosh avatar Jul 09 '18 05:07 sayantanghosh

@ariasfx did you solve it ? do you mind sharing the code for how you solved the issue?

HAOJIEFENGLANG avatar Jul 11 '18 09:07 HAOJIEFENGLANG

@HKCaesar did you solve it ? do you mind sharing the code for how you solved the issue?

HAOJIEFENGLANG avatar Jul 11 '18 09:07 HAOJIEFENGLANG

@HAOJIEFENGLANG @sidbala2310 @ariasfx I will fork and upload the code in a couple of days.

sayantanghosh avatar Jul 12 '18 03:07 sayantanghosh

Can anyone send the modified code to [email protected] for the error- Negative dimension size caused by subtracting 3 from 1 for 'conv_1/Conv2D' (op: 'Conv2D') with input shapes: [100,1,1,220], [3,3,220,500].

sandeep-25 avatar Oct 29 '18 13:10 sandeep-25

Replace this line z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='VALID') to z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='SAME') in inference fucntion of IndianPinesCNN.py file

sohailkhanmarwat avatar Dec 17 '18 11:12 sohailkhanmarwat

Replace this line z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='VALID') to z = tf.nn.conv2d(x_image, weights, strides=[1, 1, 1, 1], padding='SAME') in inference fucntion of IndianPinesCNN.py file

can't fix it...

Rambo-7 avatar Jul 03 '20 02:07 Rambo-7