deep learning - Tensorflow: Invalid Argument Error in Convolution -


i trying run bit of python code , can't seem around error:

tf.nn.conv2d(tf.reshape(x, [5, 5]), tf.reshape(wt, [3, 3]), strides=[1, 1],  padding='same') 

here, x tf.variable (5,5) numpy array , w tf.variable (3,3) numpy array.

the error is:

--------------------------------------------------------------------------- invalidargumenterror                      traceback (most recent call last) c:\anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)     669           node_def_str, input_shapes, input_tensors, input_tensors_as_shapes, --> 670           status)     671   except errors.invalidargumenterror err:  c:\anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback)      65             try: ---> 66                 next(self.gen)      67             except stopiteration:  c:\anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()     468           compat.as_text(pywrap_tensorflow.tf_message(status)), --> 469           pywrap_tensorflow.tf_getcode(status))     470   finally:  invalidargumenterror: shape must rank 4 rank 2 'conv2d_19' (op: 'conv2d') input shapes: [5,5], [3,3]. 

in order use tf.nn.conv2d. both input , filter should transformed 4d. also, strides should 1-d of length 4 (sliding window each 1 of dimensions of input). following taken documentation:

given input tensor of shape [batch, in_height, in_width, in_channels] , filter / kernel tensor of shape [filter_height, filter_width, in_channels, out_channels], op performs following:

flattens filter 2-d matrix shape [filter_height * filter_width * in_channels, output_channels]. extracts image patches input tensor form virtual tensor of shape [batch, out_height, out_width, filter_height * filter_width * in_channels]. each patch, right-multiplies filter matrix , image patch vector.

you can take : tf.reshape(x, [1, 5, 5, 1]) data, tf.reshape(wt, [3, 3, 1, 1]) filter, , strides=[1, 1, 1, 1]. results in:

tf.nn.conv2d(tf.reshape(x, [1, 5, 5, 1]), tf.reshape(wt, [3, 3, 1, 1]), strides=[1, 1, 1, 1],  padding='same') 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -