目录
- 环境配置
- 基础知识:元祖、字典、数组
- 利用PyTorch读取COCO数据集
- 利用PyTorch读取自己制作的数据集
如何使用pytorch加载并读取COCO数据集 环境配置基础知识:元祖、字典、数组利用PyTorch读取COCO数据集利用PyTorch读取自己制作的数据集
环境配置
看pytorch入门教程
基础知识:元祖、字典、数组
# 元祖 a = (1, 2) # 字典 b = {'username': 'peipeiwang', 'code': '111'} # 数组 c = [1, 2, 3] print(a[0]) print(c[0]) print(b["username"])
输出:
利用PyTorch读取COCO数据集
import torchvision from PIL import ImageDraw # 导入coco 2017 验证集和对应annotations coco_dataset = torchvision.datasets.CocoDetection(root="COCO_dataset_val_2017/val2017", annFile="COCO_dataset_val_2017/annotations_trainval2017/annotations/instances_val2017.json") # 图像和annotation分开读取 image, info = coco_dataset[0] # ImageDraw 画图工具 image_handler = ImageDraw.ImageDraw(image) for annotation in info: # bbox为检测框的位置坐标 x_min, y_min, width, height = annotation['bbox'] # ((), ())分别为左上角的坐标对和右上角的坐标对,image_handler.rectangle是指在图片是绘制方框 image_handler.rectangle(((x_min, y_min), (x_min + width, y_min + height))) image.show()
结果:
利用PyTorch读取自己制作的数据集
使用cvat工具创建自己的数据集标注,导出为coco格式并读取
结果:
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)