首页 > 解决方案 > 对张量进行切片是否会在 Tensorflow 中提供梯度?

问题描述

我想将 1024x1024 图像张量切片为 16 个大小为 256x256 的张量。我正在使用以下代码进行操作:

with tf.variable_scope("image_split", reuse=tf.AUTO_REUSE):
    img_array = tf.get_variable(name = 'img_array', shape = (16, 256, 256, 3),
                                dtype = tf.float32)     
with tf.control_dependencies([img_array[i].assign(img[(i%4)*256:(i%4+1)*256, 
    (i//4)*256:((i+4)//4)*256]) for i in range(16)]):
        img_array = tf.identity(img_array)

但我收到此错误:ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients

如果我不切片图像一切正常。切片张量是否提供梯度?如果是,那么正确的方法是什么?

标签: pythontensorflow

解决方案


推荐阅读