Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h5py/h5f.pyx in h5py.h5f.open() OSError: Unable to open file (file signature not found) #25

Open
iAppCloudSolutions opened this issue Feb 10, 2019 · 5 comments

Comments

@iAppCloudSolutions
Copy link

While running a code, we are receiving below error. Please help me out.

OSError Traceback (most recent call last)
in ()
85
86 if name == "main":
---> 87 main()

in main()
81
82 if verbose : print("\n\n\nLoading image features ...")
---> 83 image_features = get_image_features(args.image_file_name, CNN_weights_file_name)
84
85

in get_image_features(image_file_name, CNN_weights_file_name)
65 print('call image features middle')
66 print(CNN_weights_file_name)
---> 67 image_features[0,:] = get_image_model(CNN_weights_file_name).predict(im)[0]
68 return image_features
69

in get_image_model(CNN_weights_file_name)
27 print(CNN_weights_file_name)
28
---> 29 image_model = VGG_16(CNN_weights_file_name)
30
31 # this is standard VGG 16 without the last two layers

/content/drive/My Drive/VQA_Demo/models/CNN/VGG.py in VGG_16(weights_path)
99 model.add(Dense(1000, activation='softmax'))
100
--> 101 if weights_path:
102 # model.load_weights(weights_path)
103 load_model_legacy(model, weights_path)

/content/drive/My Drive/VQA_Demo/models/CNN/VGG.py in load_model_legacy(model, weight_path)
33 ''' this function is used because the weights in this model
34 were trained with legacy keras. New keras does not support loading these weights '''
---> 35
36 import h5py
37 f = h5py.File(weight_path, mode='r')

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in init(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
310 with phil:
311 fapl = make_fapl(driver, libver, **kwds)
--> 312 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
313
314 if swmr_support:

/usr/local/lib/python3.6/dist-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
140 if swmr and swmr_support:
141 flags |= h5f.ACC_SWMR_READ
--> 142 fid = h5f.open(name, flags, fapl=fapl)
143 elif mode == 'r+':
144 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper()

h5py/h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (file signature not found)

@Viktoryia-Davydovich
Copy link

You need to download VGG weights as said in models/CNN/README.md

@mevanekanayake
Copy link

Replace the get_image_features function with below:

def get_image_model(CNN_weights_file_name):
''' Takes the CNN weights file, and returns the VGG model update
with the weights. Requires the file VGG.py inside models/CNN '''
from models.CNN.VGG import VGG_16
image_model = VGG_16(CNN_weights_file_name)
image_model.pop()
image_model.pop()
# this is standard VGG 16 without the last two layers
sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
# one may experiment with "adam" optimizer, but the loss function for
# this kind of task is pretty standard
image_model.compile(optimizer=sgd, loss='categorical_crossentropy')
return image_model

@beingaryan
Copy link

The download link is broken while trying to download vgg16_weights.h5 .

PLEASE CHECK README HERE:
https://github.com/iamaaditya/VQA_Demo/tree/master/models/CNN

@iamaaditya
Copy link
Owner

iamaaditya commented Sep 22, 2021 via email

@beingaryan
Copy link

beingaryan commented Sep 22, 2021

I'm running on Google colab, I'm getting the following error
ValueError: Unknown layer: Merge. Please ensure this object is passed to the custom_objects argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.

It occurred while I tried to execute the below code
model_vqa = get_VQA_model(VQA_model_file_name, VQA_weights_file_name)

It happened when I tried load the pretrained json configuration file along with weights file present inside the VGG folder.

  1. I checked online but got nothing significant. It suggests I should use the same TF version on which the model is trained. Can you tell me the tensorflow version on which the model is trained upon?

  2. Also it is saying to add an argument of custom layer. I don't know the custom layer name with which you trained upon?
    Please check this out:can not load_model() or load_from_json() if my model contains my own Layer keras-team/keras#8612

  3. Can you tell me the modifications I need to do in the function:

`def get_VQA_model(VQA_model_file_name, VQA_weights_file_name):

# thanks the keras function for loading a model from JSON, this becomes
# very easy to understand and work. Alternative would be to load model
# from binary like cPickle but then model would be obfuscated to users
vqa_model = model_from_json(open(VQA_model_file_name).read())
# vqa_model.summary()
vqa_model.load_model(VQA_weights_file_name)
vqa_model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return vqa_model`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants