亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何遍歷目錄中的圖像?

如何遍歷目錄中的圖像?

湖上湖 2023-06-20 15:13:45
我在目錄中有貓圖像。我想手動對這些圖像應用數據增強。我的目錄是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


查看完整回答
反對 回復 2023-06-20
  • 1 回答
  • 0 關注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號