运行TensorFlow程序报错:RewriterConfig无ON属性求助
Hey there, let's get this sorted out! That error pops up because of a TensorFlow version compatibility issue—the RewriterConfig.ON constant was renamed or replaced in newer (or some older) TensorFlow releases. Here's how to fix it step by step:
Why this happens
The RewriterConfig enum values changed across TensorFlow versions. For example:
- In older TensorFlow 1.x versions,
ONwas a valid attribute - In TensorFlow 2.x and newer 1.x releases, this was replaced with
ENABLED
Step-by-Step Fixes
1. Check your TensorFlow version
First, confirm which TF version you're running. Run this in your terminal or Python shell:
pip show tensorflow # Or in Python: import tensorflow as tf print(tf.__version__)
2. Modify the problematic line in exporter.py
Go to line 72 in /Users/Rahul/desktop/models/research/object_detection/exporter.py and replace ON with the correct constant for your TF version:
For TensorFlow 2.x or newer TF 1.x (1.14+):
Change this line:
layout_optimizer = rewriter_config_pb2.RewriterConfig.ON)
To:
layout_optimizer = rewriter_config_pb2.RewriterConfig.ENABLED)
If the above doesn't work (rare cases):
You can also directly use the integer value corresponding to the enum (since ENABLED/ON maps to 1):
layout_optimizer = 1
3. Verify the fix
Run your exporter script again. If you still see issues, double-check that your models/research repo version matches your TensorFlow version—sometimes the Object Detection API code is tied to specific TF releases.
Bonus: Check available attributes (if you're unsure)
If you want to confirm what attributes are available in your RewriterConfig, add this line temporarily before the error line and run the script:
print(dir(rewriter_config_pb2.RewriterConfig))
This will print all valid attributes for the enum, so you can pick the correct one.
内容的提问来源于stack exchange,提问作者Raul Desor

