【问题标题】:load a trained model in other process with tflearn使用 tflearn 在其他进程中加载​​经过训练的模型
【发布时间】:2017-12-19 13:58:00
【问题描述】:

我正在尝试保存模型并使用 tflearn 库将其加载到其他进程中......

于是我生成了模型:

lenx = 21908
leny = 81
# Build neural network
net = tflearn.input_data(shape=[None, lenx])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, leny, activation='softmax')
net = tflearn.regression(net)

# Define model and setup tensorboard
model = tflearn.DNN(net, tensorboard_dir='tflearn_logs')
# Start training (apply gradient descent algorithm)
model.fit(train_x, train_y, n_epoch=10, batch_size=8, show_metric=True)
model.save('model.tflearn')

这行得通! 然后在其他文件中,要在其他进程中运行,我正在尝试以这种方式加载它:

lenx = 21908
leny = 81
# Build neural network
net = tflearn.input_data(shape=[None, lenx])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, leny, activation='softmax')
net = tflearn.regression(net)

model = tflearn.DNN(net, tensorboard_dir='tflearn_logs')

model.load("model.tflearn")

但我得到了这个错误:

ValueError: Cannot feed value of shape (1, 0) for Tensor 'InputData/X:0', which has shape '(?, 21908)'

我尝试了很多方法,但都不起作用。

【问题讨论】:

  • 您好,您对此有答复吗?

标签: python tensorflow tflearn


【解决方案1】:

您将成为的神经网络架构 加载应该是一样的。此外,您不必定义 最后一层,因为有 将没有培训。不要使用线路 net = tflearn.regression(net)

【讨论】:

    【解决方案2】:

    我认为您缺少的是负载中的“weights_only=True”参数:

    model.load("model.tflearn", weights_only=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      相关资源
      最近更新 更多