在训练模型前,根据模型文件存放地址判断文件是否存在,当文件不存在时,通过os.mknod()方法创建空文件,然后系统会报错
store_path = base_path + NetType + '.pt'
if not os.path.exists(store_path):
print("模型不存在!建立空模型")
os.mknod(store_path)
# os.makedirs(store_path)
print("模型存储路径:" + store_path)
网上普遍的回答大多是 windows 系统不支持 mknod 而 Ubuntu 系统上没有问题
解决方法是 使用open("xxxx",mode = "w",encoding=None)
store_path = base_path + NetType + '.pt'
if not os.path.exists(store_path):
print("模型不存在!建立空模型")
open(store_path,mode = "w",encoding=None)
# os.makedirs(store_path)
print("模型存储路径:" + store_path)
w 的用法可见这篇博客:
(130条消息) Python 打开文件 with open() 方法中文含义及‘r‘、‘w‘、‘x‘、‘a‘、‘b‘、‘t‘、‘+‘、‘U‘_daphne odera�的博客-CSDN博客
报错1: TypeError: an integer is required (got type str)
open方法内添加 encoding=None 或 encoding=“utf-8”
报错2:TypeError: open() missing required argument 'flags' (pos 2)
将 from os import open 改为 from io import open