借助Qwen-VL-Chat大模型生成xml标注-纯代码-干货分享

本文默认使用以下代码前已准备好Qwen-VL的运行环境,且已下载了Qwen-VL-Chat模型文件。
具体环境按照方式参考官网:
https://github.com/QwenLM/Qwen-VL/blob/master/README_CN.md
本工具参考:https://github.com/QwenLM/Qwen-VL/blob/master/TUTORIAL.md

# 借助Qwen-VL-Chat大模型生成xml标注的工具, 但生成的标签名称不固定,因为是大模型随机分析的目标名,可根据需求自行修改
import os
import os.path as osp
import re
from tqdm import tqdm
import torch
torch.manual_seed(1234)
# from transformers.generation import GenerationConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
from xml.dom.minidom import Document
import cv2



def write_xml(objects:list, img_name:str, xml_pth:str):
    xml_dir = osp.join(xml_pth, img_name.replace(".jpg", ".xml"))

    doc = Document()
    annotation = doc.createElement("annotation")
    doc.appendChild(annotation)

    folder = doc.createElement("folder")
    folder_text = doc.createTextNode("JPEGImages")
    folder.appendChild(folder_text)
    annotation.appendChild(folder)

    filename = doc.createElement("filename")
    filename_text = doc.createTextNode(img_name)
    filename.appendChild(filename_text)
    annotation.appendChild(filename)

    path = doc.createElement("path")
    path_text = doc.createTextNode(objects.get("imagePath"))
    path.appendChild(path_text)
    annotation.appendChild(path)

    source = doc.createElement("source")
    database = doc.createElement("database")
    database_text = doc.createTextNode("Unknown")
    database.appendChild(database_text)
    source.appendChild(database)
    annotation.appendChild(source)

    size = doc.createElement("size")
    width = doc.createElement("width")
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值