【问题标题】:Fast.ai learn.export() stopped working with no apparent code changeFast.ai learn.export() 在没有明显代码更改的情况下停止工作
【发布时间】:2020-08-04 23:52:34
【问题描述】:

我一直在 colab 上训练和导出模型的多个版本。我的导出代码一直是这样的:

model.export('model.pkl')

我已经能够重新加载模型并做出预测以确认一切正常,如下所示:

x = load_learner('', 'model.pkl')
x.predict()

突然之间,导出代码的行为有所不同。我仍然可以在 colab 上毫无问题地导出和 load_learner,但是当我将模型文件从 colab 下载到本地机器并尝试在本地运行时,我收到此错误:

Traceback (most recent call last):
  File "process.py", line 127, in <module>
    predict_utterances_in_transcript(i, path_to_processed_and_predicted_transcript_dir, audio_id)
  File "process.py", line 94, in predict_utterances_in_transcript
    predict()
  File "/Users/src/predict.py", line 9, in predict_utterances
    model = load_learner('', 'models/model.pkl')
  File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/fastai/basic_train.py", line 621, in load_learner
    state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
  File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/torch/serialization.py", line 586, in load
    with _open_zipfile_reader(f) as opened_zipfile:
  File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/torch/serialization.py", line 246, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
AttributeError: 'PosixPath' object has no attribute 'tell'

此外,到目前为止,我还可以在文本编辑器中打开和读取模型 pickle 文件。损坏的模型文件无法读取,因为错误提示它们已损坏。

我的代码或环境没有任何变化。有什么想法吗?

【问题讨论】:

    标签: python deep-learning neural-network pytorch fast-ai


    【解决方案1】:

    我遇到了完全相同的问题。从torch 1.5 迁移到torch 1.6 为我解决了这个问题。之后,下载的 pkl 文件就像一个魅力。 安装后,在 python 控制台中,导入 torch 并检查 torch 版本。它应该返回:'1.6.0'

    最好的问候, 斯蒂芬

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-11
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多