# cv2.error: OpenCV(4.8.0) /modules/dnn/src/tensorflow/tf_io.cpp:89: error: (-2:Unspecified error) FAILED to read .pb file: Invalid GraphDef

- **ID:** `opencv/dnn-readnet-from-tensorflow-failed`
- **Domain:** opencv
- **Category:** module_error
- **Error Code:** `-2`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The TensorFlow .pb model file is corrupted, incompatible with OpenCV's protobuf version, or exported with a different opset.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |
| 4.10.0 | active | — | — |

## Workarounds

1. **# In TensorFlow:
import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
# Freeze and save as frozen graph
model = tf.saved_model.load('model_dir')
frozen_func = convert_variables_to_constants_v2(model.signatures['serving_default'])
tf.io.write_graph(frozen_func.graph, '.', 'frozen_model.pb', as_text=False)** (80% success)
   ```
   # In TensorFlow:
import tensorflow as tf
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
# Freeze and save as frozen graph
model = tf.saved_model.load('model_dir')
frozen_func = convert_variables_to_constants_v2(model.signatures['serving_default'])
tf.io.write_graph(frozen_func.graph, '.', 'frozen_model.pb', as_text=False)
   ```
2. **net = cv2.dnn.readNetFromTensorflow('model.pb', 'model.pbtxt')  # Provide text protobuf for graph structure** (75% success)
   ```
   net = cv2.dnn.readNetFromTensorflow('model.pb', 'model.pbtxt')  # Provide text protobuf for graph structure
   ```

## Dead Ends

- **** — If the model was exported with an incompatible TensorFlow version, re-downloading won't change the GraphDef format. (50% fail)
- **** — ONNX conversion may fail if the original GraphDef is malformed or contains unsupported operations. (70% fail)
- **** — OpenCV's bundled protobuf may still be incompatible with newer TensorFlow exports; the error persists. (60% fail)
