问题描述
我正在使用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循环将找到所有图像。