2017-04-30 3 views
1

AlexNet 모델을 기반으로 한 내 CNN 프로젝트는 here으로 구현했습니다.Tensorflow의 예측 테스트를 위해 Sklearn의 메트릭 추가

두 개의 주요 기능, trainingprediction이 있는데, 나는 훈련 세트에 비해 다른 디렉토리에있는 테스트 세트의 이미지를 읽는 예측 부분의 메트릭에 대해 묻고 싶습니다.

이것은 prediction 코드는 다음과 같습니다

def prediction(self): 
     with tf.Session() as sess: 

      # Construct model 
      pred = self.alex_net_model(self.img_pl, self.weights, self.biases, self.keep_prob) 

      # Restore model. 
      ckpt = tf.train.get_checkpoint_state("ckpt_dir") 
      if(ckpt): 
       self.saver.restore(sess, MODEL_CKPT) 
       print "Model restored" 
      else: 
       print "No model checkpoint found to restore - ERROR" 
       return 

      ### Metrics ### 
      y_p = tf.argmax(pred,1) # the value predicted 

      target_names = ['class 0', 'class 1', 'class 2'] 
      list_pred_total = [] 
      list_true_total = [] 

      # Accuracy Precision Recall F1-score by TEST IMAGES            
      for step, elems in enumerate(self.BatchIteratorTesting(BATCH_SIZE)): 

       batch_imgs_test, batch_labels_test = elems 

       y_pred = sess.run([y_p], feed_dict={self.img_pl: batch_imgs_test, self.keep_prob: 1.0}) 
       #print(len(y_pred)) 
       list_pred_total.extend(y_pred) 
       y_true = np.argmax(batch_labels_test,1) 
       #print(len(y_true)) 
       list_true_total.extend(y_true) 

      #### TODO: METRICS FOR PRECISION RECALL F1-SCORE #### 

내 질문은 다음과 같습니다

  • 내가 training에서 일을 해요로 어떻게 제대로 classification_report이 호출 할 수 있습니다? y_pred1 ELEM 및 y_true 목록 인 이유
  • 64 (배치 크기)의 NumPy와 배열?

나는 두 개의 len이 다른 경우 metrics.classification_report(list_true_total, list_pred_total, target_names=target_names) 할 수 없습니다. 내 의심을 해결하기를 바랍니다.

답변

1

y_pred = sess.run(y_p,... (y_p 주위에 []이 없음)을 호출하면 예상대로 len (batch_size) 배열이 나타납니다.

classification_report에 대한 다른 질문을 이해할 수 없습니다.

+0

'y_pred'에 대한 답변을 보내 주셔서 감사합니다. 다른 질문을 다시 정리할 수 있습니다.이 상황에서 어떻게'metrics.classification_report'를 올바르게 호출 할 수 있습니까? – Kyrol

+0

classification_report의 문서에 대해 명확하지 않은 것은 무엇입니까? –

+0

당신이 정확하게 제안한 것처럼'y_p '대신'y_p'를 호출하는 것에 대한 의문이 문제와 관련이 있습니다. 고맙습니다! – Kyrol

관련 문제