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


    在将 列表或元组 数据转换成 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 FilesPython35libsite-packages ensorflowpythondataopsdataset_ops.py", line 235, in from_tensor_slices
    return TensorSliceDataset(tensors)
    File "F:Program FilesPython35libsite-packages ensorflowpythondataopsdataset_ops.py", line 1030, in __init__
    for i, t in enumerate(nest.flatten(tensors))
    ........
    File "F:Program FilesPython35libsite-packages ensorflowpythonframeworkconstant_op.py", line 214, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
    File "F:Program FilesPython35libsite-packages ensorflowpythonframework ensor_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长图片对应的字母的集合

  • 相关阅读:
    C语言位运算详解(转载)
    C/C++知识点
    android获取string.xml的值(转)
    C++ Primer与c++编程思想的比较(转)
    C++ 学习的网站
    C++学习网站总结(转)
    C++学习网站(转)
    C++编程学习50个经典网站 强力推荐 (转)
    JAVA反射机制(转)
    AxureRP7.0教学大纲Tutorial directory
  • 原文地址:https://www.cnblogs.com/Ting-light/p/9239404.html
Copyright © 2020-2023  润新知