tensorflow中tensor列(行)选取

tensorflow中tensor列(行)选取

今天学习Brain-tumor-segmentation-master代码,在尝试执行的过程中出现报错:
TypeError: Only integers, slices (:), ellipsis (...), tf.newaxis (None) and scalar tf.int32/tf.int64 tensors are valid indices, got [1,3]
定位报错位置:

tensorflow中tensor列(行)选取

检查发现报错原因是张量y_true_f选取特定列的表达式有误,百度解决方案基本都是shit,汇总信息后得到的解决方案如下:

y_core=K.sum(y_true_f[:,[1,3]],axis=1)

改为

tmp=tf.gather(y_true_f,[1,3],axis=1)
y_core=K.sum(tmp,axis=1)

附录:tensorflow下tensorl列(行)操作
1、选取某一列(行)或者第x列(行)到第y列(行),可以像操作数组一样书写表达式
参考链接:https://blog.csdn.net/weixin_44613063/article/details/103571787
2、选取某几列(行)需利用gather函数
参考链接:https://blog.csdn.net/qq_25964837/article/details/80462908

Original: https://blog.csdn.net/qq_43181087/article/details/126454782
Author: 眼皮跳
Title: tensorflow中tensor列(行)选取

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/720409/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球