PyTorch 中的 CocoCaptions (1)

请我喝杯咖啡☕

*备忘录:

我的帖子解释了cocodetection()使用带有captions_train2014.json、instances_train2014.json和person_keypoints_train2014.json的train2014、带有captions_val2014.json、instances_val2014.json和person_keypoints_val2014.json的val2014以及带有image_info_test2014.json的test2017, image_info_test2015.json 和 image_info_test-dev2015.json。我的帖子解释了cocodetection()使用train2017与captions_train2017.json,instances_train2017.json和person_keypoints_train2017.json,val2017与captions_val2017.json,instances_val2017.json和person_keypoints_val2017.json和test2017与image_info_test2017.json和image_info_test-dev2017.json.我的帖子解释了cocodetection()使用train2017与stuff_train2017.json,val2017与stuff_val2017.json,stuff_train2017_pixelmaps与stuff_train2017.json,stuff_val2017_pixelmaps与stuff_val2017.json,panoptic_train2017与panoptic_train2017.json,panoptic_val2017与panoptic_val2017.json 和 unlabeled2017 以及 image_info_unlabeled2017.json。我的帖子解释了 ms coco。

cococaptions() 可以使用 ms coco 数据集,如下所示。 *这适用于带有captions_train2014.json、instances_train2014.json和person_keypoints_train2014.json的train2014,带有captions_val2014.json、instances_val2014.json和person_keypoints_val2014.json的val2014以及带有image_info_test2014.json、image_info_test2015.json和的test2017 image_info_test-dev2015.json:

*备忘录:

第一个参数是root(必需类型:str或pathlib.path):*备注:这是图像的路径。绝对或相对路径都是可能的。第二个参数是 annfile(必需类型:str 或 pathlib.path):*备注:这是注释的路径。 绝对或相对路径都是可能的。第三个参数是transform(optional-default:none-type:callable)。第四个参数是 target_transform(optional-default:none-type:callable)。第五个参数是transforms(optional-default:none-type:callable)。

