tensorflow sess.run(xxx,feed_dict)ValueError:无法将字符串转换为浮点型:

时间:2019-06-27 09:30:48

标签: python dictionary tensorflow sess.run

我正在尝试实现resnet18模型以对一组图像进行多标签识别。 数据集由2个.npy文件组成,在第一个400个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
                }

`

train_batch_x和train_batch_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和self.train_y的定义: `

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)

0 个答案:

没有答案