我在目錄中有貓圖像。我想手動(dòng)對(duì)這些圖像應(yīng)用數(shù)據(jù)增強(qiáng)。我的目錄是Downloads/Images/Cats/.該目錄包含帶有兩種標(biāo)簽/名稱的圖像:cat1_001.png, cat1_002.png, ...cat2_001.png, cat2_002.png, ...指定兩種類型的貓圖像。那么,如何僅從 python 目錄中遍歷標(biāo)簽為 1 的圖像呢?
1 回答

DIEA
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
你可以這樣做:
import os
directory_in_str = 'Downloads/Images/Cats/'
directory = os.fsencode(directory_in_str)
for file in os.listdir(directory):
filename = os.fsdecode(file)
if(filename.startswith('cat1_') and filename.endswith('.png')):
print(filename)
# do your staff here
添加回答
舉報(bào)
0/150
提交
取消