python - 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,
我猜这意味着我需要一个更精确的文件结构,并将代码指向正确的位置。我绝不是一名计算机科学家,我对这样的事情是如何工作的以及如何工作的理解几乎为零。关于我做错了什么以及如何解决问题的任何建议?
解决方案
从错误消息中,我的猜测args.save_dir
是None
. 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
. 将其设为必需参数并删除默认值可能很有用,因为主函数依赖于它。
推荐阅读
- python - Pycma - fmin 迭代
- wordpress - 如何使用 Elementor 将 Mailchimp 集成到 wordpress 中
- javascript - 编写代码以打印从 1 到 `num` 的所有数字 JavaScript
- python - 在导入的文件中找不到函数,但仍然有效
- node.js - discord bot没有声音
- javascript - 为什么我不能从我的表单中获取价值?(JavaScript)
- mysql - codeigniter 中出现奇怪的内部服务器错误
- javascript - Javascript 生成的带有 -/+ 按钮的范围滑块无法按预期工作
- python - .split(" ") 与 .split() 之间有区别吗
- html - 当我直接使用它们而不是css上的“奇数”和“偶数”时如何选择多个数字?