我正在构建一个使用LSTM作为鉴别器和分类器的GAN系统。 具有相同错误的另一个问题对我没有帮助。 错误是:
tensorflow.python.framework.errors_impl.InvalidArgumentError:您必须使用dtype float和shape [1,30,2]为占位符张量'sequential_2_input'提供值 [[节点:sequential_2_input = Placeholderdtype = DT_FLOAT,shape = [1,30,2],_ device =“/ job:localhost / replica:0 / task:0 / device:CPU:0”]]
我正在尝试重新排列this示例,但我无法使其正常工作。当我尝试生成向发生器提供噪声的假例子时会出现异常。
这是我的代码:
from keras import Sequential
from keras.layers import LSTM, Dense, np, TimeDistributed
from keras.optimizers import RMSprop, Adam
def discriminator():
net = Sequential()
input_shape = (1, 30, 2)
net.add(LSTM(10, stateful=True, batch_input_shape=input_shape))
net.add(Dense(2, activation='softmax'))
return net
def generator():
net = Sequential()
input_shape = (1, 30, 2)
net.add(LSTM(10, return_sequences=True, stateful=True, batch_input_shape=input_shape))
net.add(TimeDistributed(Dense(2, activation='linear')))
return net
net_discriminator = discriminator()
# net_discriminator.summary()
net_generator = generator()
# net_generator.summary()
optim_discriminator = RMSprop(lr=0.0008, clipvalue=1.0, decay=1e-10)
model_discriminator = Sequential()
model_discriminator.add(net_discriminator)
model_discriminator.compile(loss='binary_crossentropy', optimizer=optim_discriminator, metrics=['accuracy'])
model_discriminator.summary()
optim_adversarial = Adam(lr=0.0004, clipvalue=1.0, decay=1e-10)
model_adversarial = Sequential()
model_adversarial.add(net_generator)
# Disable layers in discriminator
for layer in net_discriminator.layers:
layer.trainable = False
model_adversarial.add(net_discriminator)
model_adversarial.compile(loss='binary_crossentropy', optimizer=optim_adversarial, metrics=['accuracy'])
model_adversarial.summary()
noise = np.random.normal(0, 1, (1, 30, 2))
fake_data = net_generator.predict(noise)
知道我做错了什么?