本文介绍了多任务网络中的ValueError:形状必须为0,但为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to implement a Tensorflow version of a mulit-task network, based on this caffe implementation.

网络可视化为,但出现错误:

The networks is visualized as this tensorflow graph, but I get an Error:

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].

我不知道如何解决此问题。

I have no idea how to solve this issue.

推荐答案

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

You declared the learning rate as a 1D Tesnor while it should be a scalar: learning_rate = tf.placeholder(tf.float64, shape=[], name="lr").

这篇关于多任务网络中的ValueError:形状必须为0,但为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:46