nyoki-mtl / keras-facenet

Facenet implementation by Keras2
553 stars 217 forks source link

get the exceptional answer in windows #2

Closed blackredscarf closed 6 years ago

blackredscarf commented 6 years ago

I use your notebook example to run, but get the exception answer

2018-01-31_152333

I only replace skimage resize to cv2.resive https://gist.github.com/blackredscarf/5c827eb5afa484b39e7c456a8edfd39f

windows 10 keras 2.1.3 python 3.5 tensorflow 1.4

nyoki-mtl commented 6 years ago

Thank you for your report. I got similar result on Windows. I mainly use Ubuntu, so I did not know that it doesn't work.

I notice you can load Keras model on Windows in the same way as Ubuntu. In this method, I got an error on Keras 2.0.*, but it seems to have been fixed in the recent version.

from keras.models import load_model
model_path = '../model/keras/model/facenet_keras.h5'
model = load_model(model_path)

The results were subtly different between ubuntu and windows, but it's not such a big issue.

Ubuntu

BillGates0-LarryPage0 : 1.3355295658111572
MarkZuckerberg0-MarkZuckerberg01 : 0.508682370185852

Windows

BillGates0-LarryPage0 : 1.3282160758972168
MarkZuckerberg0-MarkZuckerberg01 : 0.5875993967056274
blackredscarf commented 6 years ago

@nyoki-mtl but I get this error: IndexError: tuple index out of range

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-33cbd6678ddf> in <module>()
      1 from keras.models import load_model
      2 model_path = "../model/facenet_keras.h5"
----> 3 model = load_model(model_path)
      4 
      5 # import sys

f:\python35\lib\site-packages\keras\models.py in load_model(filepath, custom_objects, compile)
    238             raise ValueError('No model found in config file.')
    239         model_config = json.loads(model_config.decode('utf-8'))
--> 240         model = model_from_config(model_config, custom_objects=custom_objects)
    241 
    242         # set weights

f:\python35\lib\site-packages\keras\models.py in model_from_config(config, custom_objects)
    312                         'Maybe you meant to use '
    313                         '`Sequential.from_config(config)`?')
--> 314     return layer_module.deserialize(config, custom_objects=custom_objects)
    315 
    316 

f:\python35\lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
     53                                     module_objects=globs,
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

f:\python35\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    138                 return cls.from_config(config['config'],
    139                                        custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 140                                                            list(custom_objects.items())))
    141             with CustomObjectScope(custom_objects):
    142                 return cls.from_config(config['config'])

f:\python35\lib\site-packages\keras\engine\topology.py in from_config(cls, config, custom_objects)
   2498                 if layer in unprocessed_nodes:
   2499                     for node_data in unprocessed_nodes.pop(layer):
-> 2500                         process_node(layer, node_data)
   2501 
   2502         name = config.get('name')

f:\python35\lib\site-packages\keras\engine\topology.py in process_node(layer, node_data)
   2457                     layer(input_tensors[0], **kwargs)
   2458                 else:
-> 2459                     layer(input_tensors, **kwargs)
   2460 
   2461         def process_layer(layer_data):

f:\python35\lib\site-packages\keras\engine\topology.py in __call__(self, inputs, **kwargs)
    601 
    602             # Actually call the layer, collecting output(s), mask(s), and shape(s).
--> 603             output = self.call(inputs, **kwargs)
    604             output_mask = self.compute_mask(inputs, previous_mask)
    605 

f:\python35\lib\site-packages\keras\layers\core.py in call(self, inputs, mask)
    649         if has_arg(self.function, 'mask'):
    650             arguments['mask'] = mask
--> 651         return self.function(inputs, **arguments)
    652 
    653     def compute_mask(self, inputs, mask=None):

f:\python35\lib\site-packages\keras\layers\core.py in <lambda>(inputs, scale)
     88 
     89     # References
---> 90         - [Dropout: A Simple Way to Prevent Neural Networks from Overfitting](http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf)
     91     """
     92     @interfaces.legacy_dropout_support

IndexError: tuple index out of range
nyoki-mtl commented 6 years ago

@blackredscarf

I got the same error in the following environment.

But it worked well in the following environment.

I do not know why it does not work with python 3.5. Please upgrade to python 3.6 and try it out.

blackredscarf commented 6 years ago

@nyoki-mtl Thanks! That is worked. But use load_model, I cannot change the input shape ?

nyoki-mtl commented 6 years ago

@blackredscarf Yes. This model is trained by 160*160*3 images, so if you want to change the input shape of the model, you should re-train the model by images with the shape. However, you can use facenet for images with any shape because you can change the shape of the images by resize function.