Search code examples
pythontensorflowkerasspyder

Tensorflow and Keras: OSError: unable to create model file, permission denied


I am using Anaconda Spyder 4.0.1, 64-bit windows and TensorFlow version 2.0. I am trying to follow this tutorial (https://www.pyimagesearch.com/2020/05/04/covid-19-face-mask-detector-with-opencv-keras-tensorflow-and-deep-learning/), in order to detect the person with and without a facemask. I am trying to generate a classifier file, it is giving me this error.

[INFO] saving mask detector model...
Traceback (most recent call last):
  File "train_mask_detector.py", line 141, in <module>
   model.save(args["model"], save_format="h5")
File "C:\Users\Ravi\anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 975, in save
signatures, options)
 File "C:\Users\Ravi\anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 112, in save_model
   model, filepath, overwrite, include_optimizer)
File "C:\Users\Ravi\anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 92, in save_model_to_hdf5
f = h5py.File(filepath, mode='w')
 File "C:\Users\Ravi\anaconda3\lib\site-packages\h5py\_hl\files.py", line 408, in __init__
swmr=swmr)
 File "C:\Users\Ravi\anaconda3\lib\site-packages\h5py\_hl\files.py", line 179, in make_fid
fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
 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 108, in h5py.h5f.create
OSError: Unable to create file (unable to open file: name = 'C:\Users\Ravi\Downloads\face-mask-detector\face-mask-detector', errno = 13, error message = 'Permission denied', flags = 13, o_flags = 302)

I am running the file in prompt using this command.

python train_mask_detector.py --dataset C:\Users\Ravi\Downloads\face-mask-detector\face-mask-detector\dataset --plot C:\Users\Ravi\Downloads\face-mask-detector\face-mask-detector --model C:\Users\Ravi\Downloads\face-mask-detector\face-mask-detector

In the train_mask_detector.py model is being saved in this way.

# serialize the model to disk
print("[INFO] saving mask detector model...")
model.save(args["model"], save_format="h5")

What can I do to solve this problem?


Solution

  • It got solved by model.save ('name_of_model.model'), rather than saving in 'h5' or 'hdf5' format.