【发布时间】:2017-07-23 15:13:07
【问题描述】:
我有以下代码块:
def new_weights(shape):
return tf.Variable(tf.truncated_normal(shape, stddev=0.05))
还有:
def new_conv_layer(input, # The previous layer
use_pooling=True): # Use 2x2 max-pooling
shape = [3, 3, 1, 8]
weights = new_weights(shape=shape)
biases = new_biases(length=8)
layer = tf.nn.conv2d(input=input,
filter=weights,
strides=[1, 1, 1, 1],
padding='SAME')
layer += biases
if use_pooling:
layer = tf.nn.max_pool(value=layer,
ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1],
padding='SAME')
layer = tf.nn.relu(layer)
# relu(max_pool(x)) == max_pool(relu(x)) we can
# save 75% of the relu-operations by max-pooling first.
return layer
所以我们可以观察到过滤器的大小是3x3,过滤器的数量是8。过滤器是用随机值定义的。
我需要做的是将我所有的8个过滤器定义为固定值,即预定值,例如:
weigths = [
[[0, 1, 0,],[0, -1, 0,],[0, 0, 0,],],
[[0, 0, 1,],[0, -1, 0,],[0, 0, 0,],],
[[0, 0, 0,],[0, -1, 1,],[0, 0, 0,],],
[[0, 0, 0,],[0, -1, 0,],[0, 0, 1,],],
[[0, 0, 0,],[0, -1, 0,],[0, 1, 0,],],
[[0, 0, 0,],[0, -1, 0,],[1, 0, 0,],],
[[0, 0, 0,],[1, -1, 0,],[0, 0, 0,],],
[[1, 0, 0,],[0, -1, 0,],[0, 0, 0,],]
]
我无法想象,我怎么能在我的代码中做这个修改,有没有人知道我该怎么做?
非常感谢您!
【问题讨论】:
标签: python python-2.7 tensorflow convolution