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

做决定网站网络seo是什么

做决定网站,网络seo是什么,年度网站信息化建设工作计划,宿州网站制作建设coco 2017数据集提取和转换本次分割的动物数据集 4G一. coco2017数据集结构标注文件解析二. 提取需要的类别重新封装成coco数据集(这里以动物类别为例)三. 转换为yolo 数据集本次分割的动物数据集 4G https://download.csdn.net/download/qq_26696715/8…

coco 2017数据集提取和转换

  • 本次分割的动物数据集 4G
  • 一. coco2017数据集结构
    • 标注文件解析
  • 二. 提取需要的类别重新封装成coco数据集(这里以动物类别为例)
  • 三. 转换为yolo 数据集

本次分割的动物数据集 4G

https://download.csdn.net/download/qq_26696715/87621195

一. coco2017数据集结构

总的结构如下:

├─cocotoyolo.py
├─getanimal.py
├─annotations
└─images├─train2017└─val2017

其中,images存放的是训练集、验证集的图片原图;annotations中存放的是标注文件:

2017/09/01  19:04        91,865,115 captions_train2017.json
2017/09/01  19:04         3,872,473 captions_val2017.json
2017/09/01  19:02       469,785,474 instances_train2017.json
2017/09/01  19:02        19,987,840 instances_val2017.json
2017/09/01  19:04       238,884,731 person_keypoints_train2017.json
2017/09/01  19:04        10,020,657 person_keypoints_val2017.json

标注文件解析

instances_xx2017.json 是一个COCO数据集的标注文件,包含了所有训练集图片的标注信息,字段含义如下:

  1. info:数据集的相关信息,如数据集名称、版本、年份等;
  2. licenses:数据集的许可证信息;
  3. images:训练集中所有图片的信息,包括图片ID、文件名、高度、宽度等;
  4. annotations:训练集中所有标注信息,包括标注ID、图片ID、类别ID、边界框坐标等;
  5. categories:所有类别的信息,包括类别ID、类别名称、超类别名称等。

具体解释如下:

  1. info:数据集的相关信息,包括数据集名称、版本、作者、年份等。例如,info 字段中可能包含以下信息:

    “info”: {
    “description”: “COCO 2017 Dataset”,
    “url”: “http://cocodataset.org”,
    “version”: “1.0”,
    “year”: 2017,
    “contributor”: “COCO Consortium”,
    “date_created”: “2017/09/01” }

  2. licenses:数据集的许可证信息,包括许可证ID、许可证名称等。例如,licenses 字段中可能包含以下信息:

    “licenses”: [
    {
    “id”: 1,
    “name”: “Attribution-NonCommercial-ShareAlike License”,
    “url”: “http://creativecommons.org/licenses/by-nc-sa/2.0/”
    } ]

  3. images:训练集中所有图片的信息,包括图片ID、文件名、高度、宽度等。例如,images 字段中可能包含以下信息:

    “images”: [
    {
    “id”: 1,
    “file_name”: “000000000009.jpg”,
    “height”: 480,
    “width”: 640,
    “date_captured”: “2013-11-14 17:02:52”,
    “license”: 1
    } ]

  4. annotations:训练集中所有标注信息,包括标注ID、图片ID、类别ID、边界框坐标等。例如,annotations 字段中可能包含以下信息:

    “annotations”: [
    {
    “id”: 1,
    “image_id”: 1,
    “category_id”: 1,
    “bbox”: [96.0, 120.0, 112.0, 80.0],
    “area”: 8960.0,
    “iscrowd”: 0
    } ]

  5. categories:所有类别的信息,包括类别ID、类别名称、超类别名称等。例如,categories 字段中可能包含以下信息:

    “categories”: [
    {
    “id”: 1,
    “name”: “person”,
    “supercategory”: “person”
    } ]

二. 提取需要的类别重新封装成coco数据集(这里以动物类别为例)

提取完成后的新文件夹为

├─animal_detection
│  ├─annotations
│  └─images
│      ├─train2017
│      └─val2017

提取代码 getanimal.py

