当前位置: 首页 > wzjs >正文

北京市政府网站首都之窗怎么做市场推广

北京市政府网站首都之窗,怎么做市场推广,网站建设公司 未来,门户网站开发维护合同范本目录 1. 介绍 2. 使用方法 3. 注意事项 4. 示例 5.完整代码 1. 介绍 该脚本用于将多个 COCO 格式的 JSON 标注文件合并为一个 JSON 文件。COCO 格式常用于目标检测和图像分割任务,包含以下三个主要部分: "images":图像信息&a…

目录

1. 介绍

2. 使用方法

3. 注意事项

4. 示例

5.完整代码


1. 介绍

该脚本用于将多个 COCO 格式的 JSON 标注文件合并为一个 JSON 文件。COCO 格式常用于目标检测和图像分割任务,包含以下三个主要部分:

  "images":图像信息,如图像 ID、文件名等。
  "annotations":标注信息,如边界框、类别 ID 等。
  "categories":类别信息,如类别 ID、名称等。

在合并过程中,脚本会重新分配 image id、bbox id 和 category id,以避免 ID 冲突并保持一致性。合并后的 image id 和 bbox id 将从 0 开始顺序排列。

2. 使用方法

打开脚本文件(例如 concat_json.py),并修改以下两个路径:

files_root:存放 JSON 文件的文件夹路径。
output_file:合并后 JSON 文件的保存路径。

files_root = r'D:\w-dataset\AOFandODV2\annotations\val'  # 修改为您的 JSON 文件夹路径
output_file = r'D:\w-dataset\AOFandODV2\annotations\val\output.json'  # 修改为输出文件路径

3. 注意事项

JSON 格式:确保所有 JSON 文件都是有效的 COCO 格式。脚本不会检查格式错误。
ID 重新分配:合并后的 image id 和 bbox id 将从 0 开始重新分配,原始 ID 会被覆盖。
类别合并:相同的类别名称将共享同一个 category id。新的类别 ID 从 1 开始分配(0 被预留给 "ignored")。
ID 冲突:如果原始 JSON 文件中存在相同的 image id 或 bbox id,脚本会自动重新分配以避免冲突。

4. 示例

假设有以下文件夹结构:

D:\w-dataset\AOFandODV2\annotations\val
├── file1.json
├── file2.json
└── file3.json

 打开 concat_json.py 脚本。
修改 files_root 为 'D:\\w-dataset\\AOFandODV2\\annotations\\val'。
修改 output_file 为 'D:\\w-dataset\\AOFandODV2\\annotations\\val\\output.json'。
保存脚本并在终端中运行 python concat_json.py。
运行后,合并后的 JSON 文件将保存在 'D:\\w-dataset\\AOFandODV2\\annotations\\val\\output.json'。

5.完整代码

import json
from pathlib import Path
"""
拼接多个coco格式的json file
支持多个categories
会自动将 image id 与 bbox id 顺序排列
"""
def concat(files_root:str, output_file = 'output.json'):files_root = Path(files_root)#total_data = {"images": [], "categories": [{ "supercategory": None, "id": 0, "name": "_background_" }], "annotations": []}#ignoredtotal_data = {"images": [], "categories": [{"supercategory": None, "id": 0, "name": "ignored"}],"annotations": []}file_list = [str(i) for i in files_root.iterdir() if i.suffix == '.json']img_id_count, bbox_id_count, categories_count = 0, 0, 1categories_dict:dict= {}for json_file in file_list:print(f'Now Processing {json_file}')with open(file=json_file,mode='r') as f:json_data = json.load(f)images = json_data['images']annotations = json_data['annotations']categories = json_data['categories']for img_idx, image in enumerate(images):image_new = image.copy()origin_img_id = image['id']image_new['id'] = img_id_counttotal_data['images'].append(image_new)for anno_idx, anno in enumerate(annotations):if anno['image_id'] == origin_img_id:anno_new = anno.copy()anno_new['id'] = bbox_id_countanno_new['image_id'] = img_id_counttotal_data['annotations'].append(anno_new)bbox_id_count += 1for category in categories:if anno['category_id'] == category['id'] and \category['name'] not in categories_dict.keys():categories_dict[category['name']] = categories_counttotal_data['categories'].append(dict(supercategory = None, id =categories_count, name = category['name']))categories_count += 1if anno['category_id'] == category['id']:anno_new['category_id'] = categories_dict[category['name']]img_id_count += 1with open(output_file, 'w') as f:json.dump(total_data, f)if __name__ == '__main__':files_root = r'D:\w-dataset\AOFandODV2\annotations\val' # 修改为文件夹路径output_file = r'D:\w-dataset\AOFandODV2\annotations\val\output.json'  # 输出文件,默认为当前路径下的 output.jsonconcat(files_root, output_file=output_file)

http://www.dtcms.com/wzjs/266129.html

相关文章:

  • 网站因该怎么做参考文献精准客户数据采集软件
  • 西安网站建设小程序seo推广收费标准
  • 免费做效果图的网站账户竞价托管公司
  • shuwon-成都网站建设-成都网站制作-成都网络公司-蜀美网络平台推广方案模板
  • 做网站是买服务器还是买cdn淘宝指数查询入口
  • 龙岗汤坑社区网站建设什么是seo站内优化
  • 搭建网站开发网站环境山西太原百度公司
  • 沈阳建站模板展示营销渠道策略
  • 做影视网站代理犯法吗域名交易平台
  • 北京道路优化沈阳关键词优化报价
  • 青岛网站优化外呼系统电销
  • 泰州网站推广见效快竞价点击软件工具
  • 商业网站制作教程seo营销推广全程实例
  • wordpress多站点403什么是电商平台推广
  • 海外网站域名注册seo快速入门教程
  • 建站平台控制全国各大新闻网站投稿
  • 成都微信网站制作软件怎么推广
  • 洛阳直播网站建设广告联盟平台入口
  • 做网站要实名认证吗seoul是什么意思中文
  • 福州做网站多少钱贷款客户大数据精准获客
  • 青州网站seo优化工作
  • wps文字可以做网站吗seo网站关键词优化方法
  • 网站建设和网袷宣传卢镇seo网站优化排名
  • 汤阴有没有做网站的公司祁阳seo
  • .net网站 作品北京seo服务商
  • 厦门外贸网站找谁竞价代运营外包公司
  • 网站建设一六八互联网站seo外包公司
  • 云南网站建设一条龙登封网站建设公司
  • 合肥专业网站优化上海百度分公司电话
  • 番禺网站建设优化推广电商网站入口