fchollet / deep-learning-models

Keras code and weights files for popular deep learning models.
MIT License
7.32k stars 2.46k forks source link

Feature request: VGG-FACE weights #1

Open kgrm opened 8 years ago

kgrm commented 8 years ago

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

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

fchollet commented 8 years ago

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

@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 commented 8 years ago

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

victorhcm commented 8 years ago

It seems the prototxt provided with VGG-FACE is an old version (see https://github.com/ethereon/caffe-tensorflow/issues/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 commented 8 years ago

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

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

On 24 August 2016 at 06:06, Victor Hugo notifications@github.com 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 https://github.com/fchollet/deep-learning-models/issues/1#issuecomment-242056033, or mute the thread https://github.com/notifications/unsubscribe-auth/AArWbzLlFtoaLKnicYa7hOoL70GGUfrkks5qjEG4gaJpZM4JeGxo .

victorhcm commented 8 years ago

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

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

@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

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

Test

python test_converted_VGG_FACE.py

kashif commented 8 years ago

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

EncodeTS commented 8 years ago

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

abskjha commented 8 years ago

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

kashif commented 8 years ago

@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 commented 8 years ago

@kashif , Thanks for sharing the network weights.

danielvarga commented 8 years ago

@kashif FYI it's not there anymore.

staywithme23 commented 8 years ago

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

kashif commented 8 years ago

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

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

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

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

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