TF目标检测API-Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].

使用tensorflow-1.5++多版本尝试过,与tensorflow-1.4API不兼容(问题)

此错误搞了大半天,翻看了很多很多文章,头痛。。

ValueError: Tried to convert 't' to a tensor and failed. Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].


执行检测任务:

raini@biyuzhe:~/pro/tf_models/models/research$ CUDA_VISIBLE_DEVICES="" python object_detection/train.py \
>         --logtostderr \
>         --pipeline_config_path=/home/raini/pro/tf_models/byz/pet_test/pipeline.config \
>         --train_dir=/media/raini/deepin/byz/dataset/pet-record

得到错误:

#(condition, x, y)是我打印出来观察的,最后一个结果即报错的地方

/home/raini/app/anoconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
WARNING:tensorflow:From /home/raini/pro/tf_models/models/research/object_detection/trainer.py:260: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
WARNING:tensorflow:num_readers has been reduced to 1 to match input file shards.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:depth of additional conv before box predictor: 0



========condition
Tensor("Compare/IOU/Equal:0", shape=(?, ?), dtype=bool, device=/device:GPU:0)
========x
Tensor("Compare/IOU/zeros_like:0", shape=(?, ?), dtype=float32, device=/device:GPU:0)
========y
Tensor("Compare/IOU/truediv:0", shape=(?, ?), dtype=float32, device=/device:GPU:0)



========condition
Tensor("GreaterEqual:0", shape=(?,), dtype=bool, device=/device:GPU:0)
========x
Tensor("Encode/transpose:0", shape=(?, 4), dtype=float32, device=/device:GPU:0)
========y
Tensor("Tile_3:0", shape=(?, 4), dtype=float32, device=/device:GPU:0)
INFO:tensorflow:Scale of 0 disables regularizer.
WARNING:tensorflow:From /home/raini/pro/tf_models/models/research/object_detection/core/box_predictor.py:407: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
INFO:tensorflow:Scale of 0 disables regularizer.



========condition
Tensor("Loss/RPNLoss/Compare/IOU/Equal:0", shape=(?, ?), dtype=bool, device=/device:GPU:0)
========x
Tensor("Loss/RPNLoss/Compare/IOU/zeros_like:0", shape=(?, ?), dtype=float32, device=/device:GPU:0)
========y
Tensor("Loss/RPNLoss/Compare/IOU/truediv:0", shape=(?, ?), dtype=float32, device=/device:GPU:0)



========condition
Tensor("Loss/RPNLoss/Match/cond/Cast_2:0", shape=(?,), dtype=bool, device=/device:GPU:0)
========x
Tensor("Loss/RPNLoss/Match/cond/ArgMax_2:0", shape=(?,), dtype=int32, device=/device:GPU:0)
========y
Tensor("Loss/RPNLoss/Match/cond/Add_1:0", shape=(?,), dtype=int32, device=/device:GPU:0)



========condition
Tensor("Loss/RPNLoss/GreaterEqual:0", shape=(?,), dtype=bool, device=/device:GPU:0)
========x
Tensor("Loss/RPNLoss/Encode/transpose:0", shape=(?, 4), dtype=float32, device=/device:GPU:0)
========y
Tensor("Loss/RPNLoss/Tile:0", shape=(?, 4), dtype=float32, device=/device:GPU:0)
WARNING:tensorflow:From /home/raini/pro/tf_models/models/research/object_detection/core/losses.py:317: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.
Instructions for updating:


Future major versions of TensorFlow will allow gradients to flow
into the labels input on backprop by default.


See tf.nn.softmax_cross_entropy_with_logits_v2.


========condition
Tensor("Loss/BoxClassifierLoss/Compare/IOU/Equal:0", shape=(?, 64), dtype=bool, device=/device:GPU:0)
========x
Tensor("Loss/BoxClassifierLoss/Compare/IOU/zeros_like:0", shape=(?, 64), dtype=float32, device=/device:GPU:0)
========y
Tensor("Loss/BoxClassifierLoss/Compare/IOU/truediv:0", shape=(?, 64), dtype=float32, device=/device:GPU:0)



========condition
Tensor("Loss/BoxClassifierLoss/GreaterEqual:0", shape=(64,), dtype=bool, device=/device:GPU:0)
========x
Tensor("Loss/BoxClassifierLoss/Encode/transpose:0", shape=(64, 4), dtype=float32, device=/device:GPU:0)
========y
Tensor("Loss/BoxClassifierLoss/Tile_3:0", shape=(64, 4), dtype=float32, device=/device:GPU:0)



========condition
Tensor("GreaterEqual_1:0", shape=(3,), dtype=bool, device=/device:CPU:0)
========x
range(0, 3)
========y

[0, 0, 0]



Traceback (most recent call last):
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 233, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 422, in make_tensor_proto
    _GetDenseDimensions(values)))
ValueError: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 524, in _apply_op_helper
    values, as_ref=input_arg.is_ref).dtype.name
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 233, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 212, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 422, in make_tensor_proto
    _GetDenseDimensions(values)))
ValueError: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "object_detection/train.py", line 184, in <module>
    tf.app.run()
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 124, in run
    _sys.exit(main(argv))
  File "object_detection/train.py", line 180, in main
    graph_hook_fn=graph_rewriter_fn)
  File "/home/raini/pro/tf_models/models/research/object_detection/trainer.py", line 298, in train
    train_config.optimizer)
  File "/home/raini/pro/tf_models/models/research/object_detection/builders/optimizer_builder.py", line 50, in build
    learning_rate = _create_learning_rate(config.learning_rate)
  File "/home/raini/pro/tf_models/models/research/object_detection/builders/optimizer_builder.py", line 109, in _create_learning_rate
    learning_rate_sequence, config.warmup)
  File "/home/raini/pro/tf_models/models/research/object_detection/utils/learning_schedules.py", line 169, in manual_stepping
    [0] * num_boundaries))
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 2540, in where
    return gen_math_ops._select(condition=condition, x=x, y=y, name=name)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4049, in _select
    "Select", condition=condition, t=x, e=y, name=name)
  File "/home/raini/app/anoconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 528, in _apply_op_helper
    (input_name, err))
ValueError: Tried to convert 't' to a tensor and failed. Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted [].

解决:

出错原因:知乎的大佬说是python3的兼容问题

扫描二维码关注公众号,回复: 1986246 查看本文章

解决办法:research/object_detection/utils/learning_schedules.py文件的 第167-169行由

# # 修改167-169
rate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),
                                    range(num_boundaries),
                                    [0] * num_boundaries))
# # 成
rate_index = tf.reduce_max(tf.where(tf.greater_equal(global_step, boundaries),
                                    list(range(num_boundaries)),
                                    [0] * num_boundaries))




猜你喜欢

转载自blog.csdn.net/lovebyz/article/details/80668881
今日推荐