iamaaditya / VQA_Demo

Visual Question Answering Demo on pretrained model
http://iamaaditya.github.io/2016/04/visual_question_answering_demo_notebook
MIT License
242 stars 133 forks source link

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

Open iAppCloudSolutions opened 5 years ago

iAppCloudSolutions commented 5 years ago

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 commented 5 years ago

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

mevanekanayake commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

I have updated the link. Try now.

Thanks and Regards Adi

On Wed, Sep 22, 2021 at 3:04 PM Aryan Gupta @.***> wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/iamaaditya/VQA_Demo/issues/25#issuecomment-925224371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOTJ4T6J67LSQOHMOFIT2DUDISCXANCNFSM4GWLVHZA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

beingaryan commented 3 years ago

I'm running on Google colab, I'm getting the following error ValueError: Unknown layer: Merge. Please ensure this object is passed to thecustom_objectsargument. 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:https://github.com/keras-team/keras/issues/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`