davidsandberg / facenet

Face recognition using Tensorflow
MIT License
13.83k stars 4.81k forks source link

KeyError occurs when importing the meta file #58

Closed NoobFang closed 8 years ago

NoobFang commented 8 years ago

Hi,

After I download the pre-trained model "20161030-023650", I want to restore the model by load_model() in "facenet.py". Unfortunately, a KeyError occurs:

In [15]: facenet.load_model('20161030-023650/', meta_file, ckpt_file)

KeyError Traceback (most recent call last)

in () ----> 1 facenet.load_model('20161030-023650/', meta_file, ckpt_file) facenet.py in load_model(model_dir, meta_file, ckpt_file) 468 def load_model(model_dir, meta_file, ckpt_file): 469 model_dir_exp = os.path.expanduser(model_dir) --> 470 saver = tf.train.import_meta_graph(os.path.join(model_dir_exp, meta_file)) 471 saver.restore(tf.get_default_session(), os.path.join(model_dir_exp,ckpt_file)) 472 /usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.pyc in import_meta_graph(meta_graph_or_file) 1456 return _import_meta_graph_def(meta_graph_or_file) 1457 else: -> 1458 return _import_meta_graph_def(read_meta_graph_file(meta_graph_or_file)) 1459 1460 /usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.pyc in _import_meta_graph_def(meta_graph_def) 1346 producer_op_list = meta_graph_def.meta_info_def.stripped_op_list 1347 importer.import_graph_def(meta_graph_def.graph_def, name="", -> 1348 producer_op_list=producer_op_list) 1349 1350 # Restores all the other collections. /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.pyc in import_graph_def(graph_def, input_map, return_elements, name, op_dict, producer_op_list) 250 for node in graph_def.node: 251 # Set any default attr values that aren't present. --> 252 op_def = op_dict[node.op] 253 for attr_def in op_def.attr: 254 key = attr_def.name KeyError: u'RsqrtGrad' ---------------------------------------- I use Tensorflow 0.10 in Ubuntu, with CUDA 7.5 and CUDNN 4. How can I solve this problem?
davidsandberg commented 8 years ago

I have exported the model as a graphdef protobuf that can be evaluated with a new module validate_on_lfw_new.py. It should just be to download the model and point to it when running evaluation, something like python validate_on_lfw_new.py ~/datasets/lfw/lfw_mtcnnpy_160 ~/models/export/20161030-023650.pb

NoobFang commented 8 years ago

That seems work for evaluation.

However, if the weights in .pb file are from a freezed graph, can I just import_graph_def it and re-train the model?

davidsandberg commented 8 years ago

If you want to retrain the model another alternative is to create the model programatically, i.e. by calling inference(...) for the model, like it's done in facenet_train_classifier.py. And then you can load the file containing the parameters, i.e. model-20161030-023650.ckpt-80000 using saver.restore(...) in the same way as it's done in load_model(...).

NoobFang commented 8 years ago

OK, I get it now. Thanks for your explanation!

xl94 commented 8 years ago

Which tensorflow version is the model trained for the create the graph file then?