在将 列表或元组 数据转换成 dataset类型时

import numpy as np
import tensorflow as tf
from sklearn.cross_validation import train_test_split

pic_array=np.ones((60,160,3)) #图片的长宽为60*160,每个像素点的由rgb3个值表示像素
pic_txt_array=np.ones((26,4)) #表示单个字母的向量长为26,共4个字母
data_x=[pic_array  for i in range(1000)] #1000张图片的集合
data_y=[pic_txt_array for i in range(1000)]#1000长图片对应的字母的集合

#将装着样本的列表 转换成dataset格式
train_dataset=tf.data.Dataset.from_tensor_slices((data_x,data_y))

发生异常:

File "tf_test.py", line 10, in <module>
train_dataset=tf.data.Dataset.from_tensor_slices((data_x,data_y))
File "F:\Program Files\Python35\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 235, in from_tensor_slices
return TensorSliceDataset(tensors)
File "F:\Program Files\Python35\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 1030, in __init__
for i, t in enumerate(nest.flatten(tensors))
........
File "F:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 214, in constant
value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "F:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 441, in make_tensor_proto
_GetDenseDimensions(values)))
ValueError: Argument must be a dense tensor: [array([[[1., 1., 1.],...

...,
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]]])] - got shape [6, 60, 160, 3], but wanted [6].

解决:修改源数据的格式

data_x=np.asarray([pic_array for i in range(1000)]) #1000张图片的集合
data_y=np.asarray([pic_txt_array for i in range(1000)]) #1000长图片对应的字母的集合

转载于:https://www.cnblogs.com/Ting-light/p/9239404.html

ValueError: Argument must be a dense tensor:... got shape [6, 60, 160, 3], but wanted [6].相关推荐

  1. TF目标检测API-Error: Argument must be a dense tensor: range(0, 3) - got shape [3], but wanted []....

    转自:https://blog.csdn.net/lovebyz/article/details/80668881 出错原因:知乎的大佬说是python3的兼容问题 解决办法:把research/ob ...

  2. 报错解决:ResourceExhaustedError: OOM when allocating tensor with shape

    报错解决:ResourceExhaustedError: OOM when allocating tensor with shape 早上在使用tensorflow时遇到如下报错: Traceback ...

  3. 吴恩达深度学习作业L1W2:ValueError: cannot reshape array of size 12288 into shape (50,1)

    照着代码敲下来,测试部分的代码都没问题,到了最后整合的实战代码就突然报错ValueError: cannot reshape array of size 12288 into shape (50,1) ...

  4. 关于tensor的shape理解

    关于tensor的shape和dimension 刚把mnist又过了一遍,突然感觉对tensor的shape有了新的理解,虽然很基础,还是想分享一下 关于tensor的维度,也就是阶啦,从认知上理解 ...

  5. Densefuse: 成功解决ValueError: cannot reshape array of size xxx into shape (xxx,xxx,xxx)

    最近在复现图像融合Densefuse时,出现报错: ValueError: cannot reshape array of size 97200 into shape (256,256,1) 在网上查 ...

  6. tensor.view(*shape) 函数

    最近使用PyTorch编写程序,经常会遇到tensor_data.contiguous().view(-1),以此记录下其用法. view()函数用法示例及其参数详解 首先,view( ) 是对 Py ...

  7. OP_REQUIRES failed at conv_ops.cc:386 : Resource exhausted: OOM when allocating tensor with shape..

    tensorflow-gpu验证准确率是报错如上: 解决办法: 1. 加入os.environ['CUDA_VISIBLE_DEVICES']='2' 强制使用CPU验证-----慢 2.'batch ...

  8. YunYang1994/tensorflow-yolov3 ValueError: cannot reshape array of size 43095 into shape (6) 解决办法

    参考文章:YunYang1994/tensorflow-yolov3 训练自己的数据集

  9. Resource exhausted: OOM when allocating tensor with shape[620,20000] and type float on /job:localhos

    在CPU下跑的时候并没有报错,换成GPU后就一直OOM,后来被提醒道,显存比内存小很多啊,所以改小了batch_size,并将网络结构进行了优化,减少了词向量的维度和隐藏层节点个数. 另外,在代码里添 ...

  10. ValueError: cannot reshape array of size xxx into shape (xxx,xxx,xxx)解决方法

    A = A.reshape(x1,x2,x3,-..,xn); 假设A的原始shape为(y1,y2,--,yn); 这里要求满足:x1*x2******xn = y1*y2******yn; 更多精 ...

最新文章

  1. ADPRL - 近似动态规划和强化学习 - Note 8 - 近似策略迭代 (Approximate Policy Iteration)
  2. 商汤62篇论文入选CVPR 2019,一览五大方向最新研究进展
  3. 今晚8点直播 | 微软亚洲研究院副院长刘铁岩:机器学习技术前沿与未来展望
  4. Unable to locate package错误解决办法
  5. Android-广播接收者简介
  6. 使用webpack4搭建一个基于Vue的组件库
  7. [BZOJ1385][Baltic2000]Division expression
  8. 最实用的APP界面设计知识,有温度的APP设计(转)
  9. 组合模式_Java设计模式-组合模式
  10. LeetCode每日一题:比特位计数(No.338)
  11. Redis深入之道:原理解析、场景使用以及视频解读
  12. 【第144期】游戏策划:恭喜@毛毛团入职游戏策划
  13. 2021-08-27小白比记4
  14. 一锄落花,葬在了寂寞的天涯
  15. apache Fop 2.1 支持中文
  16. 如何用计算机控制ipad,躺在床上玩电脑,使用ipone ipad远程控制LAN计算机-ipad如何连接到计算机...
  17. VS2017配置PCL1.9(win10环境)
  18. 这份公众号运营攻略,可以帮你系统地运营好公众号
  19. leaflet加载接入腾讯矢量、腾讯影像地图(leaflet篇.4)
  20. 第五章——树(数据结构)

热门文章

  1. concurrenthashmap获取不到_面试必问的ConcurrentHashMap
  2. Layui 表格table 第一次加载动态设置列
  3. PHP下载服务器上的文件
  4. php中curl的用法
  5. 条件指示符 #ifndef 的用处
  6. 午休,要有午休床,也要有毛毯
  7. build.xml:391: javac doesn‘t support the “nativeheaderdir“ attribute
  8. LINUX使用sed修改文件,如果包含变量,需要使用双引号
  9. No compiler is provided in this environment. Perhaps you are running on a JRE
  10. JAVA反射性能约慢三个量级