rcmalli / keras-vggface

VGGFace implementation with Keras Framework
MIT License
928 stars 417 forks source link

README.md example fails #8

Closed oxydron closed 7 years ago

oxydron commented 7 years ago

Tried to run the example on the README of this repo and got this:

Traceback (most recent call last):
  File "feature_extractors.py", line 128, in <module>
    main()
  File "feature_extractors.py", line 120, in main
    vgg_model_fc7 = Model(image_input, out)
  File "/home/bh/anaconda3/envs/keras2/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 88, in wrapper
    return func(*args, **kwargs)
  File "/home/bh/anaconda3/envs/keras2/lib/python3.6/site-packages/keras/engine/topology.py", line 1704, in __init__
    str(layers_with_complete_input))
RuntimeError: Graph disconnected: cannot obtain value for tensor Tensor("input_3:0", shape=(?, 224, 224, 3), dtype=float32) at layer "input_3". The following previous layers were accessed without issue: []

Conda enviroment (irrelevant packages excluded for clarity):

keras                     2.0.2                    py36_0  
keras-vggface             0.3                       <pip>
numpy                     1.12.1                   py36_0  
opencv                    3.1.0               np112py36_1   
python                    3.6.1                         0  
scipy                     0.19.0              np112py36_0  
tensorflow                1.1.0               np112py36_0  
theano                    0.9.0                    py36_0  
rcmalli commented 7 years ago

Thanks for pointing out. I think Keras API is changed after the last time I updated the project. The code sample in new README file should work now.

oxydron commented 7 years ago

Tried again and got this:

Traceback (most recent call last):
  File "fine_tuning.py", line 16, in <module>
    x = Flatten(name='flatten')(last_layer)
  File "/home/bh/anaconda3/envs/keras2/lib/python3.6/site-packages/keras/engine/topology.py", line 559, in __call__
    output_shape = self.compute_output_shape(input_shape)
  File "/home/bh/anaconda3/envs/keras2/lib/python3.6/site-packages/keras/layers/core.py", line 488, in compute_output_shape
    '(got ' + str(input_shape[1:]) + '. '
ValueError: The shape of the input to "Flatten" is not fully defined (got (None, None, 512). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.
oxydron commented 7 years ago

Tried to get the model summary and got this, with lots of None

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, None, None, 3)     0         
_________________________________________________________________
conv1_1 (Conv2D)             (None, None, None, 64)    1792      
_________________________________________________________________
conv1_2 (Conv2D)             (None, None, None, 64)    36928     
_________________________________________________________________
pool1 (MaxPooling2D)         (None, None, None, 64)    0         
_________________________________________________________________
conv2_1 (Conv2D)             (None, None, None, 128)   73856     
_________________________________________________________________
conv2_2 (Conv2D)             (None, None, None, 128)   147584    
_________________________________________________________________
pool2 (MaxPooling2D)         (None, None, None, 128)   0         
_________________________________________________________________
conv3_1 (Conv2D)             (None, None, None, 256)   295168    
_________________________________________________________________
conv3_2 (Conv2D)             (None, None, None, 256)   590080    
_________________________________________________________________
conv3_3 (Conv2D)             (None, None, None, 256)   590080    
_________________________________________________________________
pool3 (MaxPooling2D)         (None, None, None, 256)   0         
_________________________________________________________________
conv4_1 (Conv2D)             (None, None, None, 512)   1180160   
_________________________________________________________________
conv4_2 (Conv2D)             (None, None, None, 512)   2359808   
_________________________________________________________________
conv4_3 (Conv2D)             (None, None, None, 512)   2359808   
_________________________________________________________________
pool4 (MaxPooling2D)         (None, None, None, 512)   0         
_________________________________________________________________
conv5_1 (Conv2D)             (None, None, None, 512)   2359808   
_________________________________________________________________
conv5_2 (Conv2D)             (None, None, None, 512)   2359808   
_________________________________________________________________
conv5_3 (Conv2D)             (None, None, None, 512)   2359808   
_________________________________________________________________
pool5 (MaxPooling2D)         (None, None, None, 512)   0         
=================================================================
Total params: 14,714,688.0
Trainable params: 0.0
Non-trainable params: 14,714,688.0
_________________________________________________________________

I need to know the none values on the pool5 = (None, None, None, 512)

rcmalli commented 7 years ago

According to the Keras source codes, if the include_top is set to False, then input_shape should be (224, 224, 3) or (3,224,224) depending your backend. We should initialise the model as follows:

vgg_model = VGGFace(include_top=False, input_shape=(224, 224, 3)) #TF backend

I will also update the README file again.

oxydron commented 7 years ago

Maybe you should add those parameters inside the code and take off the parameter, no?

vgg_model = VGGFace(include_top=False) #TF backend
inside VGGFace():
...
input_shape=(224, 224, 3)
...
oxydron commented 7 years ago

Worked with your solution :+1: Thank you very much :)