import os
import json
import shutil# 定义要提取的类别
categories = ['bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe']# 定义数据集路径
data_dir = './'# 定义输出路径
output_dir = './animal_detection'# 创建输出目录
if not os.path.exists(os.path.join(output_dir, 'annotations')):os.makedirs(os.path.join(output_dir, 'annotations'))os.makedirs(os.path.join(output_dir, 'images', 'train2017'))os.makedirs(os.path.join(output_dir, 'images', 'val2017'))'''
训练集
'''
# 加载原始instances文件
with open(os.path.join(data_dir, 'annotations', 'instances_train2017.json'), 'r') as f:train_instances = json.load(f)# 筛选动物类别的id
# 筛选动物类别的id
animal_ids = []
new_categories = []
for c in train_instances['categories']:if c['name'] in categories:animal_ids.append(c['id'] )new_categories.append(c)# 筛选出验证集中包含动物的图片id
train_image_ids = set()
new_train_annotations = []
for ann in train_instances['annotations']:if ann['category_id'] in animal_ids:train_image_ids.add(ann['image_id'])new_train_annotations.append(ann)new_images = []
# 复制验证集中包含动物的图片到输出目录
for image in train_instances['images']:if image['id'] in train_image_ids:new_images.append(image)shutil.copy(os.path.join(data_dir, 'images', 'train2017', image['file_name']), os.path.join(output_dir, 'images', 'train2017'))# 构造新的instances文件
new_train_instances = {'info': train_instances['info'],'licenses': train_instances['licenses'],'images':new_images,'annotations': new_train_annotations,'categories': new_categories
}# 保存新的instances文件
with open(os.path.join(output_dir, 'annotations', 'instances_train2017.json'), 'w') as f:json.dump(new_train_instances, f)'''
验证集
'''
with open(os.path.join(data_dir, 'annotations', 'instances_val2017.json'), 'r') as f:val_instances = json.load(f)# 筛选动物类别的id
animal_ids = []
new_categories = []
for c in val_instances['categories']:if c['name'] in categories:animal_ids.append(c['id'] )new_categories.append(c)# 筛选出验证集中包含动物的图片id
val_image_ids = set()
new_val_annotations = []
for ann in val_instances['annotations']:if ann['category_id'] in animal_ids:val_image_ids.add(ann['image_id'])new_val_annotations.append(ann)new_images = []
# 复制验证集中包含动物的图片到输出目录
for image in val_instances['images']:if image['id'] in val_image_ids:new_images.append(image)shutil.copy(os.path.join(data_dir, 'images', 'val2017', image['file_name']), os.path.join(output_dir, 'images', 'val2017'))new_val_instances = {'info': val_instances['info'],'licenses': val_instances['licenses'],'images': new_images,'annotations': new_val_annotations,'categories': new_categories
}with open(os.path.join(output_dir, 'annotations', 'instances_val2017.json'), 'w') as f:json.dump(new_val_instances, f)

三. 转换为yolo 数据集

转换后生成

├─animal_detection
│  ├─classes.txt
│  ├─train2017.txt
│  ├─val2017.txt
│  ├─annotations
│  ├─images
│  │  ├─train2017
│  │  └─val2017
│  └─label

转换代码 cocotoyolo.py

