Tensorflow Attempting to use uninitialized value AUC/AUC/auc/false_positives
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
This TensorFlow error usually appears in TensorFlow 1.x style code when metric state variables were created but never initialized before use. AUC metrics are especially prone to this because they maintain internal counters such as true positives and false positives, and those counters live in local variables rather than ordinary model weights.
Why the error happens
In TF1, many streaming metrics are not pure tensor expressions. They create variables that accumulate state across batches.
AUC is a good example. Under the hood, TensorFlow creates variables for counts used to approximate the ROC curve. If you run the update op or read the metric value before initializing those variables, you get an error such as:
Attempting to use uninitialized value AUC/AUC/auc/false_positives
That error is not about your labels or predictions directly. It is about missing variable initialization.
Global variables versus local variables
A frequent source of confusion is that tf.metrics often stores metric state in local variables, while model weights usually live in global variables.
So this is often not enough by itself:
You also need local variable initialization when using TF1 metric ops.
Typical TF1 fix
Here is the common TF1 pattern.
The critical line is local_variables_initializer(). Without it, the internal AUC counters may still be uninitialized.
Why there are two metric tensors
Another detail that trips people up is that TF1 metrics often return two values:
- the metric tensor to read
- the update op that updates internal state
If you only read auc_value without running auc_update, you may see stale or zero-like results. If you run auc_update before initialization, you see the uninitialized-value error.
That is why a correct TF1 metric loop usually initializes variables, runs the update op over batches, and then reads the value.
Reinitializing metrics between evaluations
If you evaluate on training and validation data in the same graph, metric state can leak from one pass into the next unless you reset the local variables.
That pattern lets you clear only the metric state instead of reinitializing everything.
TensorFlow 2.x perspective
In TF2 with Keras metrics, this problem is much less common because metric objects manage state more explicitly.
You still have state, but you no longer manage graph-local variable initialization manually in the same way as TF1.
Common Pitfalls
A common mistake is calling only global_variables_initializer() and assuming all TensorFlow variables are ready. For TF1 metrics, local variables matter too.
Another issue is reading the metric tensor without running the update op. That produces confusing values even after initialization is fixed.
It is also easy to forget to reset metric state between data splits, causing training and validation AUC values to contaminate each other.
Summary
- TF1 AUC metrics create internal state variables such as false positives and true positives.
- Those variables are often local variables, not global model variables.
- Fix the error by initializing both global and local variables before running metric update ops.
- Remember that TF1 metrics usually return a value tensor and a separate update op.
- In TF2,
tf.keras.metrics.AUCavoids most of this graph-initialization friction.

