gpt4 book ai didi

python - 谷歌 Colab : How to loop through images in a folder?

转载 作者:行者123 更新时间:2023-12-03 18:32:27 25 4
gpt4 key购买 nike

我已根据 Google Colab: how to read data from my google drive? 将大量 .jpg 图片从我的 Google Drive 复制到 Google Colab :

local_download_path = os.path.expanduser('~/data')
try:
os.makedirs(local_download_path)
except: pass

# 2. Auto-iterate using the query syntax
# https://developers.google.com/drive/v2/web/search-parameters
file_list = drive.ListFile(
{'q': "'1SooKSw8M4ACbznKjnNrYvJ5wxuqJ-YCk' in parents"}).GetList()

for f in file_list:
# 3. Create & download by id.
print('title: %s, id: %s' % (f['title'], f['id']))
fname = os.path.join(local_download_path, f['title'])
print('downloading to {}'.format(fname))
f_ = drive.CreateFile({'id': f['id']})
f_.GetContentFile(fname)

这样就完成了,所以所有的图像文件都应该在 data 中。文件夹。我现在如何实际访问这些文件?我想遍历 data 中所有 .jpg 类型的文件文件夹。

最佳答案

一种替代方法是使用已经实现的 os 库。

# Just needed in case you'd like to append it to an array
data = []

for filename in os.listdir(local_download_path):
if filename.endswith("jpg"):
# Your code comes here such as
print(filename)
data.append(filename)

关于python - 谷歌 Colab : How to loop through images in a folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com