我想在张量流r1.2中设置卷积神经网络,结构如下:
def construct_nn2(input_layer, net2={}):
input_layer1 = tf.nn.dilation2d(
input=input_layer,
strides=[1, 1, 1, 1],
rates=[1, 1, 1, 1],
filter=[1.0, 1.0, 1],
padding='SAME',
name='dil'
)
net2['conv11'] = tf.layers.conv2d(
inputs=input_layer1,
filters=64,
kernel_size=[5, 5],
padding='same',
activation=tf.tanh,
name='conv11'
)
net2['conv12'] = tf.layers.conv2d(
inputs=net2['conv11'],
filters=64,
kernel_size=[3, 3],
padding='same',
activation=tf.tanh,
name='conv12'
)
net2['logits']= tf.layers.conv2d(
inputs=net2['conv12'],
filters=1,
kernel_size=[3, 3],
padding='same',
activation=tf.sigmoid,
name='logits'
)
return net2['logits']
扩张层吐出这些错误:
Traceback (most recent call last):
File "/home/test/Dropbox/occlusion_thesis/occ_small _2_add/main.py", line 137, in <module>
tn_prediction = construct_nn2(t_img)
File "/home/test/Dropbox/occlusion_thesis/occ_small _2_add/main.py", line 18, in construct_nn2
name='dil'
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 860, in dilation2d
name=name)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2508, in create_op
set_shapes_for_outputs(ret)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1873, in set_shapes_for_outputs
shapes = shape_func(op)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1823, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
debug_python_shape_fn, require_shape_fn)
File "/home/test/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Shape must be rank 3 but is rank 1 for 'dil' (op: 'Dilation2D') with input shapes: [1,248,360,128], [3].
我必须改变错误不会引起的。我已经阅读了dilation2d,但我仍然没有任何线索,我需要改变的是,这个层可以至少没有错误地工作。
编辑:
过滤器必须是具有相同形状的张量。
input_layer1 = tf.nn.dilation2d(
input=input_layer,
strides=[1, 1, 1, 1],
rates=[1, 1, 1, 1],
filter=tf.squeeze(input_layer, axis=0),
padding='SAME',
name='dil'
)
重构过滤器确实至少要运行。