【问题标题】:Pytorch Cityscapes Dataset, train_distribute problem - "Typeerror: path should be string, bytes, pathlike or integer, not NoneType"Pytorch Cityscapes 数据集,train_distribute 问题 - “类型错误:路径应该是字符串、字节、类路径或整数,而不是 NoneType”
【发布时间】:2020-06-22 17:58:37
【问题描述】:

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

当我尝试运行 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,

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

【问题讨论】:

    标签: python pytorch image-segmentation training-data nonetype


    【解决方案1】:

    根据错误消息,我猜args.save_dirNoneos.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
    

    看看你引用的脚本,the save_dir argument has a default value of None。将其设为必需参数并删除默认值可能很有用,因为 main 函数依赖于它。

    【讨论】:

      【解决方案2】:

      您必须指定 save_dir 作为参数。

      像这样运行代码 python train_distribute.py --save_dir=SAVE_PATH

      这里 SAVE_PATH 将采用您想要保存输出的路径。 另外,请注意,如果给定路径指定的文件夹不存在,则将创建该文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-05
        • 1970-01-01
        • 1970-01-01
        • 2020-03-25
        相关资源
        最近更新 更多