-
解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type num
问题描述
在将一个数组送入tensorflow训练时,报错如下:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
数组元素为数组,每个数组元素的shape不一致,示例如下:
|
cropImg[0].shape = (13, 13, 3) |
|
cropImg[1].shape = (14, 13, 3) |
|
cropImg[2].shape = (12, 13, 3) |
环境
python 3.7.9 tensorflow 2.6.0 keras 2.6.0
解决方法
stackoverflow上有许多类似的报错,大概意思都是数据类型错误,转换的数据类型非报错中括号里的数据类型,如: Unsupported object type numpy.ndarray
指cropImg数组元素不是numpy.ndarray类型。 博主非常不解,尝试了许多方法,都显示cropImg数组元素数据类型为numpy.ndarray,但错误一直存在。 后来突然转念,在生成cropImg数组时,有一个warning:
|
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray |
|
cropImg_ar = np.array(img_list) |
cropImg数组元素为shape不一致的数组,这说明cropImg数组元素类型实际上为object
,会不会是tensorflow不接受object类型的数据导致的? 将cropImg数组元素转换为shape一致后,问题解决。
出处:https://www.cnblogs.com/go8t/p/15705970.html
栏目列表
最新更新
博克-定制图例
博克-注释和图例
Bokeh–添加小部件
向博克图添加标签
将交互式滑块添加到博克图
在 Bokeh 中添加按钮
谷歌、微软、Meta?谁才是 Python 最大的金
Objective-C语法之代码块(block)的使用
URL Encode
go语言写http踩得坑
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
[SQL Server]按照设定的周别的第一天算任意
Linux下定时自动备份Docker中所有SqlServer数
六、Danfo.js 数据可视化
五、plotly.js 数据可视化
四、数据分析、清理、转化
三、Danfo.js 入门
第二部分:使用 Danfo.js 和 Dnotebook 的据分
一、现代 JavaScript 概述
javascript 第一部分:基础知识
零、前言
uni-app开发跨平台小程序开发的诸多坑【转
前端设计模式——桥接模式