我在目錄中有貓圖像。我想手動對這些圖像應用數據增強。我的目錄是Downloads/Images/Cats/.該目錄包含帶有兩種標簽/名稱的圖像:cat1_001.png, cat1_002.png, ...cat2_001.png, cat2_002.png, ...指定兩種類型的貓圖像。那么,如何僅從 python 目錄中遍歷標簽為 1 的圖像呢?
1 回答

DIEA
TA貢獻1820條經驗 獲得超2個贊
你可以這樣做:
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
添加回答
舉報
0/150
提交
取消