tensorflow - 多任务网络中ValueError : Shape must be rank 0 but is rank 1

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

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

最佳答案

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

关于tensorflow - 多任务网络中ValueError : Shape must be rank 0 but is rank 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44019515/

相关文章:

python - 没有注册 OpKernel 来支持具有这些属性的 Op 'Conv2D'

tensorflow - 如何将 rnn 的初始状态设置为 tensorflow 中的参数?

tensorflow - Keras 序列模型到 Tensorflow EstimatorSpec 的准确性下降

machine-learning - 如果输出层(标签)由 one-hot 向量和零向量组成,应使用什么损失函数?

python - Anaconda Tensorflow 运行时问题

python - Tensorflow服务容器进入事件循环后Heroku Dyno崩溃

python - tensorflow 中的双线性上采样?

python - 当验证损失满足某些标准时提前停止

python - 如何在 PyTorch 中做完全连接的批量归一化?

python - TensorFlow CNN 损失迅速增加到 NaN