【问题标题】:Is it possible to view the code of a torch pretrained network是否可以查看torch预训练网络的代码
【发布时间】:2018-04-30 01:47:36
【问题描述】:

如果您在阅读标题时正在考虑这样一个菜鸟 - 是的,我是。

我在 Google 上搜索过,但没有找到可以让我查看预训练的 Torch 神经网络是如何设计/编码的指南。我已经下载了预训练的网络(文件格式 .t7)并安装了 torch。谁能帮我查看它是如何编码的(使用什么尺寸的过滤器,使用的参数等)?

可能因为不可能,所以不在 Google 上?很乐意回答您的任何其他问题或任何不清楚的地方。

谢谢。

【问题讨论】:

    标签: torch pytorch pre-trained-model


    【解决方案1】:

    我认为不可能得到底层代码。但是你可以通过 print 得到模型的摘要,包括层和主要参数。

    model = SumModel(vocab_size=vocab_size, hiddem_dim=hidden_dim, batch_size=batch_size)
    # saving model
    torch.save(model, 'test_model.save')
    # print summary of original
    print(' - original model summary:')
    print(model)
    print()
    
    # load saved model
    loaded_model = torch.load('test_model.save')
    # print summary of loaded model
    print(' - loaded model summary:')
    print(loaded_model)
    

    这将输出如下所示的摘要。

      - original model summary:
    SumModel(
      (word_embedding): Embedding(530734, 128)
      (encoder): LSTM(128, 128, batch_first=True)
      (decoder): LSTM(128, 128, batch_first=True)
      (output_layer): Linear(in_features=128, out_features=530734, bias=True)
    )
    
     - loaded model summary:
    SumModel(
      (word_embedding): Embedding(530734, 128)
      (encoder): LSTM(128, 128, batch_first=True)
      (decoder): LSTM(128, 128, batch_first=True)
      (output_layer): Linear(in_features=128, out_features=530734, bias=True)
    )
    

    使用 Pytorch 0.4.0 测试

    如您所见,原始模型和加载模型的输出是一致的。

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 2016-09-16
      • 2020-02-03
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      相关资源
      最近更新 更多