【问题标题】:How to load a dataset from my google drive如何从我的谷歌驱动器加载数据集
【发布时间】:2020-12-28 14:41:01
【问题描述】:

这是我在 google colab 上写的代码。但是,执行后却报错。 代码:

img_width =500
img_height = 500
X=[]
for i in tqdm(range(data.shape[0])):
  path= '/content/drive/My Drive/DData/img' + data['id'][i] + '.png'
  img= image.load_img(path, target_size=(img_width, img_height, 3))
  img = image.img_to_array(img)
  img = img/255.0
  X.append(img)
  X= np.array(X)

这是错误:

Error:
TypeError                                 Traceback (most recent call last)
<ipython-input-81-1aa91a1867f4> in <module>()
3 X=[]
4 for i in tqdm(range(data.shape[0])):
----> 5   path= '/content/drive/My Drive/DData/img' + data['id'][i] + '.png'
6   img= image.load_img(path, target_size=(img_width, img_height, 3))
7   img = image.img_to_array(img)
TypeError: must be str, not numpy.int64**

【问题讨论】:

  • data['id'][i]的内容是什么?

标签: python google-colaboratory tensorflow2.0


【解决方案1】:

我不知道你在data['id'] 中存储了什么,但我猜它是一个数字数组,你不能与字符串连接。所以一种方法应该是将其转换为字符串:

path= '/content/drive/My Drive/DData/img' + str(data['id'][i]) + '.png'

还有一件事在您的代码中不起作用。 X= np.array(X) 将其变成一个不可变的 numpy 数组,您将无法在下一次迭代中附加任何内容。

【讨论】:

  • 我为我的“id”分配了数字
  • 我的回答能回答你的问题吗?您必须将其转换为字符串才能使其工作。
猜你喜欢
  • 2021-10-24
  • 2018-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-14
  • 1970-01-01
相关资源
最近更新 更多