I have copy past code from tensorflow website's introduction to autoencoder first examplefollowing code works with mnist fashion dataset but not mine.This gives me a very long warning.Please tell me what is worng with my dataset the warning screen short of same error
here x_train
is my dataset:
tf.shape(x_train)
output <tf.Tensor: shape=(3,), dtype=int32, numpy=array([169,** **28, 28])>
here x_train
is the mnist dataset:
tf.shape(x_train)
output<tf.Tensor: shape=(3,), dtype=int32, numpy=array([60000, 28, 28])>
My whole code to make dataset:
dir_path='auto/ttt/'
data=[]
x_train=[]
for i in os.listdir(dir_path):
img=image.load_img(dir_path '//' i,color_mode='grayscale',target_size=(28,28))
data=np.array(img)
data=data/255.0
x_train.append(data)
this is the warning:
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor. Received: inputs=(<tf.Tensor 'IteratorGetNext:0' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:2' shape=(None, 28)
dtype=float32>, <tf.Tensor 'IteratorGetNext:3' shape=(None, 28)
dtype=float32>, <tf.Tensor 'IteratorGetNext:4' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:5' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:6' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:7' shape=(None, 28) dtype=flo...
also this value error (same warning):
ValueError: Exception encountered when calling layer "sequential_4" (type Sequential).
Layer "flatten_2" expects 1 input(s), but it received 169 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:2' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:3' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:4' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:5' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:6' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:7' shape=(None, 28) dtype=float32>, <tf.Tensor 'IteratorGetNext:8' shape=(None, 28) dtype=float3...
CodePudding user response:
The model.fit() is given a list of arrays as input. A list of arrays is generally passed to fit() when a model has multiple inputs. In this case, the fit() method is treating each array as an input, resulting in the error.
Please convert the data to a tensor as follows and try again.
x_train=tf.convert_to_tensor(x_train)
Kindly refer to the gist for complete code. Thank you!