2017-05-17 12 views
1

私はシェルコマンドを使用して、鉄道模型:テンソルフローで実装されたフェースネットで自分の訓練モデルを使用する方法は?

python src/facenet_train.py \ 
      --batch_size 15 \ 
      --gpu_memory_fraction 0.25 \ 
      --models_base_dir trained_model_2017_05_15_10_24 \ 
      --pretrained_model trained_model_2017_05_15_10_24/20170515-121856/model-20170515-121856.ckpt-182784 \ 
      --model_def models.nn2 \ 
      --logs_base_dir logs \ 
      --data_dir /data/user_set/training/2017_05_15_10_24 \ 
      --lfw_pairs /data/user_set/lfw_pairs.txt \ 
      --image_size 224 \ 
      --lfw_dir /data/user_set/lfw \ 
      --optimizer ADAM \ 
      --max_nrof_epochs 1000 \ 
      --learning_rate 0.00001 

を私自身の訓練を受けたモデルを使用したとき、私は、このようなエラーのINFOMATIONを取得:

2017-05-17 14:23:05.448285: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 2017-05-17 14:23:05.448318: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-05-17 14:23:05.448324: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-05-17 14:23:05.448329: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-05-17 14:23:05.448334: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-05-17 14:23:05.674872: I tensorflow/core/common_runtime/gpu/gpu_device.cc:887] Found device 0 with properties: name: Quadro M4000 major: 5 minor: 2 memoryClockRate (GHz) 0.7725 pciBusID 0000:03:00.0 Total memory: 7.93GiB Free memory: 2.89GiB 2017-05-17 14:23:05.674917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:908] DMA: 0 2017-05-17 14:23:05.674935: I tensorflow/core/common_runtime/gpu/gpu_device.cc:918] 0: Y 2017-05-17 14:23:05.674957: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Quadro M4000, pci bus id: 0000:03:00.0) Traceback (most recent call last): File "forward.py", line 21, in images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0") File "/home/chen/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2563, in get_tensor_by_name return self.as_graph_element(name, allow_tensor=True, allow_operation=False) File "/home/chen/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2414, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "/home/chen/.pyenv/versions/anaconda3-4.2.0/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2456, in _as_graph_element_locked "graph." % (repr(name), repr(op_name))) KeyError: "The name 'input:0' refers to a Tensor which does not exist. The operation, 'input', does not exist in the graph."

は、機能コードを取得する:

import tensorflow as tf 
import facenet 
w_MODEL_PATH_='/home/chen/demo_dir/facenet_tensorflow_train/trained_model_2017_05_15_10_24/20170515-121856' 

with tf.Graph().as_default(): 
    with tf.Session() as sess: 
     # load the model 
     meta_file, ckpt_file = facenet.get_model_filenames(w_MODEL_PATH_) 
     facenet.load_model(w_MODEL_PATH_, meta_file, ckpt_file) 
     # print("model_path:", w_MODEL_PATH_,"meta_file:", meta_file,"ckpt_file:", ckpt_file) 

     # Get input and output tensors 
     # ops = tf.get_default_graph().get_operations() 
     # 
     # print(ops) 

     images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0") 
     embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0") 
     phase_train_placeholder = tf.get_default_graph().get_tensor_by_name("phase_train:0") 

     image_size = images_placeholder.get_shape()[1] 
     embedding_size = embeddings.get_shape()[1] 

     # print(image_size) 

     paths = ['one.png', 'two.png'] 

     # Run forward pass to calculate embeddings 
     images = facenet.load_data(paths, do_random_crop=False, do_random_flip=False, image_size=image_size, 
            do_prewhiten=True) 
     # print("images:", idx, images) 
     feed_dict = {images_placeholder: images, phase_train_placeholder: False} 
     # print(idx,"embeddings:", embeddings) 
     emb_array = sess.run(embeddings, feed_dict=feed_dict) 
     # print(idx, "emb_array:", emb_array) 
     print(emb_array) 

私は自分の訓練されたモデルの使い方を知らないので、助けてください。

答えて

0

最後の部分については、このコードを使用してモデルの操作を確認してください。

for i in tf.get_default_graph().get_operations(): 
    print(i.name) 

あなたが最適化について話している場合は、

あなた自身のマシンでテンソルフローをコンパイルする必要があるため、このエラーが発生しています。それは非常に簡単です。

オプションの完全なリストについては、ドキュメントを読むことができますが、基本的にいくつかの手順を実行する必要があります。

https://www.tensorflow.org/install/install_sources

  1. gitのクローン
  2. レポ
  3. bazel tensorflowビルドシステムをインストールtensorflow
  4. のconfigure tensorflow
  5. ビルドそれはアナコンダがある場合
  6. は、お使いの環境でtensorflowをインストールtensorflowかPythonを使用している場合はvirtualenv

もちろん、他の必要なライブラリをインストールする必要があります。 Ubuntuで行うのはかなり簡単です。

また、あなたがanacondaを使用している場合は、tensorflow-gpuのconda forgeバージョンを試すこともできますが、CPUの最適化でコンパイルされていることを確認することはできません。

https://conda-forge.org/

  1. アナコンダインストール
  2. はconda鍛造レポのURLを追加し
  3. 更新conda
  4. インストールtensorflow-GPU
関連する問題