如何从Google Colab的“ train”文件夹中的多个文件夹中加载多个图像?

问题描述

I want to find those images and assign it to train variable as shown. Problem is mine one is not a gzip file. Mine one is 6 folders,each with 40 images(.jpg) in it.  So which command to use?

我正在使用Google Colab进行食品分类的ML模型。我的火车文件夹包含6个子文件夹。我想读取所有图像,并将其分配给train_images变量,如图所示。问题是我有6个文件夹,每个文件夹中有40张图片(.jpg)。那么代码应该是什么?我为此使用python。

请帮助!

解决方法

这可能有帮助:

>>> for folder in os.listdir('desktop/images'):
...     for image in os.listdir(f'desktop/images/{folder}'): print(image)
...
20160327_174551.jpg
20160327_174559.jpg
20160327_174636.jpg
20160327_174718.jpg
20160327_174756.jpg
20160327_174810.jpg

images目录中有六个文件夹,每个文件夹中有一个图像。这两个for循环将找到所有图像。