Tensorflow convolution network

I want to reuse the code from the MNIST example for Tensorflow professionals . My images are 388px X 191px, just 2 classes. Source code can be found here . I tried to reuse this code by changing only the input and output levels , as shown below:

input level

x = tf.placeholder("float", shape=[None, 74108]) y_ = tf.placeholder("float", shape=[None, 2]) x_image = tf.reshape(x, [-1,388,191,1]) 

output level

 W_fc2 = weight_variable([1024, 2]) b_fc2 = bias_variable([2]) 

Running modified code gives an undefined stack:

 W tensorflow/core/common_runtime/executor.cc:1027] 0x2136510 Compute status: Invalid argument: Input has 14005248 values, which isn't divisible by 3136 [[Node: Reshape_4 = Reshape[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_5, Reshape_4/shape)]] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1267, in run _run_using_default_session(self, feed_dict, self.graph, session) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2763, in _run_using_default_session session.run(operation, feed_dict) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 345, in run results = self._do_run(target_list, unique_fetch_targets, feed_dict_string) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 419, in _do_run e.code) tensorflow.python.framework.errors.InvalidArgumentError: Input has 14005248 values, which isn't divisible by 3136 [[Node: Reshape_4 = Reshape[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_5, Reshape_4/shape)]] Caused by op u'Reshape_4', defined at: File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 554, in reshape name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1710, in create_op original_op=self._default_original_op, op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 988, in __init__ self._traceback = _extract_stack() 
+7
python neural-network tensorflow convolution conv-neural-network
source share
1 answer
 tensorflow.python.framework.errors.InvalidArgumentError: Input has 14005248 values, which isn't divisible by 3136 [[Node: Reshape_4 = Reshape[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_5, Reshape_4/shape)]] 

But the way you performed it does not allow you to see the actual line causing the problem. Save it in a file and python <file> .

  File "<stdin>", line 1, in <module> 

But the answer is that you did not change the size of your convolution and layer pools, so when you used 28x28 images to run, they ended up shrinking to 7x7x (convolutional_depth). Now you run huge images, so after the first convolutional layer and 2x2 maxpool you have a VERY BIG thing that you are trying to feed, but you will redo:

 h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) h_pool2 = max_pool_2x2(h_conv2) W_fc1 = weight_variable([7 * 7 * 64, 1024]) b_fc1 = bias_variable([1024]) 

The output of h_pool2 is much larger with your large images. You need to compress them more - most likely with more convolutional and maximum levels. You can also try increasing the size of W_fc1 according to the size of the input that gets there. It works through two 2x2 maxpools - each reduces the size by 2 in sizes x and y. 28x28x1 β†’ 14x14x32 β†’ 7x7x64. So your images go from 388 x 191 β†’ 194 x 95 β†’ 97 x 47

As a warning, a fully connected level with inputs 97 * 47 = 4559 will slowly slow down.

+7
source share

All Articles