【发布时间】:2019-12-01 04:29:44
【问题描述】:
我想将我的数据从 2d 转换为 3d,因为我创建了自动编码器,其中代码(隐藏层)有 3 个神经元。训练开始时会抛出异常。
import numpy as np
import tensorflow as tf
from tensorflow.keras import layers
from sklearn.datasets import make_circles
input_vector = layers.Input(shape=(1,2))
encoded = layers.Dense(3,activation="relu")(input_vector)
input_encoded = layers.Input(shape=(3,))
x = layers.Dense(3,activation="relu")(input_encoded)
decoded = layers.Reshape((1,2))(x)
encoder = tf.keras.Model(input_vector, encoded, name="encoder")
decoder = tf.keras.Model(input_encoded, decoded, name="decoder")
autoencoder = tf.keras.Model(input_vector, decoder(encoder(input_vector)), name="autoencoder")
autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
count = 1000
X, y = make_circles(n_samples=count, noise=0.05)
x_test, y = make_circles(n_samples=count, noise=0.05)
X = np.reshape(X,(count,1,2))
x_test = np.reshape(x_test,(count,1,2))
autoencoder.fit(X, X,
epochs=5,
batch_size=100,
shuffle=True,
validation_data=(x_test, x_test))
实际结果抛出异常
---------------------------------------------------------------------------
InvalidArgumentError: Input to reshape is a tensor with 300 values, but the requested shape has 200
[[{{node decoder_1/reshape_1/Reshape}}]]
【问题讨论】:
标签: python tensorflow keras autoencoder tf.keras