Tensorflow Attempted to use uninitialized value AUC / AUC / auc / false_positives

I train CNN using image classification. Due to the limited size of my dataset, I use training transfer. Basically, I use the pre-trained Google network, proving it with a re-qualified example ( https://www.tensorflow.org/tutorials/image_retraining ).

The model works great and gives very good accuracy. But my dataset has a high imbalance, which means that accuracy is not the best indicator for evaluating model performance.

Studying various solutions, some suggested changing the sampling method or performance metric. I decided to go with him later.

Tensorflow provides good reliability indicators, including AUC, accuracy, recall, etc.

Now, here is the retouching model code: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py

I add the following function add_evaluation_step(result_tensor, ground_truth_tensor):

  with tf.name_scope('AUC'):
    with tf.name_scope('prediction'):
        prediction = tf.argmax(result_tensor, 1)
    with tf.name_scope('AUC'):
        auc_value = tf.metrics.auc(tf.argmax(ground_truth_tensor, 1), prediction, curve='ROC')


  tf.summary.scalar('accuracy', evaluation_step)
  tf.summary.scalar('AUC', auc_value)

But I get this error:

Traceback ( ): "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py" , 1135,     tf.app.run(main = main, argv = [sys.argv [0]] + unparsed) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow///app.py", 44,     _sys.exit(main (_sys.argv [: 1] + flags_passthrough)) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain. ", 911,     ground_truth_input: train_ground_truth}) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/client/session.py", 767,     run_metadata_ptr) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/client/session.py", 965, _run     feed_dict_string, options, run_metadata) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/client/session.py", 1015, _do_run     target_list, options, run_metadata) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/client/session.py", 1035, _do_call     raise type (e) (node_def, op, message) tensorflow.python.framework.errors_impl.FailedPreconditionError: AUC/AUC/auc/false_positives
[[Node: AUC/AUC/auc/false_positives/read = IdentityT = DT_FLOAT, _class= [ "loc: @AUC/AUC/auc/false_positives" ], _device = "/job: localhost/replica: 0/task: 0/cpu: 0" ]]

op u'AUC/AUC/auc/false_positives/read ', : "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py" , 1135,     tf.app.run(main = main, argv = [sys.argv [0]] + unparsed) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow///app.py", 44,     _sys.exit(main (_sys.argv [: 1] + flags_passthrough)) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain. ", 874,     final_tensor, ground_truth_input) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py" , 806, add_evaluation_step     auc_value, update_op = tf.metrics.auc(tf.argmax(ground_truth_tensor, 1), , curve = 'ROC') "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/metrics_impl.py" , 555, auc     , , , ) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/metrics_impl.py" , 473, _confusion_matrix_at_thresholds     false_p = _create_local ('false_positives', shape = [num_thresholds]) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/metrics_impl.py" , 177, _create_local     validate_shape = validate_shape) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/variables.py", 226, init    expected_shape = expected_shape) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/variables.py", 344, _init_from_args     self._snapshot = array_ops.identity(self._variable, name= "read" ) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/gen_array_ops.py", 1490,     result = _op_def_lib.apply_op ( "Identity", input = input, name = name) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/op_def_library.py", 768, apply_op     op_def = op_def) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/ops.py", 2402, create_op     original_op = self._default_original_op, op_def = op_def) "/home/user_2/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/ops.py", 1264, init    self._traceback = _extract_stack()

FailedPreconditionError (. ): AUC/AUC/auc/false_positives [[ Node: AUC/AUC/auc/false_positives/read = IdentityT = DT_FLOAT, _class= [ "loc: @AUC/AUC/auc/false_positives" ], _device = "/job: localhost/replica: 0/task: 0/cpu: 0" ]]

, , :

init = tf.global_variables_initializer()
sess.run(init)
+4
1

:

init = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init)
+7

Source: https://habr.com/ru/post/1678737/


All Articles