from torchvision.datasets import CocoCaptionscap_train2014_data = CocoCaptions(    root="data/coco/imgs/train2014",    annFile="data/coco/anns/trainval2014/captions_train2014.json")cap_train2014_data = CocoCaptions(    root="data/coco/imgs/train2014",    annFile="data/coco/anns/trainval2014/captions_train2014.json",    transform=None,    target_transform=None,    transforms=None)ins_train2014_data = CocoCaptions(    root="data/coco/imgs/train2014",    annFile="data/coco/anns/trainval2014/instances_train2014.json")pk_train2014_data = CocoCaptions(    root="data/coco/imgs/train2014",    annFile="data/coco/anns/trainval2014/person_keypoints_train2014.json")len(cap_train2014_data), len(ins_train2014_data), len(pk_train2014_data)# (82783, 82783, 82783)cap_val2014_data = CocoCaptions(    root="data/coco/imgs/val2014",    annFile="data/coco/anns/trainval2014/captions_val2014.json")ins_val2014_data = CocoCaptions(    root="data/coco/imgs/val2014",    annFile="data/coco/anns/trainval2014/instances_val2014.json")pk_val2014_data = CocoCaptions(    root="data/coco/imgs/val2014",    annFile="data/coco/anns/trainval2014/person_keypoints_val2014.json")len(cap_val2014_data), len(ins_val2014_data), len(pk_val2014_data)# (40504, 40504, 40504)test2014_data = CocoCaptions(    root="data/coco/imgs/test2014",    annFile="data/coco/anns/test2014/image_info_test2014.json")test2015_data = CocoCaptions(    root="data/coco/imgs/test2015",    annFile="data/coco/anns/test2015/image_info_test2015.json")testdev2015_data = CocoCaptions(    root="data/coco/imgs/test2015",    annFile="data/coco/anns/test2015/image_info_test-dev2015.json")len(test2014_data), len(test2015_data), len(testdev2015_data)# (40775, 81434, 20288)cap_train2014_data# Dataset CocoCaptions#     Number of datapoints: 82783#     Root location: data/coco/imgs/train2014cap_train2014_data.root# 'data/coco/imgs/train2014'print(cap_train2014_data.transform)# Noneprint(cap_train2014_data.target_transform)# Noneprint(cap_train2014_data.transforms)# Nonecap_train2014_data.coco# cap_train2014_data[26]# (,#  ['three zeebras standing in a grassy field walking',#   'Three zebras are standing in an open field.',#   'Three zebra are walking through the grass of a field.',#   'Three zebras standing on a grassy dirt field.',#   'Three zebras grazing in green grass field area.'])cap_train2014_data[179]# (,#  ['a young guy walking in a forrest holding an object in his hand',#   'A partially black and white photo of a man throwing ... the woods.',#   'A disc golfer releases a throw from a dirt tee ... wooded course.',#   'The person is in the clearing of a wooded area. ',#   'a person throwing a frisbee at many trees '])cap_train2014_data[194]# (,#  ['A person on a court with a tennis racket.',#   'A man that is holding a racquet standing in the grass.',#   'A tennis player hits the ball during a match.',#   'The tennis player is poised to serve a ball.',#   'Man in white playing tennis on a court.'])ins_train2014_data[26] # Errorins_train2014_data[179] # Errorins_train2014_data[194] # Errorpk_train2014_data[26]# (, [])pk_train2014_data[179] # Errorpk_train2014_data[194] # Errorcap_val2014_data[26]# (,#  ['a close up of a child next to a cake with balloons',#   'A baby sitting in front of a cake wearing a tie.',#   'The young boy is dressed in a tie that matches his cake. ',#   'A child eating a birthday cake near some balloons.',#   'A baby eating a cake with a tie around ... the background.'])cap_val2014_data[179]# (,#  ['Many small children are posing together in the ... white photo. ',#   'A vintage school picture of grade school aged children.',#   'A black and white photo of a group of kids.',#   'A group of children standing next to each other.',#   'A group of children standing and sitting beside each other. '])cap_val2014_data[194]# (,#  ['A man hitting a tennis ball with a racquet.',#   'champion tennis player swats at the ball hoping to win',#   'A man is hitting his tennis ball with a recket on the court.',#   'a tennis player on a court with a racket',#   'A professional tennis player hits a ball as fans watch.'])ins_val2014_data[26] # Errorins_val2014_data[179] # Errorins_val2014_data[194] # Errorpk_val2014_data[26] # Errorpk_val2014_data[179] # Errorpk_val2014_data[194] # Errortest2014_data[26]# (, [])test2014_data[179]# (, [])test2014_data[194]# (, [])test2015_data[26]# (, [])test2015_data[179]# (, [])test2015_data[194]# (, [])testdev2015_data[26]# (, [])testdev2015_data[179]# (, [])testdev2015_data[194]# (, [])import matplotlib.pyplot as pltfrom matplotlib.patches import Polygon, Rectangleimport numpy as npfrom pycocotools import maskdef show_images(data, ims, main_title=None):    file = data.root.split('/')[-1]    fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(14, 8))    fig.suptitle(t=main_title, y=0.9, fontsize=14)    x_crd = 0.02    for i, axis in zip(ims, axes.ravel()):        if data[i][1]:            im, anns = data[i]            axis.imshow(X=im)            y_crd = 0.0            for j, ann in enumerate(iterable=anns):                text_list = ann.split()                if len(text_list) > 9:                    text = " ".join(text_list[0:10]) + " ..."                else:                    text = " ".join(text_list)                plt.figtext(x=x_crd, y=y_crd, fontsize=10,                            s=f'{j} : {text}')                y_crd -= 0.06            x_crd += 0.325            if i == 2 and file == "val2017":                x_crd += 0.06        elif not data[i][1]:            im, _ = data[i]            axis.imshow(X=im)    fig.tight_layout()    plt.show()ims = (26, 179, 194)show_images(data=cap_train2014_data, ims=ims,             main_title="cap_train2014_data")show_images(data=cap_val2014_data, ims=ims,              main_title="cap_val2014_data")show_images(data=test2014_data, ims=ims,             main_title="test2014_data")show_images(data=test2015_data, ims=ims,             main_title="test2015_data")show_images(data=testdev2015_data, ims=ims,             main_title="testdev2015_data")

image description

image description

image description

image description

image description

以上就是PyTorch 中的 CocoCaptions (1)的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1355485.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月13日 19:14:48
下一篇 2025年12月13日 19:15:00

