deep-learning-models icon indicating copy to clipboard operation
deep-learning-models copied to clipboard

Feature request: VGG-FACE weights

Open kgrm opened this issue 9 years ago • 21 comments

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

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

kgrm avatar Aug 05 '16 22:08 kgrm

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.

fchollet avatar Aug 09 '16 17:08 fchollet

@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.

IvanDrokin avatar Aug 15 '16 16:08 IvanDrokin

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

fchollet avatar Aug 15 '16 21:08 fchollet

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 avatar Aug 23 '16 16:08 victorhcm

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())

victorhcm avatar Aug 24 '16 13:08 victorhcm

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 https://github.com/fchollet/deep-learning-models/issues/1#issuecomment-242056033, or mute the thread https://github.com/notifications/unsubscribe-auth/AArWbzLlFtoaLKnicYa7hOoL70GGUfrkks5qjEG4gaJpZM4JeGxo .

fchollet avatar Aug 24 '16 15:08 fchollet

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.

victorhcm avatar Aug 27 '16 14:08 victorhcm

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

kgrm avatar Aug 27 '16 15:08 kgrm

@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

MarcBS avatar Sep 01 '16 09:09 MarcBS

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

kashif avatar Oct 04 '16 08:10 kashif

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

EncodeTS avatar Oct 17 '16 00:10 EncodeTS

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

abskjha avatar Oct 22 '16 05:10 abskjha

@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

kashif avatar Oct 22 '16 07:10 kashif

@kashif , Thanks for sharing the network weights.

abskjha avatar Oct 23 '16 12:10 abskjha

@kashif FYI it's not there anymore.

danielvarga avatar Oct 28 '16 13:10 danielvarga

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

staywithme23 avatar Oct 28 '16 19:10 staywithme23

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?

kashif avatar Oct 28 '16 19:10 kashif

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.

danielvarga avatar Oct 28 '16 20:10 danielvarga

@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')

`

bienbinod avatar Feb 20 '17 09:02 bienbinod

@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.

MarcBS avatar Feb 20 '17 09:02 MarcBS

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

bienbinod avatar Feb 20 '17 10:02 bienbinod