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}")  # 如果没有匹配的配置文件,打印提示信息
相关推荐
降世神童14 分钟前
华为云Flexus+DeepSeek征文| 使用华为云CCE容器部署Dify-LLM高可用方案的验证与测试
运维·华为云·aigc
降世神童15 分钟前
华为云Flexus+DeepSeek征文| 基于华为云Dify-LLM高可用平台开发运维故障处理智能体
运维·华为云·aigc
笑衬人心。33 分钟前
初学Spring AI 笔记
人工智能·笔记·spring
luofeiju42 分钟前
RGB下的色彩变换:用线性代数解构色彩世界
图像处理·人工智能·opencv·线性代数
测试者家园1 小时前
基于DeepSeek和crewAI构建测试用例脚本生成器
人工智能·python·测试用例·智能体·智能化测试·crewai
张较瘦_1 小时前
[论文阅读] 人工智能 + 软件工程 | Call Me Maybe:用图神经网络增强JavaScript调用图构建
论文阅读·人工智能·软件工程
大模型真好玩1 小时前
准确率飙升!Graph RAG如何利用知识图谱提升RAG答案质量(四)——微软GraphRAG代码实战
人工智能·python·mcp
Baihai_IDP1 小时前
vec2text 技术已开源!一定条件下,文本嵌入向量可“近乎完美地”还原
人工智能·面试·llm
江太翁1 小时前
Pytorch torch
人工智能·pytorch·python
拓端研究室1 小时前
专题:2025即时零售与各类人群消费行为洞察报告|附400+份报告PDF、原数据表汇总下载
大数据·人工智能