-
解决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
最新更新
Python获取微信好友数据
Python 的排序方法 sort 和 sorted 的区别
WinForm轻松实现自定义分页 (转载)
Mac系统下使用brew搭建PHP(LNMP/LAMP)开发环境
在win系统安装配置 Memcached for PHP 5.3 图文
箱图在数据预处理中的应用
Python WEB开发:用Tornado框架制作简易【表
自从学会了用python解析视频,都不用去找
Python代码阅读(第50篇):对列表间隔取
Python爬虫+数据分析+可视化展示,分析《
MongoDB常用命令(2)
MongoDB基本介绍与安装(1)
SQLServer触发器调用JavaWeb接口
SQL Server索引的原理深入解析
SqlServer2016模糊匹配的三种方式及效率问题
SQL中Truncate的用法
sqlserver 多表关联时在where语句中慎用tri
链接服务器读取Mysql---出现消息 7347,级别
SQL Server解惑——为什么你拼接的SQL语句换
MySQL视图了解一下
laf.js - 开源的云开发框架(README.md)
javascript创建对象
Node.js 源码分析 - 从 main 函数开始
Node.js 源码分析 - 原生模块(C++模块)的注册
ECharts图标中用的js相关的处理方法
GoJS 使用笔记
单元测试 - 测试场景记录
Node.js 源码分析 - 加载 js 文件
ES6入门
聊聊动效降级