对于一个嵌入式项目,我在Tensorflow中训练了一个网络,现在我正在基于Numpy / Scipy的模型脚本中重新加载变量。但是,我不清楚如何使用自己的权重重做conv2d步骤。
我看过以下链接:Difference between Tensorflow convolution and numpy convolution, 但是我还没有联系到权重是四维的问题。
这是我的Tensorflow代码:
# input shape: (1, 224, 224, 1)
weight1 = tf.Variable([3,3,1,16],stddev)
conv1 = tf.nn.conv2d(input,w,[1,1,1,1])
# conv1 shape: (1, 224, 224, 16)
weight2 = tf.Variable([3,3,16,32],stddev)
conv2 = tf.nn.conv2d(conv2,w,[1,1,1,1])
# conv2 shape: (1, 224, 224, 32)
当我尝试使用Scipy或Numpy库中的卷积函数时,输出尺寸不正确:
from scipy.ndimage.filters import convolve
conv1 = convolve(input, weight1[::-1])
# conv1 shape: (1, 224, 224, 1)
conv2 = convolve(conv1, weight2[::-1])
# conv2 shape: (1, 224, 224, 16)