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

处理BOP数据集,将其和COCO数据集结合

处理BOP数据集,将其和COCO数据集结合

BOP

取消映射关系,并自增80
取消文件名的images前缀

import os
import json
from tqdm import tqdm
import argparseparser = argparse.ArgumentParser()
parser.add_argument('--json_path', default='H:/Dataset/COCO/train_pbr/000002/coco/annotations/scene_gt_coco.json', type=str,help="input: coco format(json)")
parser.add_argument('--save_path', default='H:/Dataset/COCO/train_pbr/000002/coco/labels', type=str,help="specify where to save the output dir of labels")
arg = parser.parse_args()def convert(size, box):dw = 1. / (size[0])dh = 1. / (size[1])x = box[0] + box[2] / 2.0y = box[1] + box[3] / 2.0w = box[2]h = box[3]x = x * dww = w * dwy = y * dhh = h * dhreturn (x, y, w, h)if __name__ == '__main__':json_file = arg.json_path  # COCO Object Instance 类型的标注ana_txt_save_path = arg.save_path  # 保存的路径data = json.load(open(json_file, 'r'))if not os.path.exists(ana_txt_save_path):os.makedirs(ana_txt_save_path)id_map = {}  # coco数据集的id不连续!重新映射一下再输出!for i, category in enumerate(data['categories']):id_map[category['id']] = i# 通过事先建表来降低时间复杂度max_id = 0for img in data['images']:max_id = max(max_id, img['id'])# 注意这里不能写作 [[]]*(max_id+1),否则列表内的空列表共享地址img_ann_dict = [[] for i in range(max_id + 1)]for i, ann in enumerate(data['annotations']):img_ann_dict[ann['image_id']].append(i)for img in tqdm(data['images']):filename = img["file_name"]img_width = img["width"]img_height = img["height"]img_id = img["id"]head, tail = os.path.splitext(filename)head2 = head.split("/")head3 = head2[1]ana_txt_name = head3 + ".txt"  # 对应的txt名字,与jpg一致f_txt = open(os.path.join(ana_txt_save_path, ana_txt_name), 'w')'''for ann in data['annotations']:if ann['image_id'] == img_id:box = convert((img_width, img_height), ann["bbox"])f_txt.write("%s %s %s %s %s\n" % (id_map[ann["category_id"]], box[0], box[1], box[2], box[3]))'''# 这里可以直接查表而无需重复遍历for ann_id in img_ann_dict[img_id]:ann = data['annotations'][ann_id]box = convert((img_width, img_height), ann["bbox"])#print(box[0],box[1],box[2],box[3])f_txt.write("%s %s %s %s %s\n" % (ann["category_id"]+80, box[0], box[1], box[2], box[3]))f_txt.close()

在这里插入图片描述

http://www.lryc.cn/news/234145.html

相关文章:

  • 跟李沐学AI-深度学习课程05线性代数
  • 电子病历编辑器源码(Springboot+原生HTML)
  • Qt的日志输出
  • 基于热交换算法优化概率神经网络PNN的分类预测 - 附代码
  • main.js 中的 render函数
  • Pandas 将DataFrame中单元格内的列表拆分成单独的行
  • PDF转化为图片
  • 【Java】智慧工地管理系统源码(SaaS模式)
  • torch.nn.functional.log_softmax 函数解析
  • jQuery、vue、小程序、uni-app中的本地存储数据和接受数据是什么?
  • 黑马React18: 基础Part 1
  • windows Oracle Database 19c 卸载教程
  • 动态规划解决leetcode上的两道回文问题(针对思路)
  • 使用人工智能自动测试 Flutter 应用程序
  • 四、程序员指南:数据平面开发套件
  • Go 之 captcha 生成图像验证码
  • 【Java从入门到大牛】多线程
  • UE5 C++报错:is not currently enabled for Live Coding
  • mysql服务器数据同步
  • Docker Golang 开发环境搭建指南
  • MFC保存窗口客户区为图片
  • JAVA安全之Shrio550-721漏洞原理及复现
  • 有Mac或无Mac电脑通用的获取安卓公钥的方案
  • 电池故障估计:Realistic fault detection of li-ion battery via dynamical deep learning
  • 微服务和Spring Cloud Alibaba介绍
  • 【js】 lodash命名转换和封装
  • RK3568驱动指南|第七篇 设备树-第67章 of操作函数实验:获取属性
  • vue3安装vue-router
  • 〖大前端 - 基础入门三大核心之JS篇㊱〗- JavaScript 的DOM节点操作
  • 【计算机基础】优雅的PPT就应该这样设计