2017-09-22 8 views
0

私はtf slim(v1.3)を使用して、開始v4の最終層を訓練しました。処理を既存のツールに統合しようとしていますが、予測。 argmaxだけでなく、すべての予測値が必要です。私はチェックポイントのパスといくつかのnumpyの配列(100x100x3は私が訓練したものですが、299x299x3に拡張されています)を持っています。誰かが私を正しい方向に向けることができますか?私は評価のために複数の画像を供給していますが、必ずしもバッチではありません(おそらく、1つ以上の画像を取り、結果を返すマイクロサービスを実行しますが、初期化時にチェックポイントを一度読み込むだけです)。ここでTFスリムと開始予測の確率

答えて

0

はこれを行う方法の例です:

with tf.Graph().as_default(): 
     tf_global_step = slim.get_or_create_global_step() 
     network_fn = nets_factory.get_network_fn("inception_v4", 
      num_classes=5, 
      is_training=False) 

     ############################################################## 
     # Create a dataset provider that loads data from the dataset # 
     ############################################################## 
     provider = slim.dataset_data_provider.DatasetDataProvider(
      dataset, 
      shuffle=False, 
      common_queue_capacity=2, 
      common_queue_min=1) 
     [images] = provider.get(['image']) 

     ##################################### 
     # Select the preprocessing function # 
     ##################################### 
     image_preprocessing_fn = preprocessing_factory.get_preprocessing(
      "inception_v4", 
      is_training=False) 

     eval_image_size = network_fn.default_image_size 
     images = image_preprocessing_fn(images, eval_image_size, eval_image_size) 
     images = tf.reshape(images, [eval_image_size, eval_image_size, 3]) 
     images, _ = tf.train.batch(
       [images, 0], 
       batch_size=len(dataset.data_sources), 
       num_threads=1, 
       capacity=len(dataset.data_sources)) 
     #################### 
     # Define the model # 
     #################### 
     logits, _ = network_fn(images) 
     variables_to_restore = slim.get_variables_to_restore() 

     soft = tf.nn.softmax(logits, 1) 
     predictions = tf.argmax(logits, 1) 
     num_batches = 1 

     if tf.gfile.IsDirectory(checkpoint_path): 
      checkpoint_path = tf.train.latest_checkpoint(checkpoint_path) 

     tf.logging.info('Evaluating %s' % checkpoint_path) 
     r_logits, r_soft, r_prediction = slim.evaluation.evaluate_once(
      master='', 
      checkpoint_path=checkpoint_path, 
      logdir=eval_dir, 
      num_evals=num_batches, 
      eval_op=[], 
      final_op=[logits, soft, predictions], 
      variables_to_restore=variables_to_restore) 
関連する問題