#COCO 格式的数据集转化为 YOLO 格式的数据集
#--json_path 输入的json文件路径
#--save_path 保存的文件夹名字,默认为当前目录下的labels。import os
import json
from tqdm import tqdmdef 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]
#round函数确定(xmin, ymin, xmax, ymax)的小数位数x = round(x * dw, 6)w = round(w * dw, 6)y = round(y * dh, 6)h = round(h * dh, 6)return (x, y, w, h)if __name__ == '__main__':#这里根据自己的json文件位置,换成自己的就行root = "animal_detection/"json_trainfile = root+'annotations/instances_train2017.json' # COCO Object Instance 类型的标注json_valfile = root+'annotations/instances_val2017.json' # COCO Object Instance 类型的标注ana_txt_save_path = root+'labels/'  # 保存的路径traindata = json.load(open(json_trainfile, 'r'))valdata = json.load(open(json_valfile, 'r'))# 重新映射并保存class 文件if not os.path.exists(ana_txt_save_path):os.makedirs(ana_txt_save_path)id_map = {} # coco数据集的id不连续!重新映射一下再输出!with open(os.path.join(root, 'classes.txt'), 'w') as f:# 写入classes.txtfor i, category in enumerate(traindata['categories']):f.write(f"{category['name']}\n")id_map[category['id']] = i'''保存train txt'''# print(id_map)#这里需要根据自己的需要,更改写入图像相对路径的文件位置。list_file = open(os.path.join(root, 'train2017.txt'), 'w')for img in tqdm(traindata['images']):filename = img["file_name"]img_width = img["width"]img_height = img["height"]img_id = img["id"]head, tail = os.path.splitext(filename)ana_txt_name = head + ".txt"  # 对应的txt名字,与jpg一致f_txt = open(os.path.join(ana_txt_save_path, ana_txt_name), 'w')for ann in traindata['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]))f_txt.close()#将图片的相对路径写入train2017或val2017的路径list_file.write('./images/train2017/%s.jpg\n' %(head))list_file.close()'''保存val txt'''# print(id_map)#这里需要根据自己的需要,更改写入图像相对路径的文件位置。list_file = open(os.path.join(root, 'val2017.txt'), 'w')for img in tqdm(valdata['images']):filename = img["file_name"]img_width = img["width"]img_height = img["height"]img_id = img["id"]head, tail = os.path.splitext(filename)ana_txt_name = head + ".txt"  # 对应的txt名字,与jpg一致f_txt = open(os.path.join(ana_txt_save_path, ana_txt_name), 'w')for ann in valdata['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]))f_txt.close()#将图片的相对路径写入train2017或val2017的路径list_file.write('./images/val2017/%s.jpg\n' %(head))list_file.close()
http://www.lbrq.cn/news/2554939.html

相关文章:

  • 创建软件网站seo的优化策略有哪些
  • 手机网站设计作品欣赏搜狗seo
  • 房屋网站模板购物网站大全
  • 兰州企业网站网络公司网站
  • 提供邯郸做移动网站seo教程
  • 学校网站建设调查报告软件开发外包公司
  • 无锡商城网站建设哈尔滨网络推广
  • app拉新渠道南宁seo营销推广
  • 做动态网站学php_asp+还是jsp好?武汉网站搜索引擎优化
  • 清远网站建设推广关键词排名点击软件推荐
  • 面包类网站设计成都网站设计
  • 可以自己做视频网站吗拼多多商品关键词搜索排名
  • 怎么买域名自己做网站营销团队找产品合作
  • 网站文章更新做销售找客户渠道
  • 昆明网站开发哪家好网站定制
  • 上海松江区做网站的公司成都百度seo优化公司
  • 对省政府网站建设的发展有期待seo快速推广
  • 平顶山公司做网站seo关键词优化系统
  • 网站开发团队介绍谷歌商店下载官网
  • 品划做网站广告公司广告牌制作
  • 常德市人民政府网站今日最新闻
  • 律师网站深圳网站设计关键词热度分析工具
  • 河南映天建设网站关键词优化技巧
  • 网站建设综合推荐指数网站
  • 做网站咋不用买虚拟机网址和网站的区别
  • 海南专业网站建设seo的排名机制
  • 做网站服务器需要系统关键词生成器 在线
  • 网站建设差打不开疫情防控最新通告
  • 重庆百度网站快速排名怎么样推广自己的产品
  • 高端企业门户网站建设服务公司外贸营销推广
  • Gitee
  • Ubuntu 开启wifi 5G 热点
  • android MVC/MVP/MVVM/MVI架构发展历程和编写范式
  • WPF TreeView自带自定义滚动条
  • Vue项目使用ssh2-sftp-client实现打包自动上传到服务器(完整教程)
  • 嵌入式教学的云端革命:高精度仿真如何重塑倒车雷达实验与工程教育——深圳航天科技创新研究院赋能新一代虚实融合实训平台