title: how to fix 'Unable to create file' error when trying to save model weights while training
body: <p>I am doing image-captioning project while training I try to save model weight 
  by model.save('./model_weights1/model_'+ str(i) + '.h5') after every epoch but I get error</p>
  
  <p>It returns </p>
  
  <blockquote>
    <p>Unable to create file (unable to open file: name = './model_weights1/model_0.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 602)</p>
  </blockquote>
  
  <p>I have checked the directory path exists and path also seems to be correct</p>
  
  <h2>CODE:</h2>
  
  <pre><code>for i in range(epochs):
      generator = data_loader(train_descriptions,encoded_images,maxlen,batch_size,word_to_idx)
      model.fit_generator(generator,epochs=1,steps_per_epoch=steps,verbose = 1)
      model.save('./model_weights1/model_'+ str(i) + '.h5')
  </code></pre>
  
  <hr>
  
  <p>ERROR</p>
  
  <hr>
  
  <pre><code>OSError                                   Traceback (most recent call last)
  &lt;ipython-input-58-00c04165c7ca&gt; in &lt;module&gt;()
        2     generator = data_loader(train_descriptions,encoded_images,maxlen,batch_size,word_to_idx)
        3     model.fit_generator(generator,epochs=1,steps_per_epoch=steps,verbose = 1)
  ----&gt; 4     model.save('./model_weights1/model_'+ str(i) + '.h5',overwrite=True)
  
  ~/anaconda3/lib/python3.6/site-packages/keras/engine/network.py in save(self, filepath, overwrite, include_optimizer)
     1088             raise NotImplementedError
     1089         from ..models import save_model
  -&gt; 1090         save_model(self, filepath, overwrite, include_optimizer)
     1091 
     1092     def save_weights(self, filepath, overwrite=True):
  
  ~/anaconda3/lib/python3.6/site-packages/keras/engine/saving.py in save_model(model, filepath, overwrite, include_optimizer)
      377         opened_new_file = False
      378 
  --&gt; 379     f = h5dict(filepath, mode='w')
      380 
      381     try:
  
  ~/anaconda3/lib/python3.6/site-packages/keras/utils/io_utils.py in __init__(self, path, mode)
      184             self._is_file = False
      185         elif isinstance(path, str):
  --&gt; 186             self.data = h5py.File(path, mode=mode)
      187             self._is_file = True
      188         elif isinstance(path, dict):
  
  ~/anaconda3/lib/python3.6/site-packages/h5py/_hl/files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
      267             with phil:
      268                 fapl = make_fapl(driver, libver, **kwds)
  --&gt; 269                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
      270 
      271                 if swmr_support:
  
  ~/anaconda3/lib/python3.6/site-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
      103         fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
      104     elif mode == 'w':
  --&gt; 105         fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
      106     elif mode == 'a':
      107         # 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 = './model_weights1/model_0.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 602)
  </code></pre>
  
  <hr>