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}")  # 如果没有匹配的配置文件,打印提示信息
相关推荐
nenchoumi3119几秒前
VLA 论文精读(十六)FP3: A 3D Foundation Policy for Robotic Manipulation
论文阅读·人工智能·笔记·学习·vln
后端小肥肠10 分钟前
文案号搞钱潜规则:日入四位数的Coze工作流我跑通了
人工智能·coze
LCHub低代码社区12 分钟前
钧瓷产业原始创新的许昌共识:技术破壁·产业再造·生态重构(一)
大数据·人工智能·维格云·ai智能体·ai自动化·大禹智库·钧瓷码
-曾牛12 分钟前
Spring AI 快速入门:从环境搭建到核心组件集成
java·人工智能·spring·ai·大模型·spring ai·开发环境搭建
阿川201516 分钟前
云智融合普惠大模型AI,政务服务重构数智化路径
人工智能·华为云·政务·deepseek
自由鬼44 分钟前
开源AI开发工具:OpenAI Codex CLI
人工智能·ai·开源·软件构建·开源软件·个人开发
生信碱移1 小时前
大语言模型时代,单细胞注释也需要集思广益(mLLMCelltype)
人工智能·经验分享·深度学习·语言模型·自然语言处理·数据挖掘·数据可视化
一个数据大开发1 小时前
解读《数据资产质量评估实施规则》:企业数据资产认证落地的关键指南
大数据·数据库·人工智能
云卓SKYDROID1 小时前
无人机环境适应性与稳定性技术要点!
人工智能·无人机·科普·高科技·云卓科技
小诸葛的博客1 小时前
详解Linux中的定时任务管理工具crond
linux·运维·chrome