tensorflow - “仅整数、切片 (`:`)、省略号 (`...`)、tf.newaxis (`None`) 和标量”出错
问题描述
我正在尝试使用 Tensorflow 后端在 Keras 中训练深度学习算法。我正在尝试执行以下操作:
x = tf.reshape(theta, [-1])[K.argmax(image)]
image
输入在哪里,eta
是一个坐标。我正在尝试使 theta 变平,但出现错误
Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf.int64 tensors are valid indices, got <tf.Tensor 'loss_42/dense_264_loss/ArgMax:0' shape=(25,) dtype=int64>
解决方案
我猜你想根据K.argmax(image)
. 您不能直接在张量流中使用花哨的索引样式。tf.gather
可以做到这一点。
res = tf.gather(tf.reshape(theta, [-1]), K.argmax(image))
推荐阅读
- entity-framework - 升级到 .NET Core 3.1 并在与使用 .FirstOrDefault() 相关的 LINQ 查询中收到错误
- python - 使用正则表达式提取匹配的任一侧的字符
- javascript - 为什么shopify可拖动事件开始:第一次后拖动停止工作
- css - 如何为输入类型日期设置省略号(本机日期选择器 html)
- javascript - *ng-if 不在 ionic 5 中的 ion-modal 内部工作
- wpf - 图像、按钮或切换按钮不会显示在任何笔记本电脑上
- node.js - 运行节点应用程序时带有环境变量的 Docker CMD
- haskell - 如何在 Hakyll html 中为第二个帖子目录创建第二个列表?
- css - 为什么在尝试将我的 Angular 项目从基于 CSS 的项目转换为 SCSS 项目时出现此错误?
- django - 为前端图片渲染创建一个“虚拟”URL 路径