解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
问题描述
在将一个数组送入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
解决方法
stackoverlow上有许多类似的报错,大概意思都是数据类型错误,转换的数据类型非报错中括号里的数据类型,如:
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://stackoverflow.com/questions/62570936/valueerror-failed-to-convert-a-numpy-array-to-a-tensor-unsupported-object-type
https://stackoverflow.com/questions/58636087/tensorflow-valueerror-failed-to-convert-a-numpy-array-to-a-tensor-unsupporte
https://blog.csdn.net/liveshow021_jxb/article/details/112752145
解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)的更多相关文章
- 完美解决报错Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'
Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' 首先这个错误的意思是 前台页面 ...
- numpy array的复制-【老鱼学numpy】
对象的引用 看例子: a = np.array([0, 1, 2, 3]) b = a a[0] = 5 print("b=", b) # 判断a和b是否是同样的地址 print( ...
- Python中 list, numpy.array, torch.Tensor 格式相互转化
1.1 list 转 numpy ndarray = np.array(list) 1.2 numpy 转 list list = ndarray.tolist() 2.1 list 转 torch. ...
- Python 将numpy array由浮点型转换为整型
Python 将numpy array由浮点型转换为整型 ——使用numpy中的astype()方法可以实现,如:
- python numpy.array插入一行或一列
numpy.array插入一行或一列 import numpy as np a = np.array([[1,2,3],[4,5,6],[7,8,9]]) b = np.array([[0,0,0]] ...
- tensorflow基础--LeNet-5测试模型遇到TypeError: Failed to convert object of type <class 'list'> to Tensor
最近在看<TensorFlow 实战Google深度学习框架第二版>这本书,测试LeNet-5这个模型时遇到了TypeError: Failed to convert object of ...
- 解决spring mvc 上传报错,Field [] isn't an enum value,Failed to convert value of type 'java.lang.String[]' to required type '
没有选择附件,但是点击上传按钮的时候会报错. 之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了. 错误信息: -- :: [http--] TRACE org.springframe ...
- Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决
今天做springbook项目前端输入日期传到数据库保存报了一下错误 Whitelabel Error Page This application has no explicit mapping fo ...
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
异常信息如下: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value ...
随机推荐
- [bzoj1416]神奇的口袋
容易发现操作任意次并不会改变每一个点的概率(因为每一个点加d的概率相同,期望与原数成比例),然后直接输出即可(要用高精度) 1 #include<bits/stdc++.h> 2 usin ...
- Ubuntu压缩和解压缩
1.常用的压缩格式 tar tar.bz2 tar.gz 2.gzip压缩 gzip xxx //压缩 gzip -d xxx.gz //解压缩 gzip对文件夹的压缩 gzip -r xxx //文 ...
- Spring Cloud Alibaba微服务一站式解决方案-开篇v2.2.1.RELEASE
学习路线 **本人博客网站 **IT小神 www.itxiaoshen.com 生态概述 架构演进 什么是微服务 https://martinfowler.com/microservices/ Mic ...
- ICCV2021 | Swin Transformer: 使用移位窗口的分层视觉Transformer
前言 本文解读的论文是ICCV2021中的最佳论文,在短短几个月内,google scholar上有388引用次数,github上有6.1k star. 本文来自公众号CV技术指南的论文分享系 ...
- JdbcTemplate 、Mybatis、ORM 、Druid 、HikariCP 、Hibernate是什么?它们有什么关系?
JdbcTemplate .Mybatis.ORM .Druid .HikariCP .Hibernate是什么?它们有什么关系? 学完Spring和SpringMVC之后,就急于求成的开始学习起Sp ...
- Treevalue(0x03)——函数树化详细解析(下篇)
好久不见,再一次回到 treevalue 系列.本文将基于上一篇treevalue讲解,继续对函数的树化机制进行详细解析,并且会更多的讲述其衍生特性及应用. 树化方法与类方法 首先,基于之前的树化函数 ...
- 深入理解 OpenFOAM 环境变量与编译
操作系统选择 由于 OpenFOAM 在 Linux 平台开发和测试,在非 Linux 平台无法直接对软件进行编译和安装,所以在非 Linux 平台上最简便方法是使用 docker 容器运行 Open ...
- R包xlsx安装与使用
1. Rstudio安装xlsx报错 xlsx包加载依赖Java环境,我之前就安装过Java,但安装xlsx成功后,加载xlsx时一直报错: Error : loadNamespace()里算'rJ ...
- Docker Nginx-Proxy 容器Nginx Proxy反向代理
Docker Nginx-Proxy 容器Nginx Proxy反向代理 简单介绍 Docker容器的自动Nginx反向代理 dockerhub地址 https://hub.docker.co ...
- rkhunter使用
1.下载地址:http://jaist.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.6/ 2.上传至Linux后解压 3.编译安装 [root@t ...