python - 对张量进行切片是否会在 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
如果我不切片图像一切正常。切片张量是否提供梯度?如果是,那么正确的方法是什么?
解决方案
推荐阅读
- ruby - 在 OSX Catalina 上安装用于 gem 安装的 Ruby 开发工具
- python - “NoneType”类型的对象没有正则表达式的 len()
- reactjs - React 编译失败。找不到模块:无法解析“Main.css”
- javascript - 如何获取 Vuejs 链接以在组件之间切换?
- php - 无法使用 apache 构建 PHP 7.4
- coldfusion - cffile 正在覆盖现有文件
- sql - 如何理解四表连接查询
- laravel - 执行 artisan 备份时找不到 Laradock mysqldump:运行(Spatie Laravel 备份)
- python - 如何拆分维度内包含多个项目的列表?
- python - Discord.py 重写:“静音”命令不起作用