PyTorch 中的 CocoCaptions (1)

wufei123 2025-01-26 阅读:13 评论:0
请我喝杯咖啡☕ *备忘录: 我的帖子解释了cocodetection()使用带有captions_train2014.json、instances_train2014.json和person_keypoints_train2014....

请我喝杯咖啡☕

*备忘录:

  • 我的帖子解释了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 CocoCaptions

cap_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/train2014

cap_train2014_data.root
# 'data/coco/imgs/train2014'

print(cap_train2014_data.transform)
# None

print(cap_train2014_data.target_transform)
# None

print(cap_train2014_data.transforms)
# None

cap_train2014_data.coco
# <pycocotools.coco.COCO at 0x759028ee1d00>

cap_train2014_data[26]
# (<PIL.Image.Image image mode=RGB size=427x640>,
#  ['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]
# (<PIL.Image.Image image mode=RGB size=480x640>,
#  ['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]
# (<PIL.Image.Image image mode=RGB size=428x640>,
#  ['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] # Error

ins_train2014_data[179] # Error

ins_train2014_data[194] # Error

pk_train2014_data[26]
# (<PIL.Image.Image image mode=RGB size=427x640>, [])

pk_train2014_data[179] # Error

pk_train2014_data[194] # Error

cap_val2014_data[26]
# (<PIL.Image.Image image mode=RGB size=640x360>,
#  ['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]
# (<PIL.Image.Image image mode=RGB size=500x302>,
#  ['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]
# (<PIL.Image.Image image mode=RGB size=640x427>,
#  ['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] # Error

ins_val2014_data[179] # Error

ins_val2014_data[194] # Error

pk_val2014_data[26] # Error

pk_val2014_data[179] # Error

pk_val2014_data[194] # Error

test2014_data[26]
# (<PIL.Image.Image image mode=RGB size=640x640>, [])

test2014_data[179]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

test2014_data[194]
# (<PIL.Image.Image image mode=RGB size=640x360>, [])

test2015_data[26]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

test2015_data[179]
# (<PIL.Image.Image image mode=RGB size=640x426>, [])

test2015_data[194]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

testdev2015_data[26]
# (<PIL.Image.Image image mode=RGB size=640x360>, [])

testdev2015_data[179]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

testdev2015_data[194]
# (<PIL.Image.Image image mode=RGB size=640x480>, [])

import matplotlib.pyplot as plt
from matplotlib.patches import Polygon, Rectangle
import numpy as np
from pycocotools import mask

def 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)的详细内容,更多请关注知识资源分享宝库其它相关文章!

版权声明

本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com

分享:

扫一扫在手机阅读、分享本文

发表评论
热门文章
  • 闪耀暖暖靡城永恒怎么样-闪耀暖暖靡城永恒套装介绍(闪耀.暖暖.套装.介绍.....)

    闪耀暖暖靡城永恒怎么样-闪耀暖暖靡城永恒套装介绍(闪耀.暖暖.套装.介绍.....)
    闪耀暖暖钻石竞技场第十七赛季“华梦泡影”即将开启!全新闪耀性感套装【靡城永恒】震撼来袭!想知道如何获得这套精美套装吗?快来看看吧! 【靡城永恒】套装设计理念抢先看: 设计灵感源于夜色中的孤星,象征着淡然、漠视一切的灰色瞳眸。设计师希望通过这套服装,展现出在虚幻与真实交织的夜幕下,一种独特的魅力。 服装细节考究,从面料的光泽、鞋跟声响到裙摆的弧度,都力求完美还原设计初衷。 【靡城永恒】套装设计亮点: 闪耀的绸缎与金丝交织,轻盈的羽毛增添华贵感。 这套服装仿佛是从无尽的黑...
  • BioWare埃德蒙顿工作室面临关闭危机,龙腾世纪制作总监辞职引关注(龙腾.总监.辞职.危机.面临.....)

    BioWare埃德蒙顿工作室面临关闭危机,龙腾世纪制作总监辞职引关注(龙腾.总监.辞职.危机.面临.....)
    知名变性人制作总监corrine busche离职bioware,引发业界震荡!外媒“smash jt”独家报道称,《龙腾世纪:影幢守护者》制作总监corrine busche已离开bioware,此举不仅引发了关于个人职业发展方向的讨论,更因其可能预示着bioware埃德蒙顿工作室即将关闭而备受关注。本文将深入分析busche离职的原因及其对bioware及游戏行业的影响。 Busche的告别信:挑战与感激并存 据“Smash JT”获得的内部邮件显示,Busche离职原...
  • 奇迹暖暖诸星梦眠怎么样-奇迹暖暖诸星梦眠套装介绍(星梦.暖暖.奇迹.套装.介绍.....)

    奇迹暖暖诸星梦眠怎么样-奇迹暖暖诸星梦眠套装介绍(星梦.暖暖.奇迹.套装.介绍.....)
    奇迹暖暖全新活动“失序之圜”即将开启,参与活动即可获得精美套装——诸星梦眠!想知道这套套装的细节吗?一起来看看吧! 奇迹暖暖诸星梦眠套装详解 “失序之圜”活动主打套装——诸星梦眠,高清海报震撼公开!少女在无垠梦境中,接受星辰的邀请,馥郁芬芳,预示着命运之花即将绽放。 诸星梦眠套装包含:全新妆容“隽永之梦”、星光面饰“熠烁星光”、动态特姿连衣裙“诸星梦眠”、动态特姿发型“金色绮想”、精美特效皇冠“繁星加冕”,以及动态摆件“芳馨酣眠”、“沉云余音”、“流星低语”、“葳蕤诗篇”。...
  • 斗魔骑士哪个角色强势-斗魔骑士角色推荐与实力解析(骑士.角色.强势.解析.实力.....)

    斗魔骑士哪个角色强势-斗魔骑士角色推荐与实力解析(骑士.角色.强势.解析.实力.....)
    斗魔骑士角色选择及战斗策略指南 斗魔骑士游戏中,众多角色各具特色,选择适合自己的角色才能在战斗中占据优势。本文将为您详细解读如何选择强力角色,并提供团队协作及角色培养策略。 如何选择强力角色? 斗魔骑士的角色大致分为近战和远程两种类型。近战角色通常拥有高攻击力和防御力,适合冲锋陷阵;远程角色则擅长后方输出,并依靠灵活走位躲避攻击。 选择角色时,需根据个人游戏风格和喜好决定。喜欢正面硬刚的玩家可以选择战士型角色,其高生命值和防御力能承受更多伤害;偏好策略性玩法的玩家则可以选择法...
  • 龙族卡塞尔之门昂热角色详解-龙族卡塞尔之门昂热全面介绍(之门.龙族.卡塞尔.详解.角色.....)

    龙族卡塞尔之门昂热角色详解-龙族卡塞尔之门昂热全面介绍(之门.龙族.卡塞尔.详解.角色.....)
    龙族卡塞尔之门:昂热角色深度解析 在策略手游《龙族卡塞尔之门》中,卡塞尔学院校长昂热凭借其传奇背景和强大技能,成为玩家们竞相选择的热门角色。作为初代狮心会的最后一人,他拥有超过130岁的阅历,沉稳成熟的外表下,藏着一颗爽朗豁达的心。游戏中,昂热不仅具备出色的单体输出,更擅长通过控制和辅助技能,为团队创造优势。 技能机制详解 昂热的技能组合灵活多变,包含普通攻击、言灵·时零以及随星级提升解锁的被动技能。虽然普通攻击仅针对单体目标,但言灵·时零却能对全体敌人造成物理伤害,并有几率...