相关推荐

  • AI 代理初学者教程

    AI 代理入门指南 概述 人工智能(AI)已彻底改变了我们的生活、工作和互动方式,成为现代科技的核心。AI 代理是AI领域的基础概念,赋予机器决策、解决问题和适应变化的能力。本教程将全面介绍AI代理,涵盖AI、机器学习和编程语言的基础知识,以及基于代理的建模和仿真。 什么是AI代理? AI代理是利用…

    2025年12月13日
    000
  • 了解 Python 中的正则表达式:一个实际示例

    简介 正则表达式(Regex或Regexp)是强大的模式匹配和文本处理工具,用于精确查找、匹配和操作字符串。本文通过一个Python客户验证函数的实际案例,演示正则表达式的应用。 背景 假设需要验证客户信息,特别是姓名和手机号码。以下Python代码片段使用正则表达式验证手机号码: 立即学习“Pyt…

    2025年12月13日
    000
  • 使用 Amazon Bedrock 构建个性化学习伴侣

    我现在正在攻读硕士学位,我一直想找到方法来减少每天的学习时间。瞧!这是我的解决方案:使用 amazon bedrock 创建一个学习伙伴。 我们将利用 amazon bedrock 来利用 gpt-4 或 t5 等基础模型 (fm) 的力量。 这些模型将帮助我们创建一个生成式人工智能,可以回答用户对…

    好文分享 2025年12月13日
    000
  • PyTorch 中的 CocoCaptions (2)

    请我喝杯咖啡☕ *备忘录: 我的帖子解释了cococaptions()使用带有captions_train2014.json、instances_train2014.json和person_keypoints_train2014.json的train2014、带有captions_val2014.j…

    2025年12月13日 好文分享
    000
  • 上传文件到 OpenAI:传递接力棒

    本文将指导您如何利用 OpenAI 文件 API 上传预处理好的 JSONL 文件,为后续模型微调做好准备,这就好比将整理好的邮件交给邮递员进行投递。 准备工作: 确保已安装 OpenAI Python 包:pip install openai获取您的 OpenAI API 密钥。 上传文件步骤 (…

    2025年12月13日
    000
  • PyTorch 中的 CocoDetection(2)

    请我喝杯咖啡☕ *我的帖子解释了 ms coco。 cocodetection() 可以使用 ms coco 数据集,如下所示。 *这适用于带有captions_train2017.json、instances_train2017.json和person_keypoints_train2017.js…

    2025年12月13日 好文分享
    000
  • PyTorch 中的 CocoDetection (1)

    请我喝杯咖啡☕ *备忘录: 我的帖子解释了cocodetection()使用train2017与captions_train2017.json,instances_train2017.json和person_keypoints_train2017.json,val2017与captions_val2…

    2025年12月13日 好文分享
    000
  • Hal创建并共享生成应用程序

    Hal9 (GitHub) 旨在简化基于LLM、扩散模型和其他AI模型的应用程序的创建、部署和共享。无论是构建聊天机器人、代理、API还是生成式应用,Hal9 都能最大限度地减少工程开销,让您专注于AI本身。 为什么选择Hal9? 许多生成式AI项目耗费大量时间在工程难题上——例如构建界面、集成工具…

    2025年12月13日
    000
  • 5 年内值得关注的令人兴奋的网络趋势

    未来五年,Web 开发将迎来激动人心的变革。以下十个关键趋势值得关注: WebGPU: WebGPU 将彻底改变浏览器图形和计算处理方式,提供对GPU的低级访问,从而实现高性能渲染、数据处理和机器学习应用。其灵活性远超WebGL,更接近Vulkan和DirectX 12等现代图形API。这将为浏览器…

    2025年12月13日
    000
  • 您的营销电子邮件最终会成为垃圾邮件吗?我们构建了一个工具来找出答案

    电子邮件营销的成功关键在于邮件送达收件箱而非垃圾邮件文件夹。本文将构建一个可验证邮件是否会被标记为垃圾邮件,并解释原因的工具。该工具将以api形式在线部署,方便集成到您的工作流程中。 垃圾邮件验证机制 Apache SpamAssassin是一个由Apache软件基金会维护的开源垃圾邮件检测平台,被…

    2025年12月13日
    000
  • 使用 Python 高效批量写入 DynamoDB:分步指南

    高效批量写入dynamodb的python指南 对于处理大量数据的应用程序而言,高效地将数据插入AWS DynamoDB至关重要。本指南将逐步演示一个Python脚本,实现以下功能: 检查DynamoDB表是否存在: 如果不存在则创建。生成随机测试数据: 用于模拟大规模数据插入。批量写入数据: 利用…

    2025年12月13日
    000
  • Python 中的交替异步生成器

    本文展示了一个 python 异步生成器 alternatinggenerator,它能够交替地从两个其他异步生成器中获取值。 该代码实现了异步迭代协议 (__aiter__ 和 __anext__),允许使用 async for 循环或手动调用 anext 来迭代结果。 alternatingge…

    2025年12月13日
    000
  • Python 入门:使用 Poetry 创建 Hello World 项目

    使用 Poetry 快速构建 Python Hello World 项目 Poetry 是一个功能强大的 Python 包管理和构建工具,它简化了项目创建、依赖管理和环境隔离等流程。本教程将引导您一步步使用 Poetry 创建一个简单的 “Hello, World!” Pyt…

    2025年12月13日
    000
  • 如何在云端运行Python

    本文将指导您如何在Amazon Web Services (AWS) 上创建虚拟机并运行Python脚本。 步骤一:启动EC2实例 登录AWS控制台: 访问AWS管理控制台,选择EC2服务。 启动新的EC2实例: 点击“启动实例”,选择Amazon机器镜像(AMI),例如Ubuntu Server。…

    2025年12月13日
    000
  • 5 年内即可学习的最佳开发堆栈

    技术日新月异,选择合适的工具和技术至关重要。无论您是新手还是资深开发者,掌握正确的技术栈都能开启无限职业可能。以下是2025年最值得学习的几大技术栈: 1. MERN 技术栈 (MongoDB、Express.js、React、Node.js) MERN 依然是全栈Web开发领域的热门选择,功能强大…

    2025年12月13日
    000
  • 如何解析计算机代码,代码的出现 ay 3

    探秘advent of code第三天的解析挑战:优雅地处理杂乱输入 最近重温Advent of Code第三天的挑战,它巧妙地提出了一个有趣的解析问题:从杂乱的输入中提取有效代码。这对于解析器和词法分析器开发来说是一次绝佳的练习。让我们一起探索解决这个问题的策略。 起初,我依赖hy进行解析。但最近…

    2025年12月13日
    000
  • 使用 HTMX 和 Django 创建待办事项应用程序,部分无限滚动

    本教程是学习使用 django 和 htmx 实现无限滚动的第七部分。我们将遵循 htmx 文档,逐步实现待办事项列表的无限滚动功能。完整系列教程可在 dev.to/rodbv 查看。 更新部分模板以支持多项目加载 实现无限滚动需要一次返回多个待办事项(项目的下一页),并将其加载到现有部分模板中。这…

    2025年12月13日 好文分享
    000
  • 提交微调工作:组织劳动力

    高效利用OpenAI进行模型微调:纪律与协调 为了高效地完成模型微调任务,我们需要遵循严格的流程,并充分利用OpenAI提供的工具。本文将详细介绍如何创建和管理OpenAI的微调作业,确保模型能够从精心准备的数据集中学习。 使用OpenAI进行微调 创建微调作业使用client.fine_tunin…

    2025年12月13日
    000
  • Python 教程 – 函数

    python函数详解:提升代码效率和可读性的利器 函数是Python中组织代码、减少冗余的强大工具。它们是可复用的代码块,能够执行特定任务。Python函数分为两种:无返回值函数(void函数)和有返回值函数。 基本函数结构: def function_name(arguments): “””函数文…

    2025年12月13日
    000
  • 使用 Django 和 HTMX 创建待办事项应用程序 – 创建前端并添加 HTMX 部分

    本系列文章的第三部分带您深入学习如何结合 htmx 和 django 构建动态待办事项列表。如果您错过了前两部分,建议先阅读。 模板和视图的创建 我们将创建一个基础模板和一个指向索引视图的索引模板,该视图列出数据库中的待办事项。我们将使用 DaisyUI(Tailwind CSS 的扩展)来美化界面…

    2025年12月13日 好文分享
    000

发表回复

登录后才能评论
关注微信