ValueError: Input 0 of layer dense is incompatible with the layer:...解决办法

ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 784 but received input with shape (128, 28, 28)

源代码:

    x = next(iter(test_db))
    x_new_logits = model(x)
    x_new = tf.sigmoid(x_rec_logits)
    x_new = tf.reshape(x_new,[-1, 28, 28]).numpy()*255.
    x_new = x_hat.astype(np.uint8)
    save_images(x_hat,'vae_images/rec_epoch%d.png'%epoch)

形状不一致导致,加入:x = tf.reshape(x,[-1, 784])

    x = next(iter(test_db))
    x = tf.reshape(x,[-1, 784])
    x_new_logits,_,_ = model(x)
    x_new = tf.sigmoid(x_rec_logits)
    x_new = tf.reshape(x_new,[-1, 28, 28]).numpy()*255.
    x_new = x_hat.astype(np.uint8)

问题解决。

你可能感兴趣的:(tensorflow,python,python,numpy,深度学习)