在完成了一些视频教程之后,我已经成功地使用python3.6、tensorflow和keras训练了一个机器学习模型。但是当我试图打开我的训练模型时,它抛出一个错误OSError: Unable to open file (unable to open file: name = 'logs/Cats-vs-dog-cnn-64x2', errno = 13, error message = 'Permission denied', flags = 0, o_flags = 0)
这是我用来保存训练模型的代码片段NAME = "Cats-vs-dog-cnn-64x2"
tensorboard = TensorBoard(log_dir='logs/{}'.format(NAME))
model = Sequential()
model.add(Conv2D(64, (3,3), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Conv2D(64, (3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit(X, y, batch_size=5, epochs=10, validation_split=0.1, callbacks=[tensorboard])
下面是我如何从另一个python文件打开经过训练的模型。在
^{pr2}$
这是完整的错误日志。在Traceback (most recent call last): File
"C:\Users\Thamindu\Music\test\test.py", line 12, in
model = tf.keras.models.load_model("logs/{}".format("Cats-vs-dog-cnn-64x2"))
File
"C:\Users\Thamindu\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\engine\saving.py",
line 219, in load_model
f = h5py.File(filepath, mode='r') File "C:\Users\Thamindu\AppData\Local\Programs\Python\Python36\lib\site-packages\h5py_hl\files.py",
line 394, in init
swmr=swmr) File "C:\Users\Thamindu\AppData\Local\Programs\Python\Python36\lib\site-packages\h5py_hl\files.py",
line 170, in make_fid
fid = h5f.open(name, flags, fapl=fapl) File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File
"h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5f.pyx", line 85, in h5py.h5f.open OSError: Unable to open
file (unable to open file: name = 'logs/Cats-vs-dog-cnn-64x2', errno =
13, error message = 'Permission denied', flags = 0, o_flags = 0)
任何帮助都将不胜感激。在