title: Getting "OSError: Unable to open file Permission denied " when trying to open trained model using keras in python
body: <p>After following through some video tutorials, I have successfully trained a machine learning model using python 3.6, tensorflow and keras. But when I'm trying to open my trained model, it throws an error saying</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>Here's the code snippet I used to save the trained model</p>
  
  <pre><code>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])
  </code></pre>
  
  <p>Here's how I'm trying to open that trained model from another python file.</p>
  
  <pre><code>import cv2
  import tensorflow as tf
  
  CATEGORIES = ["Dog", "Cat"]
  
  def prepare(filepath):
    IMG_SIZE = 70
    img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
    new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
    return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
  
  model = tf.keras.models.load_model("logs/{}".format("Cats-vs-dog-cnn-64x2"))
  </code></pre>
  
  <p>Here's the complete error log.</p>
  
  <blockquote>
    <p>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"))<br>
    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 <strong>init</strong>
        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<br>
    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)</p>
  </blockquote>
  
  <p>Any help would be appreciated.</p>