我无法加载我的模型,因为我无法放置 PosixPath [英] I can't load my model because I can't put a PosixPath

查看:700
本文介绍了我无法加载我的模型,因为我无法放置 PosixPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个脚本,我需要使用 fast-ai 包中的一些函数.事实是,我在 Windows 上,当我定义路径时,fast-ai 中名为 load_learner 的函数无法加载模型.

I'm setting up a script and I need to use some functions from fast-ai package. The fact is that I'm on Windows and when I define my paths, the function from fast-ai named load_learner can't load the model.

我尝试将函数更改为包:

I've tried to change the function into the package as:

state = pickle.load(open(str(path) + '/' + str(fname), 'rb'))

代替:

state = pickle.load(open(path/fname, 'rb'))

但我收到此错误:

 File "lib\site-packages\fastai\basic_train.py", line 462, in load_learner
    state = pickle.load(open(path/fname, 'rb'))
  File "\lib\pathlib.py", line 1006, in __new__
    % (cls.__name__,))
NotImplementedError: cannot instantiate 'PosixPath' on your system

我的路径定义为:

folder_path = './models/model1'
fname = 'model.pkl'

我把这个函数称为:model = load_learner(folder_path, fname)

如何在此功能中使用 Windows 路径?

How can I use Windows paths in this function?

发布的答案仅在 Linux 上是正确的.我在 Windows 上仍然有这个问题.我没有找到在 Windows 上通过 PosixPath 的方法.我发现的唯一解决方案是从我的模块中更改内部包,但这不是解决此类问题的安全方法.

The answer posted was correct only on Linux. I still have the issue on Windows. I didn't find a way to pass through the PosixPath on Windows. The only solution that I found is to change the internal packages from my modules but it is not a secure way to solve this kind of issue.

提前致谢.

推荐答案

根据我自己的问题,我找到了一个方法:

According my own question, I find a way using:

from pathlib import Path

folder_path = Path('./models/model1')

<小时>

更新 1

此解决方案仅适用于 Linux,在 Windows 上我仍然遇到错误.


UPDATE 1

This solution only works on Linux, on Windows I still get an error.

这篇关于我无法加载我的模型,因为我无法放置 PosixPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