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}")  # 如果没有匹配的配置文件,打印提示信息
相关推荐
来两个炸鸡腿2 小时前
【Datawhale2609】算子开发实战 task02-TileLang Add 与 NineToothed Vector Add
人工智能·大模型·算子
Hotchip_MEMS2 小时前
传统咪头与MEMS硅麦:雾化器气流传感方案对比
人工智能·笔记·物联网·电脑·制造
4SAPI2 小时前
大模型接口管理平台推荐:多模型时代的API Gateway架构与选型分析
人工智能·agent
皇儒无上2 小时前
智慧矿山-关于推进山西省煤矿灾害差异化智能化建设强化 AI 风险防控的政策建议
人工智能·机器学习·区块链
YOLO数据集集合2 小时前
小目标无人机、飞机、直升机检测数据集 | 小目标检测 无人机检测 空中目标识别 低空安防 反无人机9090期
深度学习·yolo·目标检测·无人机·飞机·小目标·直升机
byte轻骑兵2 小时前
【LE Audio】PBP精讲[4]: 公共广播通告的设计逻辑与数据交互流程
人工智能·音视频·le audio·低功耗蓝牙音频
山科智能信息处理实验室2 小时前
arXiv 2025 | Retrieval Survey:推荐系统召回阶段的方法分类与工业落地全解析
深度学习·推荐算法
正经教主2 小时前
【FDE系列】阶段2:Day 28:FastAPI 入门 — 把你的函数变成 API 服务
人工智能·python·fde
天远Date Lab3 小时前
零信任架构实战:基于天远名下企业A构建自动化商户合规网关
人工智能·ai·工具分享