【发布时间】:2020-03-25 23:59:18
【问题描述】:
我有自己的深度学习项目数据集。我将其上传到 Google Drive 并将其链接到 Colab 页面。但是 Colab 在一秒钟内只能读取 2-3 张图像,而我的计算机可以读取数十张。 (我使用 imread 来读取图像。)
keras的模型编译过程没有速度问题,但只有从Google Drive读取图像。有人知道解决方案吗?有人也遇到过这个问题,但仍未解决:Google Colab very slow reading data (images) from Google Drive(我知道这是链接中问题的重复,但我重新发布了它,因为它仍未解决。我希望这不是违反堆栈溢出规则。)
编辑:我用于读取图像的代码片段:
def getDataset(path, classes, pixel=32, rate=0.8):
X = []
Y = []
i = 0
# getting images:
for root, _, files in os.walk(path):
for file in files:
imagePath = os.path.join(root, file)
className = os.path.basename(root)
try:
image = Image.open(imagePath)
image = np.asarray(image)
image = np.array(Image.fromarray(image.astype('uint8')).resize((pixel, pixel)))
image = image if len(image.shape) == 3 else color.gray2rgb(image)
X.append(image)
Y.append(classes[className])
except:
print(file, "could not be opened")
X = np.asarray(X, dtype=np.float32)
Y = np.asarray(Y, dtype=np.int16).reshape(1, -1)
return shuffleDataset(X, Y, rate)
【问题讨论】:
-
你能提供你用来加载数据的代码吗?
-
@Solvalou 我将它添加到问题描述中。
标签: keras deep-learning conv-neural-network google-colaboratory