Ich versuche, einige tiefe neuronale Netzwerk mit Tensorflow zu implementieren. Aber ich habe schon ein Problem bei den ersten Schritten.tensorflow: Seltsames Ergebnis von Faltung im Vergleich zu theano (nicht umdrehen, aber)
Wenn ich geben Sie Folgendes mit theano.tensor.nnet.conv2d, erhalte ich das erwartete Ergebnis:
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
Allerdings, wenn ich die presumingly gleiche Sache in tf.nn.conv2d tun, mein Ergebnis ist anders:
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
Die Das Layout der Faltungsoperation in Tensorflow unterscheidet sich ein wenig von dem von theano, weshalb die Eingabe etwas anders aussieht. Da jedoch die Schritte in Theano auf (1,1,1,1) voreingestellt sind und auch eine gültige Faltung der Standard ist, sollte dies genau die gleiche Eingabe sein.
Darüber hinaus dreht Tensorflow den Kernel nicht (implementiert Kreuzkorrelation).
Haben Sie eine Idee, warum dies nicht das gleiche Ergebnis liefert?
Vielen Dank im Voraus,
Roman