【问题标题】:After loading a trained model in torch, how to use this loaded model to classify new inputs?在torch中加载一个训练好的模型后,如何使用这个加载的模型对新的输入进行分类?
【发布时间】:2016-08-14 18:35:46
【问题描述】:

我正在使用作者提供的code 复制作品“用于文本分类的字符级卷积网络”。

当我完成训练过程后,我得到了存储在“sequential_50000_1458876622.t7b”中的转储模型,其可视化图像为sequential_50000_1458876622.png

我一直试图弄清楚如何在训练后应用转储模型。我不确定如何在新的未分类数据上使用它。这是我在torch7中尝试过的:

th> model=torch.load("sequential_5000_1458675427.t7b")
th> model

它显示:

nn.Sequential {
[input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> output]
  (1): nn.TemporalConvolution
  (2): nn.Threshold
  (3): nn.TemporalMaxPooling
  (4): nn.TemporalConvolution
  (5): nn.Threshold
  (6): nn.TemporalMaxPooling
  (7): nn.TemporalConvolution
  (8): nn.Threshold
  (9): nn.TemporalConvolution
  (10): nn.Threshold
  (11): nn.TemporalConvolution
  (12): nn.Threshold
  (13): nn.TemporalConvolution
  (14): nn.Threshold
  (15): nn.TemporalMaxPooling
  (16): nn.Reshape(8704)
  (17): nn.Linear(8704 -> 1024)
  (18): nn.Threshold
  (19): nn.Dropout(0.000000)
  (20): nn.Linear(1024 -> 1024)
  (21): nn.Threshold
  (22): nn.Dropout(0.000000)
  (23): nn.Linear(1024 -> 14)
  (24): nn.LogSoftMax
}

我不知道如何使用这个模型来预测新的未分类数据。

【问题讨论】:

    标签: deep-learning torch conv-neural-network


    【解决方案1】:

    您需要通过模型的前向传递运行所需的案例;捕获返回的预测值:

    score = model:forward(input_case)
    

    根据您的模型的返回参数,分数可以是单个分类或最佳选择的向量;相应地配置您的报告。

    如果您需要更完整的示例,请尝试搜索“torch7 score tutorial”。为了让您更快速地开始,here 是 GitHub 上 Torch 教程下的一个相对简洁的示例。

    【讨论】:

    • 谢谢,修剪。我将运行正确的“分数”代码并按照您的建议学习本教程。
    猜你喜欢
    • 2021-12-05
    • 2017-12-12
    • 2021-03-22
    • 2017-09-01
    • 1970-01-01
    • 2019-12-12
    • 2019-07-08
    • 1970-01-01
    • 2021-02-19
    相关资源
    最近更新 更多