国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

东光县| 洮南市| 原阳县| 武隆县| 西乌| 平果县| 永仁县| 庐江县| 邹城市| 嘉义县| 福海县| 石门县| 运城市| 淮阳县| 曲周县| 邹城市| 射阳县| 上饶县| 连云港市| 鄢陵县| 滕州市| 阿鲁科尔沁旗| 青神县| 彰武县| 石渠县| 紫金县| 家居| 芦溪县| 弥勒县| 竹山县| 鱼台县| 义马市| 日土县| 枣庄市| 龙泉市| 津市市| 凤冈县| 伊春市| 财经| 闻喜县| 永寿县|