无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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)

宜宾县| 梨树县| 隆林| 全南县| 宽城| 西青区| 南皮县| 铁岭县| 新巴尔虎右旗| 肥城市| 阳高县| 和顺县| 焉耆| 英超| 南涧| 千阳县| 荔波县| 泸州市| 罗山县| 张家港市| 和顺县| 清新县| 道真| 宣汉县| 会昌县| 府谷县| 绥德县| 富源县| 镇安县| 神农架林区| 兰溪市| 富蕴县| 资源县| 盐池县| 万荣县| 大埔县| 永靖县| 桐梓县| 衡阳县| 睢宁县| 酒泉市|