具有多个预测的张量流错误

时间:2018-08-24 23:42:01

标签: tensorflow neural-network tflearn

此代码生成器使我可以保存“模型”

# Network building
netg = tflearn.input_data([None, 12])
netg = tflearn.embedding(netg, input_dim=10000, output_dim=12)
netg = tflearn.lstm(netg, 4, dropout=0.8,dynamic=True)
netg = tflearn.fully_connected(netg, 2, activation='softmax')
netg = tflearn.regression(netg, optimizer='adam', learning_rate=0.001,loss='categorical_crossentropy')

# Training
modelg = tflearn.DNN(netg, tensorboard_verbose=0)
model.fit(trainX, trainY, validation_set=(testX, testY), show_metric=True, batch_size=20,n_epoch=10)
modelg.load('NNmodeloLSTMsell.model',weights_only=True)
model.save('NNmodeloLSTMsell.model')

我使用这段代码进行这样的预测

def predictorLSTMsell(t):


# Network building
netg = tflearn.input_data([None, 12])
netg = tflearn.embedding(netg, input_dim=10000, output_dim=12)
netg = tflearn.lstm(netg, 4, dropout=0.8,dynamic=True)
netg = tflearn.fully_connected(netg, 2, activation='softmax')
netg = tflearn.regression(netg, optimizer='adam', learning_rate=0.001,loss='categorical_crossentropy')

# Training
modelg = tflearn.DNN(netg, tensorboard_verbose=0)
#model.fit(trainX, trainY, validation_set=(testX, testY), show_metric=True, batch_size=20,n_epoch=10)
modelg.load('NNmodeloLSTMsell.model',weights_only=True)
t= np.array(t)
t = t.reshape([-1, 12])

print('t predict',( np.round(modelg.predict([t[0]])[0]) ))

当我两次尝试使用'predictorLSTMsell()'时,这给了我一个错误。它第一次起作用,但是第二次却给了我这个错误。

enter image description here

enter image description here

0 个答案:

没有答案