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

Feature request: VGG-FACE weights #1

Open
kgrm opened this issue Aug 5, 2016 · 21 comments
Open

Feature request: VGG-FACE weights #1

kgrm opened this issue Aug 5, 2016 · 21 comments

Comments

@kgrm
Copy link

kgrm commented Aug 5, 2016

Consider including an additional, domain-specific set of weights for the VGG model.

http://www.robots.ox.ac.uk/~vgg/software/vgg_face/

@fchollet
Copy link
Owner

fchollet commented Aug 9, 2016

Consider creating a PR to add these weights (you can upload the files on gDrive for now and I will include them in the repo). Caffe models can be automatically converted to Keras models.

@IvanDrokin
Copy link

@fchollet, can you explain how to convert Caffe model to Keras model? There is VGG-16 model trained on 205places dataset, and i want to use it in Keras. I tried to use @MarcBS code for conversion, but didn't succeed on it.

@fchollet
Copy link
Owner

I was referring to the code by @MarcBS. Why isn't it working? Marc, can you help?

@victorhcm
Copy link

victorhcm commented Aug 23, 2016

It seems the prototxt provided with VGG-FACE is an old version (see ethereon/caffe-tensorflow#44). Take a look at this comment, it points out the changes you'll have to do in VGG_FACE_deploy.prototxt.

EDIT: I modified the prototxt and it worked. Here is the updated one.

@victorhcm
Copy link

The model did convert, however when I tried to load it I got the following error:

AssertionError: Keyword argument not understood: b_learning_rate_multiplier

I tried to load it based on @MarcBS code:

from keras.models import Sequential, Graph, model_from_json
from keras.optimizers import SGD
import numpy as np
import copy
model = model_from_json(open('./Keras_model_structure.json').read())

@fchollet
Copy link
Owner

Try to only load/save the weights, not the model topology.

On 24 August 2016 at 06:06, Victor Hugo [email protected] wrote:

The model did convert, however when I tried to load it I got the following
error:

AssertionError: Keyword argument not understood: b_learning_rate_multiplier

I tried to load it based on @MarcBS code
https://github.com/MarcBS/keras/blob/master/keras/caffe/test_converted.py
:

from keras.models import Sequential, Graph, model_from_json
from keras.optimizers import SGD
import numpy as np
import copy
model = model_from_json(open('./Keras_model_structure.json').read())


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AArWbzLlFtoaLKnicYa7hOoL70GGUfrkks5qjEG4gaJpZM4JeGxo
.

@victorhcm
Copy link

It also didn't work, but I think it might be something related to the conversion.

In [12]: model = load_model('./Keras_model_weights.h5')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-9925206257bf> in <module>()
----> 1 model = load_model('./Keras_model_weights.h5')

/usr/local/lib/python2.7/dist-packages/Keras-1.0.6-py2.7.egg/keras/models.pyc in load_model(filepath, custom_objects)
    124     model_config = f.attrs.get('model_config')
    125     if model_config is None:
--> 126         raise ValueError('No model found in config file.')
    127     model_config = json.loads(model_config.decode('utf-8'))
    128     model = model_from_config(model_config, custom_objects=custom_objects)

ValueError: No model found in config file.

@kgrm
Copy link
Author

kgrm commented Aug 27, 2016

I think @fchollet meant to try to define the model in the python script and try to load the weights via model.load_weights.

@MarcBS
Copy link

MarcBS commented Sep 1, 2016

@victorhcm, I am sorry for not being able to answer sooner. I tried converting the model with your .prototxt and testing it and it worked fine for me. For clarification here I write the steps that I followed:

For all the following steps (either conversion and test) we must use the keras fork in this link.

Conversion

  • Copy the files VGG_FACE.caffemodel and VGG_FACE_deploy_updated.prototxt into to same folder (e.g. '/VGG_Face')
  • Run the following command inside the directory '/keras/caffe':

python caffe2keras.py -load_path '/VGG_Face/' -prototxt 'VGG_FACE_deploy_updated.prototxt' -caffemodel 'VGG_FACE.caffemodel'

Test

  • Inside the same directory, modify the file 'test_converted_VGG_FACE.py' (see file here). Change the model_path and the path to the image used for testing.
  • Run the following command:

python test_converted_VGG_FACE.py

@kashif
Copy link

kashif commented Oct 4, 2016

I have this more or less working... I will send a PR soonish... just in case someone else is working on this.

@EncodeTS
Copy link

EncodeTS commented Oct 17, 2016

I've already upload the weights of VGG_Face,please refer to fchollet/deep-learning-models#15.

@abskjha
Copy link

abskjha commented Oct 22, 2016

Hi,
@kashif , @victorhcm : Can you share the converted weighted of vgg-face?
Thanks.

@kashif
Copy link

kashif commented Oct 22, 2016

@slashstar you can get it from here (580MB), if I have enough space on dropbox in a few mins 🙈 :

https://www.dropbox.com/s/xnm9j3ftc1zh8tc/vgg_face_model_weights.h5?dl=0

@abskjha
Copy link

abskjha commented Oct 23, 2016

@kashif , Thanks for sharing the network weights.

@danielvarga
Copy link

@kashif FYI it's not there anymore.

@staywithme23
Copy link

@danielvarga did you get it? @slashstar The link doesn't work.

@kashif
Copy link

kashif commented Oct 28, 2016

sorry @danielvarga @adwin5 my dropbox got too full... i am putting it back...

https://www.dropbox.com/s/xnm9j3ftc1zh8tc/vgg_face_model_weights.h5?dl=0

can you try?

@danielvarga
Copy link

Got it, thank you! I've uploaded it to

http://people.mokk.bme.hu/~daniel/vgg_face_model_weights.h5

@kashif Is this okay with you? If yes: I won't give any hard promises that the above link stays live for a long time, but my expectation is that it does.

@bienbinod
Copy link

@MarcBS
Hi,

First of all, thank you for such an amazing module for converting caffe model to keras model.
I followed the instructions that you mentioned in this thread to generate the keras version of VGG face and I could convert it successfully. I used test_converted_VGG_FACE.py to test on the new face images and it works when I use your script from the same location where you are keeping. But when I bring out your script from the directory where you are keeping and run to make a prediction, it shows following error. Could you please comment on it, why its not working? I have latest keras 1.2.2 installed on my machine. I tried downgrading the version to 1.2.0 and tried to run, it still does not work.

     `Using Theano backend.
       Preparing test image.
       Loading model.
       Traceback (most recent call last):
       File "test_converted_VGG_FACE.py", line 52, in <module>
       model = model_from_json(open(model_path+'/Keras_model_structure.json').read())
       File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/models.py", line 210, in model_from_json
       return layer_from_config(config, custom_objects=custom_objects)
       File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 38, in layer_from_config
       return layer_class.from_config(config['config'], custom_objects=custom_objects)
       File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/engine/topology.py", line 2575, in from_config
process_layer(layer_data)
      File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/engine/topology.py", line 2553, in process_layer
custom_objects=custom_objects)
      File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 40, in layer_from_config
return layer_class.from_config(config['config'])
      File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/engine/topology.py", line 1016, in from_config
return cls(**config)
      File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/layers/convolutional.py", line 388, in __init__
super(Convolution2D, self).__init__(**kwargs)
     File "/Users/XXX/anaconda2/envs/python2/lib/python2.7/site-packages/keras/engine/topology.py", line 323, in __init__
    raise TypeError('Keyword argument not understood:', kwarg)
   TypeError: ('Keyword argument not understood:', u'b_learning_rate_multiplier')

`

@MarcBS
Copy link

MarcBS commented Feb 20, 2017

@bienbinod, thank you for your feedback.
If you are using the original Keras repo your converted models won't work. You must use this Keras fork, given that the converter also uses that specific version.

@bienbinod
Copy link

@MarcBS Thanks for your quick reply. I did as you suggested and it works.

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