报错内容

raise NotImplementedError(“cannot instantiate %r on your system”
NotImplementedError: cannot instantiate ‘PosixPath’ on your system’‘’
在这里插入图片描述

报错原因:

模型在linux训练后windows路径加载错误(路径错误问题)

解决方案1:在调用PosixPath时修改

  1. windows系统读取时,报错:NotImplementedError: cannot instantiate ‘PosixPath’ on your system
    在代码的最前面加上:
import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
  1. Linux系统读取时,报错:NotImplementedError: cannot instantiate ‘WindowsPath’ on your system
    在代码的最前面加上:
import pathlib
pathlib.WindowsPath = pathlib.PosixPath

解决方案2:修改…\anaconda3\envs\ADP\lib\pathlib.py文件

 def __new__(cls, *args, **kwargs):
        if cls is Path:
            cls = WindowsPath if os.name == 'nt' else PosixPath
        self = cls._from_parts(args)
 		
 		#添加代码
        if type(self) == PosixPath:
            cls = WindowsPath
            self = cls._from_parts(args)

        if not self._flavour.is_supported:
            raise NotImplementedError("cannot instantiate %r on your system"
                                      % (cls.__name__,))
        return self

如图:在这里插入图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