我想将 Google Drive 中的多个图像文件读入我的 Google Colab Python Notebook 下面是我的 Google Drive 文件夹结构
--Drive
--Main_Folder
--Sub_Folder_1
--imagefile1.jpg
--imagefile2.jpg
--imagefile3.jpg
--Sub_Folder_2
--imagefile1.jpg
--imagefile2.jpg
--imagefile3.jpg
--Sub_Folder_3
--imagefile1.jpg
--imagefile2.jpg
--imagefile3.jpg
答案 0 :(得分:0)
首先在您的 colab 实例上安装谷歌驱动器,然后执行此操作。
import os
from PIL import Image
info = []
for root, __, files in os.walk("path/to/google/drive/folder"):
for f in files:
if f.endswith(".jpg"):
info.append({
"img": Image.open(os.path.join(root, f)), # add an appropriate reading flag if you want
# optional
# "foldername": os.path.dirname(root)
})
# do whatever you want with the infolist you have now