我在Ubuntu系统下运行带有CPU版本的Tensorflow 1.9和Python 3.6的python object_detection / builders / model_builder_test.py,存在NameError:未定义名称“ xrange”,有人知道为什么会这样以及如何处理它?谢谢。这是我遵循的指南。
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 311, in test_create_ssd_resnet_v1_fpn_model_from_config
model = model_builder.build(model_proto, is_training=True)
File "/home/tensorflow/models/research/object_detection/builders/model_builder.py", line 110, in build
add_background_class)
File "/home/tensorflow/models/research/object_detection/builders/model_builder.py", line 214, in _build_ssd_model
ssd_config.anchor_generator)
File "/home/tensorflow/models/research/object_detection/builders/anchor_generator_builder.py", line 91, in build
cfg.normalize_coordinates
File "/home/tensorflow/models/research/object_detection/anchor_generators/multiscale_grid_anchor_generator.py", line 61, in __init__
for scale in xrange(scales_per_octave)]
NameError: name 'xrange' is not defined
答案 0 :(得分:0)
xrange()
已从python3
中删除,并由range()
取代。改为使用range()
(其工作原理与xrange()
完全相同)。
但是,如果需要在range()
中使用python2
函数(本例中不需要),请使用xrange()
,因为range()
返回了一个列表发电机(如@ xdurch0在评论中所述)。