You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行TensorFlow程序报错:RewriterConfig无ON属性求助

Fixing AttributeError: 'RewriterConfig' has no attribute 'ON' in TensorFlow Object Detection Exporter

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, ON was 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:15:52