models icon indicating copy to clipboard operation
models copied to clipboard

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

Open RonakDedhiya opened this issue 8 years ago • 11 comments

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

RonakDedhiya avatar Feb 23 '18 15:02 RonakDedhiya

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.

vonchenplus avatar Feb 24 '18 07:02 vonchenplus

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

angerson avatar Feb 26 '18 19:02 angerson

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)

Yuvarajganesh112 avatar Mar 07 '18 20:03 Yuvarajganesh112

can you solve it, I have met the same error

Ifeng96 avatar Mar 11 '18 14:03 Ifeng96

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.

dketterer avatar Mar 14 '18 14:03 dketterer

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

dketterer avatar Mar 14 '18 14:03 dketterer

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.

iluxave avatar Mar 19 '18 03:03 iluxave

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

frostell avatar Mar 22 '18 09:03 frostell

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

CHAMOD avatar Mar 22 '18 20:03 CHAMOD

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.

B-Nishant avatar Mar 29 '18 14:03 B-Nishant

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

ymodak avatar Nov 30 '18 21:11 ymodak