나는 tensorflow가있는 약간의 신경망을 구현하려고합니다. 그러나 나는 첫 번째 단계에서 이미 문제가있다.tensorflow : theano에 비해 convolution에서의 이상한 결과 (비록 뒤집히지 않고)
내가 입력 할 때 다음과 같은 theano.tensor.nnet.conv2d을 사용하여, 나는 예상 된 결과 얻을 : 나는 tf.nn.conv2d에 presumingly 같은 일을 수행 할 때
import theano.tensor as T
import theano
import numpy as np
# Theano expects input of shape (batch_size, channels, height, width)
# and filters of shape (out_channel, in_channel, height, width)
x = T.tensor4()
w = T.tensor4()
c = T.nnet.conv2d(x, w, filter_flip=False)
f = theano.function([x, w], [c], allow_input_downcast=True)
base = np.array([[1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1]]).T
i = base[np.newaxis, np.newaxis, :, :]
print f(i, i) # -> results in 3 as expected because np.sum(i*i) = 3
그러나, 내 결과가 다릅니다
import tensorflow as tf
import numpy as np
# TF expects input of (batch_size, height, width, channels)
# and filters of shape (height, width, in_channel, out_channel)
x = tf.placeholder(tf.float32, shape=(1, 4, 3, 1), name="input")
w = tf.placeholder(tf.float32, shape=(4, 3, 1, 1), name="weights")
c = tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='VALID')
with tf.Session() as sess:
base = np.array([[1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1]]).T
i = base[np.newaxis, :, :, np.newaxis]
weights = base[:, :, np.newaxis, np.newaxis]
res = sess.run(c, feed_dict={x: i, w: weights})
print res # -> results in -5.31794233e+37
을 tensorflow에서 컨볼 루션 연산의 레이아웃은 theano와 약간 다르므로 입력이 약간 다르게 보입니다. 그러나 Theano의 strides는 기본적으로 (1,1,1,1)이고 유효한 convolution이 기본값이기 때문에 이것은 똑같은 입력이어야합니다.
또한 tensorflow는 커널을 뒤집지 않습니다 (교차 상관 구현).
동일한 결과가 표시되지 않는 이유는 무엇입니까? 사전에
덕분에,
는