多任务网络中的ValueError:Shape必须为0级,但是为1级

时间:2017-05-17 08:30:31

标签: tensorflow deep-learning

我想基于this caffe实现实现多任务网络的Tensorflow版本。

网络可视化为tensorflow graph,但我收到错误:

Traceback (most recent call last):
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 671, in _call_cpp_shape_fn_impl
    input_tensors_as_shapes, status)
  File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__
    next(self.gen)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 0 but is rank 1 for 'GradientDescent/update_heatmap/spatial_net/conv1/weights/ApplyGradientDescent' (op: 'ApplyGradientDescent') with input shapes: [5,5,3,128], [1], [5,5,3,128].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bill/Development/scan_to_image/scan_to_image/train_by_heatmap_with_tfrecords.py", line 322, in <module>
    train_from_tfrecords(dataset_folder)
  File "/home/bill/Development/scan_to_image/scan_to_image/train_by_heatmap_with_tfrecords.py", line 190, in train_from_tfrecords
    training_operation = slim.learning.create_train_op(total_loss, optimizer)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/contrib/slim/python/slim/learning.py", line 436, in create_train_op
    colocate_gradients_with_ops=colocate_gradients_with_ops)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/contrib/training/python/training/training.py", line 448, in create_train_op
    grad_updates = optimizer.apply_gradients(grads, global_step=global_step)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 456, in apply_gradients
    update_ops.append(processor.update_op(self, grad))
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/training/optimizer.py", line 97, in update_op
    return optimizer._apply_dense(g, self._v)  # pylint: disable=protected-access
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/training/gradient_descent.py", line 50, in _apply_dense
    use_locking=self._use_locking).op
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/training/gen_training_ops.py", line 306, in apply_gradient_descent
    name=name)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
    op_def=op_def)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2338, in create_op
    set_shapes_for_outputs(ret)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1719, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1669, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn
    debug_python_shape_fn, require_shape_fn)
  File "/home/bill/pyvenv/py35/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Shape must be rank 0 but is rank 1 for 'GradientDescent/update_heatmap/spatial_net/conv1/weights/ApplyGradientDescent' (op: 'ApplyGradientDescent') with input shapes: [5,5,3,128], [1], [5,5,3,128].

我不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

您将学习率声明为1D Tesnor,而它应该是标量:learning_rate = tf.placeholder(tf.float64, shape=[], name="lr")