Skip to content Skip to sidebar Skip to footer

Tensorflow/tflearn: Valueerror: Cannot Feed Value Of Shape (256, 400, 400) For Tensor U'targetsdata/y:0', Which Has Shape '(?, 64)'

I'd like to make a ConvNet with the same size of output as one of input. So, I implemented it using TFLearn library. Because I just wanted a simple example satisfying those purpose

Solution 1:

The problem is that your convnet output has a shape of (None, 64), but your are giving target data (labels) with a shape of (None, 400, 400). I am not sure what you want to do with your code, are you trying to do some auto-encoding? or is it for a classification task?

For auto-encoder, the following is a convolutional auto encoder for MNIST, you can just adapt it with your own data and change input_data shape:

from __future__ import division, print_function, absolute_import

import numpy as np
import matplotlib.pyplot as plt
import tflearn
import tflearn.data_utils as du

# Data loading and preprocessingimport tflearn.datasets.mnist as mnist
X, Y, testX, testY = mnist.load_data(one_hot=True)

X = X.reshape([-1, 28, 28, 1])
testX = testX.reshape([-1, 28, 28, 1])
X, mean = du.featurewise_zero_center(X)
testX = du.featurewise_zero_center(testX, mean)

# Building the encoder
encoder = tflearn.input_data(shape=[None, 28, 28, 1])
encoder = tflearn.conv_2d(encoder, 16, 3, activation='relu')
encoder = tflearn.max_pool_2d(encoder, 2)
encoder = tflearn.conv_2d(encoder, 8, 3, activation='relu')
decoder = tflearn.upsample_2d(encoder, 2)
decoder = tflearn.conv_2d(encoder, 1, 3, activation='relu')

# Regression, with mean square error
net = tflearn.regression(decoder, optimizer='adam', learning_rate=0.001,
                         loss='mean_square', metric=None)

# Training the auto encoder
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(X, X, n_epoch=10, validation_set=(testX, testX),
          run_id="auto_encoder", batch_size=256)

# Encoding X[0] for testprint("\nTest encoding of X[0]:")
# New model, re-using the same session, for weights sharing
encoding_model = tflearn.DNN(encoder, session=model.session)
print(encoding_model.predict([X[0]]))

# Testing the image reconstruction on new data (test set)print("\nVisualizing results after being encoded and decoded:")
testX = tflearn.data_utils.shuffle(testX)[0]
# Applying encode and decode over test set
encode_decode = model.predict(testX)
# Compare original images with their reconstructions
f, a = plt.subplots(2, 10, figsize=(10, 2))
for i inrange(10):
    a[0][i].imshow(np.reshape(testX[i], (28, 28)))
    a[1][i].imshow(np.reshape(encode_decode[i], (28, 28)))
f.show()
plt.draw()
plt.waitforbuttonpress()

Post a Comment for "Tensorflow/tflearn: Valueerror: Cannot Feed Value Of Shape (256, 400, 400) For Tensor U'targetsdata/y:0', Which Has Shape '(?, 64)'"