PaddleSeg 从配置文件和模型 URL 自动化运行预测任务

python 复制代码
git clone  https://github.com/PaddlePaddle/PaddleSeg.git
python 复制代码
# 在ipynb里面运行
cd PaddleSeg
python 复制代码
import sys
sys.path.append('/home/aistudio/work/PaddleSeg')
python 复制代码
import os

# 配置文件夹路径
folder_path = "/home/aistudio/work/PaddleSeg/configs"

# 遍历文件夹,寻找所有 .yml 文件并存储到字典中
# key 是文件名(不带扩展名),value 是文件的完整路径
yml_files = {}
for root, dirs, files in os.walk(folder_path):
    for file in files:
        if file.lower().endswith(".yml"):
            file_path = os.path.join(root, file)
            file_name_without_extension = os.path.splitext(file)[0]  # 获取文件名(不带扩展名)
            yml_files[file_name_without_extension] = file_path  # 保存文件路径
            print(file_path)  # 打印找到的配置文件路径

# 读取包含模型 URL 的文件
file_to_read = "/home/aistudio/work/PaddleSeg/voc/pascal_voc12_urls_extracted.txt"
url_lines = {}
if os.path.exists(file_to_read):
    with open(file_to_read, 'r') as f:
        lines = f.readlines()
        for line in lines:
            url = line.strip()  # 去除换行符和多余空格
            parsed_name = url.split("/")[-2]  # 提取 URL 中的模型名称部分
            url_lines[parsed_name] = url  # 保存模型名称与 URL 的映射
            print(url)  # 打印提取的 URL
else:
    print(f"File not found: {file_to_read}")  # 如果文件不存在,打印提示信息

# 拼接并运行预测命令
base_command = "python tools/predict.py --config {} --model_path {} --image_path /home/aistudio/data/data117064/voctestimg --save_dir {}"
for model_name, model_path in url_lines.items():
    if model_name in yml_files:  # 检查模型名称是否有对应的配置文件
        config_file = yml_files[model_name]  # 获取匹配的配置文件路径
        save_dir = f"output/{model_name}"  # 保存路径按照模型名称组织
        os.makedirs(save_dir, exist_ok=True)  # 确保保存目录存在
        command = base_command.format(config_file, model_path, save_dir)  # 填充命令模板
        print(f"Executing: {command}")  # 打印正在执行的命令
        os.system(command)  # 执行命令
    else:
        print(f"No matching config file found for model: {model_name}")  # 如果没有匹配的配置文件,打印提示信息
相关推荐
GrepowTattu15 分钟前
从2026世界机器人大会看机器人补能:为什么智能充电正在成为重要一环
人工智能·机器人
IT_陈寒24 分钟前
React Hooks闭包陷阱差点让我加班到凌晨
前端·人工智能·后端
揽秀亭长25 分钟前
视频转文字工具对比:从字幕生成到文本整理
人工智能·音视频
工业甲酰苯胺26 分钟前
AI低代码破局:制造业数智转型落地实战
大数据·人工智能·低代码·制造
CaseyWei34 分钟前
Harness 架构 Multi‑Agent(多智能体)完整深度解析
人工智能·ai·架构·harness
开心大爆炸39 分钟前
xrdp 连接 登录对话框输入密码后闪退
linux·运维·服务器
eaglewgs1 小时前
关于AI书写测试用例,谈一下我的思考
人工智能·测试开发·ai·测试用例·agent·测试经验·agent测试开发
熊野君1 小时前
第 4 章 技术产品经理核心能力模型
大数据·人工智能·产品经理
问天_观心1 小时前
大模型微调学习(一)
开发语言·人工智能·学习·语言模型·github
百胜软件@百胜软件1 小时前
AI赋能零售,迈向智能零售时代丨黄飞获邀担任2026年度上海市专业技术人才知识更新工程急需紧缺人才培养项目讲师
人工智能·百度·零售