Models: TypeError: Expected int32, got range(0, 3) of type 'range' instead.

Created on 23 Feb 2018  Â·  11Comments  Â·  Source: tensorflow/models

System information

  • What is the top-level directory of the model you are using: object_detection
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 1.5
  • Bazel version (if compiling from source): No
  • CUDA/cuDNN version: No
  • GPU model and memory: No
  • Exact command to reproduce: python3 train.py --logtostderr --train_dir=./models/train --pipeline_config_path=faster_rcnn_resnet101_coco.config

When running the object detection model with pre-trained faster_rcnn_resnet101_coco. I ran into this error.

Traceback (most recent call last):
  File "train.py", line 167, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 124, in run
    _sys.exit(main(argv))
  File "train.py", line 163, in main
    worker_job_name, is_chief, FLAGS.train_dir)
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/trainer.py", line 255, in train
    train_config.optimizer)
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/builders/optimizer_builder.py", line 50, in build
    learning_rate = _create_learning_rate(config.learning_rate)
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/builders/optimizer_builder.py", line 108, in _create_learning_rate
    learning_rate_sequence)
  File "/usr/local/lib/python3.5/dist-packages/object_detection-0.1-py3.5.egg/object_detection/utils/learning_schedules.py", line 153, in manual_stepping
    tf.constant(range(num_boundaries), dtype=tf.int32),
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_util.py", line 413, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/tensor_util.py", line 328, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got range(0, 3) of type 'range' instead.

When figuring out error, it is failing at manual_stepping.
In rcnn_resnet101_coco.config, we are using manual stepping whereas if used with exponential_stepping no error pops and work properly.

while tracing error, there are recent commit in learning_schedules.py
It is giving error at
tf.constant(range(num_boundaries),dtype=tf.int32)) line 153
This fails since tf.constant is not compatible with range as input

Most helpful comment

you can modify
line 153 : tf.constant(range(num_boundaries), dtype=tf.int32),
to tf.constant(list(range(num_boundaries)), dtype=tf.int32),

That is a python issue since range is not a list.

All 11 comments

you can modify
line 153 : tf.constant(range(num_boundaries), dtype=tf.int32),
to tf.constant(list(range(num_boundaries)), dtype=tf.int32),

That is a python issue since range is not a list.

@tombstone Looks like a small Python 3 incompatibility, can you take a look?

I tried making that tf.constant(list(range(num_boundaries)), dtype=tf.int32), but I get
Type error: list() takes at most 1 argument (2 given)

can you solve it, I have met the same error

Problem seems to be, that they tried to enforce int32 for the TPU architecture.

# Casting global step to tf.int32 is dangerous, but necessary to be
# compatible with TPU.

@Yuvarajganesh112 did you write tf.constant(list(range(num_boundaries), dtype=tf.int32)), instead of tf.constant(list(range(num_boundaries)), dtype=tf.int32),

you can modify
line 153 : tf.constant(range(num_boundaries), dtype=tf.int32),
to tf.constant(list(range(num_boundaries)), dtype=tf.int32),

That worked for me.

Thank you @vonchenplus, your mod of line 153 in learning_schedules.py worked for me too.

@frostell Thanks. In linux environment It was worked for me too.

you can modify
line 153 : tf.constant(range(num_boundaries), dtype=tf.int32),
to tf.constant(list(range(num_boundaries)), dtype=tf.int32),

I made this changes still it gives me same error :
TypeError: Expected int32, got range(0, 3) of type 'range' instead.
please help me.

Closing this issue since a fix has been committed. Feel free to reopen the issue if it still persists. Thanks!

Was this page helpful?
0 / 5 - 0 ratings