2017-01-23 10 views
2

作成しようとしていますValueError:寸法は同じでなければなりませんが、入力形状が[Conv2D](op: 'Conv2D')の場合は1と3です。[1,400,400,1]、[1,3,3,1]

import tensorflow as tf 
import numpy as np 
from PIL import Image 
import matplotlib.pyplot as plt 

filename_queue = tf.train.string_input_producer(['/home/ubuntu/test.png']) 

reader = tf.WholeFileReader() 
key, value = reader.read(filename_queue) 

my_img = tf.image.decode_png(value) 

init_op = tf.initialize_all_variables() 
sess = tf.InteractiveSession() 
with sess.as_default(): 
    sess.run(init_op) 

coord = tf.train.Coordinator() 
threads = tf.train.start_queue_runners(coord=coord) 

for i in range(1): 
    image = my_img.eval() 
image = tf.cast(image, tf.float64) 
image = tf.expand_dims(image, 0) 

K=np.array([[0,1,0],[1,1,1],[0,1,0]]).astype(float) 
K = tf.expand_dims(K, 2) 
K = tf.expand_dims(K, 0) 


conv = tf.nn.conv2d(
     image, 
     K, 
     strides=[3, 3, 3, 3], 
     padding="SAME") 

、私はこのエラーを取得しています:

Traceback (most recent call last): 
    File "test4.py", line 35, in <module> 
    padding="SAME") 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 396, in conv2d 
    data_format=data_format, name=name) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 759, in apply_op 
    op_def=op_def) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2242, in create_op 
    set_shapes_for_outputs(ret) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1617, in set_shapes_for_outputs 
    shapes = shape_func(op) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1568, in call_with_requiring 
    return call_cpp_shape_fn(op, require_shape_fn=True) 
    File "/usr/local/lib/python2.7/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/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 675, in _call_cpp_shape_fn_impl 
    raise ValueError(err.message) 
ValueError: Dimensions must be equal, but are 1 and 3 for 'Conv2D' (op: 'Conv2D') with input shapes: [1,400,400,1], [1,3,3,1]. 

私の入力の考えだけで、入力画像、カーネルと出力コードがあるを持つことである2D入力するための単純な1層の畳み込みカーネルは3x3である

答えて

8

0123に基づいて:

shape of input = [batch, in_height, in_width, in_channels] 
shape of filter = [filter_height, filter_width, in_channels, out_channels] 

フィルタの入力と三次元の最終寸法は、入力チャネルの数を表します。あなたの場合、彼らは平等ではありません。

You can change the shape of filter to [3, 3, 1, 1]. 
+0

問題を解決していただきありがとうございます – MORagab

関連する問題