【发布时间】:2020-06-19 13:07:05
【问题描述】:
这是我用来保存模型的函数。文件夹“模型”不存在。但它不应该创建一个文件夹'models'并使用写入的文件名保存模型。我在任何地方都找不到解决方案。
# Create a function to save a model
def save_model(model, suffix=None):
"""
Saves a given model in a models directory and appends a suffix (str)
for clarity and reuse.
"""
# Create model directory with current time
modeldir = os.path.join("/content/drive/My Drive/Dog Eyes/models/",
datetime.datetime.now().strftime("%Y%m%d-%H%M%s"))
model_path = modeldir + "-" + suffix + ".h5" # save format of model
print(f"Saving model to: {model_path}...")
model.save(model_path)
return model_path
我正在调用这个函数
# Save our model trained on 1000 images
save_model(model, suffix="1000-images-mobilenetv2-Adam")
这是我在执行函数时遇到的错误
Unable to create file (unable to open file: name = '/content/drive/My Drive/Dog Eyes/models/20200306-18501583520636-1000-images-mobilenetv2-Adam.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242)
完整的错误信息
Saving model to: /content/drive/My Drive/Dog Eyes/models/20200306-18501583520636-1000-images-mobilenetv2-Adam.h5...
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-62-d56ea448536c> in <module>()
----> 1 save_model(model, suffix="1000-images-mobilenetv2-Adam")
5 frames
/tensorflow-2.1.0/python3.6/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
177 fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
178 elif mode == 'w':
--> 179 fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
180 elif mode == 'a':
181 # Open in append mode (read/write).
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5f.pyx in h5py.h5f.create()
OSError: Unable to create file (unable to open file: name = '/content/drive/My Drive/Dog Eyes/models/20200306-18501583520636-1000-images-mobilenetv2-Adam.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 242)
【问题讨论】:
标签: python tensorflow machine-learning google-drive-api google-colaboratory