首页 > 解决方案 > Pytorch Cityscapes 数据集,train_distribute 问题 - “类型错误:路径应该是字符串、字节、类路径或整数,而不是 NoneType”

问题描述

我对机器学习、python 等非常不熟悉,所以请原谅我不经意的错误。我正在尝试在我拥有的街景数据集上使用机器学习系统。我找到了很多资源,我正在研究这个包,它有很多例子,看起来很简单。

当我尝试运行 train_distribute.py 文件时,我收到了这个错误:

(base) corey@corona:~/Desktop/pycity/GALD-Net-master$ python train_distribute.py
 
Traceback (most recent call last):
  File "train_distribute.py", line 261, in <module>
    main()
  File "train_distribute.py", line 136, in main
    if not os.path.exists(args.save_dir):
  File "/home/corey/anaconda3/lib/python3.7/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

查看代码,它来自以下几行:

def main():

    # make save dir
    if args.local_rank == 0:
        if not os.path.exists(args.save_dir):
            os.makedirs(args.save_dir)
    # launch the logger
    Log.init(
        log_level=args.log_level,

我猜这意味着我需要一个更精确的文件结构,并将代码指向正确的位置。我绝不是一名计算机科学家,我对这样的事情是如何工作的以及如何工作的理解几乎为零。关于我做错了什么以及如何解决问题的任何建议?

标签: pythonpytorchimage-segmentationtraining-datanonetype

解决方案


从错误消息中,我的猜测args.save_dirNone. os.path.exists不能None作为路径处理:

>>> import os
>>> os.path.exists(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/genericpath.py", line 19, in exists
    os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

查看您引用的脚本,save_dir参数的默认值为None. 将其设为必需参数并删除默认值可能很有用,因为主函数依赖于它。


推荐阅读