"OSError: Unable to create file" upon adding one character to h5 save name

"OSError: Unable to create file" upon adding one character to h5 save name

作品

model.save_weights(base_path + name[:89] + '_weights.h5')

不会:

model.save_weights(base_path + name[:90] + '_weights.h5')


保存 Keras 模型权重时发生;不管 name[89:] 是什么错误 - 但 name[:89] 一切正常。想到的唯一罪魁祸首是保存名长度,但这并没有反映在错误中 - 它和下面的其他细节。

有什么办法吗?帮助表示赞赏。


OS:Win 10-17134,64 位

OSError: Unable to create file (unable to open file: name = '...', errno = 2,
error message = 'No such file or directory', flags = 13, o_flags = 302)
base_path = ("D:\Desktop\Database\Deep Learning\DL_code\models_logs\"  
           + "M22__DCSEResNet_MP1_lr5_13.5k_124x2_cnndp.5_sncnndp.1_stagedp.5"
           + "__cnnsedp.2_preodp.5_Nadam_1e-4__max.507\")

name      = ("M22__DCSEResNet_MP1_lr5_13.5k_124x2_cnndp.5_sncnndp.1"
           + "_stagedp.5__cnnsedp.2_preodp.5_Nadam_1e-4__max.507_40vals")
name[:89] = ("M22__DCSEResNet_MP1_lr5_13.5k_124x2_cnndp.5_sncnndp.1"
           + "_stagedp.5__cnnsedp.2_preodp.5_Nadam")
len(base_path + name      + '_weights.h5') = 279
len(base_path + name[:89] + '_weights.h5') = 259

几乎可以肯定是 2^8 的限制,但可能你的字符串有写成 \ 的反斜杠,所以它在 260 而不是 256 时中断。

P.S。愚蠢的我没有看到或者你编辑了你的问题并添加了路径:你的反斜杠确实写成 \.

P.P.S。实际上是 260 chars limitation