最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

PyTorch深度學(xué)習(xí)快速入門教程(絕對通俗易懂!)【小土堆】

2023-02-22 20:22 作者:霧彥poison  | 我要投稿

P7 p6. Dataset類代碼實戰(zhàn)

對P7寫入txt文檔略做了些調(diào)整:

(ps:增加了檢查文件夾是否存在,不存在則創(chuàng)建的功能,這樣就省去了自己自己再去一個個創(chuàng)建的功能)

import os


root_dir = “your_path”

# 使用字典的“鍵值對”將目標圖片文件夾與標簽文件對應(yīng)

targets = {

"ants_image": "ants_label",

"bees_image": "bees_label",

"spiders_image": "spiders_label"

}


# 創(chuàng)建文件夾、遍歷

for target_dir, out_dir in targets.items():

# 檢查標簽文件夾是否存在,沒有則創(chuàng)建

if not os.path.exists(os.path.join(root_dir, out_dir)):

os.makedirs(os.path.join(root_dir, out_dir))

img_paths = os.listdir(os.path.join(root_dir, target_dir))

label = target_dir.split('_')【0】

for img_path in img_paths:

file_name = img_path.split('.jpg')【0】

with open(os.path.join(root_dir, out_dir, f"{file_name}.txt"), 'w+') as f:

f.write(label)

临澧县| 瓮安县| 宁津县| 东方市| 庐江县| 香格里拉县| 宁津县| 山东| 邢台县| 温州市| 亚东县| 大洼县| 蓬莱市| 宣恩县| 江油市| 牟定县| 甘肃省| 吐鲁番市| 浮山县| 京山县| 宁远县| 云安县| 荔波县| 基隆市| 定西市| 福贡县| 玉龙| 汉阴县| 丘北县| 成都市| 岳阳县| 遵义县| 常德市| 永顺县| 普格县| 夏津县| 上高县| 大同县| 延川县| 竹溪县| 绍兴市|