raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.97k stars 664 forks source link

filenotfound Error : Keras vis for windows. #146

Closed tonystark12 closed 5 years ago

tonystark12 commented 5 years ago

I am facing the following error statement

    FileNotFoundError: [WinError 3] The system cannot find the path specified: '/tmp/5pido2dr.h5'

when trying to run keras-vis. The code block causing the error :

    layer_idx = utils.find_layer_idx(model, 'dense_2') #after naming the layers
    model.layers[layer_idx].activation = activations.softmax
    model = utils.apply_modifications(model)

for class_idx in np.arange(10):    
     indices = np.where(y_train[:, class_idx] == 1.)[0]
     idx = indices[0]

     grads = visualize_saliency(model, layer_idx, filter_indices=class_idx, 
                           seed_input=X_train[idx], 
     backprop_modifier='guided')

     f, ax = plt.subplots(1, 2)
     ax[0].imshow(X_train[idx][..., 0])
     ax[1].imshow(grads, cmap='jet')

     savename = "layer_activations" + str(class_idx) + ".png"
     f.savefig(savename)

and the complete error output :

    OSError                                   Traceback (most recent call last)
    c:\python36\lib\site-packages\vis\utils\utils.py in apply_modifications(model)
        122     try:
    --> 123         model.save(model_path)
        124         return load_model(model_path)

    c:\python36\lib\site-packages\keras\engine\network.py in save(self, filepath, overwrite, include_optimizer)
        1084         from ..models import save_model
     -> 1085         save_model(self, filepath, overwrite, include_optimizer)
        1086 

    c:\python36\lib\site-packages\keras\engine\saving.py in save_model(model, filepath, overwrite, include_optimizer)
        104 
    --> 105         f = h5py.File(filepath, mode='w')
        106         opened_new_file = True

    c:\python36\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
        311                 fapl = make_fapl(driver, libver, **kwds)
    --> 312                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
        313 

    c:\python36\lib\site-packages\h5py\_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
        147     elif mode == 'w':
    --> 148         fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
        149     elif mode == 'a':

    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 = '/tmp/5pido2dr.h5', errno = 2, error message = 'No such file or directory', flags = 13, o_flags = 302)

    During handling of the above exception, another exception occurred:

    FileNotFoundError                         Traceback (most recent call last)
    <ipython-input-20-df7d3b5036c3> in <module>()
          1 layer_idx = utils.find_layer_idx(model, 'dense_2') #after naming the layers
          2 model.layers[layer_idx].activation = activations.softmax
    ----> 3 model = utils.apply_modifications(model)
          4 
          5 for class_idx in np.arange(10):

     c:\python36\lib\site-packages\vis\utils\utils.py in apply_modifications(model)
         ** 124         return load_model(model_path)
          125     finally:
      --> 126         os.remove(model_path)
          127 
          128 

     FileNotFoundError: [WinError 3] The system cannot find the path specified: '/tmp/5pido2dr.h5'

There is an OS error preceding which appears to be the primary cause. I am not sure why this error arises. The .h5 filename keeps changing. With due research, I have suggestions that this could be a environmental variable issue and requires reinstall.

But am not sure the right method for debug. I am using WIN 10, with python 3.6.5, and jupyter 4.4.0

Upon further investigation into utils.py, I realize that the path "/tmp/..." is hard coded and thus appears to support only Unix. Am I missing something here?

tonystark12 commented 5 years ago

Please do let me know if the question is naive. 👍

keisen commented 5 years ago

Hi @tonystark12 . Sorry, probably, this issue was already fixed, but it is not released yet. So please re-install keras-vis via github.

pip install git+https://github.com/raghakot/keras-vis.git -U

Thanks!

tonystark12 commented 5 years ago

Hi @tonystark12 . Sorry, probably, this issue was already fixed, but it is not released yet. So please re-install keras-vis via github.

pip install git+https://github.com/raghakot/keras-vis.git -U

Thanks!

Thank you for your reply. I shall try the same and get back to you with the results.! I had installed directly from pip earlier.

tonystark12 commented 5 years ago

It worked. Thanks for the info.

morenoh149 commented 5 years ago

@tonystark12 please close your issue if resolved

sauravmishra1710 commented 4 years ago

I am facing the same issue with Keras Vis.

ValueError: Unknown initializer: GlorotUniform

model.layers[layer_index].activation = activations.linear model = utils.apply_modifications(model)

I have tried all the possible approaches mentioned above. Also tried re-installing via pip install git+https://github.com/raghakot/keras-vis.git -U

Let me know if a solution is available for this.