张量流赛斯·润(xxx,feed\u dict)ValueError:无法将字符串转换为float:

2024-06-06 19:30:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试实现一个resnet18模型来对一组图像进行多标签识别。 数据集由2个.npy文件组成,在第一个文件中存储512*512*1个图像的矩阵;在第二个文件中存储这些图像的名称及其标签。你知道吗

print(train_feed_dict[self.x][0])
[[[ 11   0   0]
  [  0   4   0]
  [  0   7   0]
  ...
  [  3   2   0]
  [  7   0   1]
  [ 10   0   2]]

 ...

 [[  1  24  92]
  [ 11  24  92]
  [ 17  22  78]
  ...
  [  0   0   0]
  [  0   0   0]
  [  0   0   0]]]


print(train_feed_dict[self.y][0:10])
    [['VSFM7uUw' '3']
     ['J2tDltQ3' '16']
     ['Pr9SGexh' '2']
     ['CfwhN3G1' '9,8']
     ['mKR5To95' '9,10,1,2']
     ['ZLNOmXFa' '12']
     ['UaQPQ0XN' '0']
     ['hNCvKG2x' '0']
     ['wZYmeZoK' '4']
     ['Iqg9FkqJ' '0']]

print(train_feed_dict[self.lr])
    0.0032768`

train_feed_dict定义如下:

train_feed_dict = {
                    self.x : train_batch_x,
                    self.y : train_batch_y,
                    self.lr : epoch_lr
                }

`

列车批次x和列车批次y的定义 `你知道吗

train_batch_x, train_batch_y = self.get_train_batch(train_index, idx)

definition of get_train_batch:

def get_train_batch(self, xx, idx):
        return  self.train_x[idx * self.batch_size: 
     (idx+1)*self.batch_size], \
                self.train_y[idx * self.batch_size: 
    (idx+1)*self.batch_size],

`

定义自助火车以及自我训练: `你知道吗

self.train_x = np.load("/home/adios/Desktop/python/0train0_x.npy")
            self.train_y = 
np.load("/home/adios/Desktop/python/0train0_y.npy")

`

我收到的错误是: `你知道吗

Traceback (most recent call last):
    File "/home/adios/Desktop/python/resnet/train.py", line 42, in <module>
    main()
    File "/home/adios/Desktop/python/resnet/train.py", line 31, in main
    cnn.train()
    File "/home/adios/Desktop/python/resnet/ResNet.py", line 403, in 
    train
    feed_dict = train_feed_dict
    File "/home/adios/.conda/envs/tensor/lib/python2.7/site-    
    packages/tensorflow/python/client/session.py", line 929, in run
    run_metadata_ptr)
    File "/home/adios/.conda/envs/tensor/lib/python2.7/site-
    packages/tensorflow/python/client/session.py", line 1121, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
    File "/home/adios/.conda/envs/tensor/lib/python2.7/site- 
    packages/numpy/core/numeric.py", line 538, in asarray
    return array(a, dtype, copy=False, order=order)
    ValueError: could not convert string to float: iqNJyqQK

`

到目前为止,我一直在尝试将self.train_y中图片的名称改为整数以避免这个问题。例如iqNJyqQk会变成254 它确实跳过了它,然后我对2,8形式的标签有一个类似的问题,我尝试做同样的事情并在其中放入一些随机整数(此时我只想在得到正确的结果之前解决这个问题)。我确实逃脱了

ValueError: could not convert string to float: 

错误,但我有另一个错误:

ValueError: Cannot feed value of shape (128, 2) for Tensor u'y:0', 
    which has shape '(?, 29)

Tags: inpyselfhomesizefeednpbatch