J'essayais de construire un Encodeur Variation Auto avec Tensorflow. J'ai commencé avec le modèle le plus simple. J'ai la méthode suivante:Correction de la couche de déconvolution dans Tensorflow
def conv_layer(x, w_shape, b_shape, padding='SAME'):
W = weight_variable(w_shape)
tf.summary.histogram(W.name, W)
b = bias_variable(b_shape)
tf.summary.histogram(b.name, b)
# Note that I used a stride of 2 on purpose in order not to use max pool layer.
activations = tf.nn.relu(tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding=padding) + b)
tf.summary.histogram(activations.name, activations)
return activations
def deconv_layer(x, w_shape, b_shape, padding="SAME"):
W = weight_variable(w_shape)
tf.summary.histogram(W.name, W)
b = bias_variable(b_shape)
tf.summary.histogram('bias', b)
x_shape = tf.shape(x)
out_shape = tf.stack([x_shape[0], x_shape[1], x_shape[2], w_shape[2]])
# Note that I have used a stride of 2 since I used a stride of 2 in conv layer.
transposed_activations = tf.nn.conv2d_transpose(x, W, out_shape, [1, 1, 1, 1], padding=padding) + b
tf.summary.histogram(transposed_activations.name, transposed_activations)
return transposed_activations
Et le modèle de l'ensemble du réseau est la suivante:
with tf.name_scope('conv1'):
conv1 = conv_layer(image, [3, 3, 3, 32], [32])
with tf.name_scope('conv2'):
conv2 = conv_layer(conv1, [3, 3, 32, 64], [64])
with tf.name_scope('conv3'):
conv3 = conv_layer(conv2, [3, 3, 64, 128], [128])
with tf.name_scope('conv4'):
conv4 = conv_layer(conv3, [3, 3, 128, 256], [256])
with tf.name_scope('z'):
z = conv_layer(conv4, [3, 3, 256, 256], [256])
with tf.name_scope('deconv4'):
deconv4 = deconv_layer(z, [3, 3, 128, 256], [128])
with tf.name_scope('deconv3'):
deconv3 = deconv_layer(deconv4, [3, 3, 64, 128], [64])
with tf.name_scope('deconv2'):
deconv2 = deconv_layer(deconv3, [3, 3, 32, 64], [32])
with tf.name_scope('deconv1'):
deconv_image = deconv_layer(deconv2, [3, 3, 3, 32], [3])
Je reçois mes images d'un FIFOQueue
et les introduire dans ce modèle. La taille de mes images est 112, 112, 3
. Mon problème est lors du changement des progrès de [1, 1, 1, 1] to [1, 2, 2, 1]
dans les deux conv et deconv couches I obtenu l'erreur suivante:
InvalidArgumentError (see above for traceback): Conv2DSlowBackpropInput: Size of out_backprop doesn't match computed: actual = 4, computed = 2
[[Node: deconv4/conv2d_transpose = Conv2DBackpropInput[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/gpu:0"](deconv4/stack, deconv4/Variable/read, z/Relu)]]
[[Node: deconv1/add/_17 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_85_deconv1/add", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
PS: Je sais que je manque la fonction d'activation à la couche deconv, mais je suppose que cela n'a rien à voir avec l'erreur que j'obtiens. Toute aide est très appréciée !!
J'ai la même erreur. L'avez-vous résolu? – freude
@freude, j'espère que ma réponse a du sens pour vous. S'il vous plaît aimez si vous êtes convaincu. –
@freude, j'ai bien réglé la solution. J'oublie de mentionner le problème avec la forme de sortie. Veuillez revoir la réponse finale et l'accepter si vous étiez convaincu !! merci –