2017-03-15 17 views
0

私はオープンアクセスギブスコードの1つを使用して画像分類用の畳み込みニューラルネットワークを作成しようとしています。私は2種類の画像を持っています。私は、コードの一部の実行を開始する場合でも、私はこのエラーの起源はどこか、おそらくですが、私の直感は、と言われます(エラーが発生したコードの一部にこのエラーTensorflow Deprecation警告

/Users/user/anaconda/envs/tensorflow/lib/python3.5/site-packages/ipykernel/__main__.py:46: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future. 

これをされて得続けますそれは画像のラベルにありますが、私はそれを修正する方法がわかりません、私は複数回ラベルを貼り付けてみましたが、何もこれを修正するために働いていませんでした)。

def print_test_accuracy(show_example_errors=False, 
        show_confusion_matrix=False): 

    # Number of images in the test-set. 
    num_test = len(test_images) 

    # Allocate an array for the predicted classes which 
    # will be calculated in batches and filled into this array. 
    cls_pred = np.zeros(shape=num_test, dtype=np.int) 

    # Now calculate the predicted classes for the batches. 
    # We will just iterate through all the batches. 
    # There might be a more clever and Pythonic way of doing this. 

    # The starting index for the next batch is denoted i. 
    i = 0 

    while i < num_test: 
     # The ending index for the next batch is denoted j. 
     j = min(i + test_batch_size, num_test) 

     # Get the images from the test-set between index i and j. 
     images = test_images[i:j, :] 

     # Get the associated labels. 
     labels = test_labels[i:j, :] 

     # Create a feed-dict with these images and labels. 
     feed_dict = {x: images, 
       y_true: labels} 

     # Calculate the predicted class using TensorFlow. 
     cls_pred[i:j] = session.run(y_pred_cls, feed_dict=feed_dict) 

     # Set the start-index for the next batch to the 
     # end-index of the current batch. 
     i = j 

    # Convenience variable for the true class-numbers of the test-set. 
    cls_true = test_class_labels 

    # Create a boolean array whether each image is correctly classified. 
    correct = (cls_true == cls_pred) 

    # Calculate the number of correctly classified images. 
    # When summing a boolean array, False means 0 and True means 1. 
    correct_sum = sum(correct) 

    # Classification accuracy is the number of correctly classified 
    # images divided by the total number of images in the test-set. 
    acc = float(correct_sum)/num_test 

    # Print the accuracy. 
    msg = "Accuracy on Test-Set: {0:.1%} ({1}/{2})" 
    print(msg.format(acc, correct_sum, num_test)) 

    # Plot some examples of mis-classifications, if desired. 
    if show_example_errors: 
     print("Example errors:") 
     plot_example_errors(cls_pred=cls_pred, correct=correct) 

    # Plot the confusion matrix, if desired. 
    if show_confusion_matrix: 
     print("Confusion Matrix:") 
     plot_confusion_matrix(cls_pred=cls_pred) 
+0

、この警告の唯一の可能性の高いソースを'correct =(cls_true == cls_pred)'です。両方の配列が同じサイズを持っているかどうか確認してください –

+0

私の記事https://martin-thoma.com/image-classification/に興味があるかもしれません。 –

答えて

0

tf.equalをお試しください:

correct = tf.equal(cls_pred, cls_true) 

か、それは確率分布ではなく、すでに単なるARGMAXの場合:上記のコードから

correct = tf.equal(tf.argmax(cls_pred, 1), tf.argmax(cls_true, 1))