PyTorch 中的 CocoCaptions (2)

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

请我喝杯咖啡☕

*备忘录:

  • 我的帖子解释了cococaptions()使用带有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()使用带有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_train2017.json、instances_train2017.json和person_keypoints_train2017.json的train2017,带有captions_val2017.json、instances_val2017.json和person_keypoints_val2017.json的val2017以及带有image_info_test2017.json和的test2017 image_info_test-dev2017.json:

from torchvision.datasets import CocoCaptions

cap_train2017_data = CocoCaptions(
    root="data/coco/imgs/train2017",
    annFile="data/coco/anns/trainval2017/captions_train2017.json"
)

ins_train2017_data = CocoCaptions(
    root="data/coco/imgs/train2017",
    annFile="data/coco/anns/trainval2017/instances_train2017.json"
)

pk_train2017_data = CocoCaptions(
    root="data/coco/imgs/train2017",
    annFile="data/coco/anns/trainval2017/person_keypoints_train2017.json"
)

len(cap_train2017_data), len(ins_train2017_data), len(pk_train2017_data)
# (118287, 118287, 118287)

cap_val2017_data = CocoCaptions(
    root="data/coco/imgs/val2017",
    annFile="data/coco/anns/trainval2017/captions_val2017.json"
)

ins_val2017_data = CocoCaptions(
    root="data/coco/imgs/val2017",
    annFile="data/coco/anns/trainval2017/instances_val2017.json"
)

pk_val2017_data = CocoCaptions(
    root="data/coco/imgs/val2017",
    annFile="data/coco/anns/trainval2017/person_keypoints_val2017.json"
)

len(cap_val2017_data), len(ins_val2017_data), len(pk_val2017_data)
# (5000, 5000, 5000)

test2017_data = CocoCaptions(
    root="data/coco/imgs/test2017",
    annFile="data/coco/anns/test2017/image_info_test2017.json"
)

testdev2017_data = CocoCaptions(
    root="data/coco/imgs/test2017",
    annFile="data/coco/anns/test2017/image_info_test-dev2017.json"
)

len(test2017_data), len(testdev2017_data)
# (40670, 20288)

cap_train2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x428>,
#  ['A flower vase is sitting on a porch stand.',
#   'White vase with different colored flowers sitting inside of it. ',
#   'a white vase with many flowers on a stage',
#   'A white vase filled with different colored flowers.',
#   'A vase with red and white flowers outside on a sunny day.'])

cap_train2017_data[47]
# (<PIL.Image.Image image mode=RGB size=640x427>,
#  ['A man standing in front of a microwave next to pots and pans.',
#   'A man displaying pots and utensils on a wall.',
#   'A man stands in a kitchen and motions towards pots and pans. ',
#   'a man poses in front of some pots and pans ',
#   'A man pointing to pots hanging from a pegboard on a gray wall.'])

cap_train2017_data[64]
# (<PIL.Image.Image image mode=RGB size=480x640>,
#  ['A little girl holding wet broccoli in her hand. ',
#   'The young child is happily holding a fresh vegetable. ',
#   'A little girl holds a hand full of wet broccoli. ',
#   'A little girl holds a piece of broccoli towards the camera.',
#   'a small kid holds on to some vegetables '])

ins_train2017_data[2] # Error

ins_train2017_data[47] # Error

ins_train2017_data[67] # Error

pk_train2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x428>, [])

pk_train2017_data[47] # Error

pk_train2017_data[64] # Error

cap_val2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x483>,
#  ['Bedroom scene with a bookcase, blue comforter and window.',
#   'A bedroom with a bookshelf full of books.',
#   'This room has a bed with blue sheets and a large bookcase',
#   'A bed and a mirror in a small room.',
#   'a bed room with a neatly made bed a window and a book shelf'])

cap_val2017_data[47]
# (<PIL.Image.Image image mode=RGB size=640x480>,
#  ['A group of people cutting a ribbon on a street.',
#   'A man uses a pair of big scissors to cut a pink ribbon.',
#   'A man cutting a ribbon at a ceremony ',
#   'A group of people on the sidewalk watching two young children.',
#   'A group of people holding a large pair of scissors to a ribbon.'])

cap_val2017_data[64]
# (<PIL.Image.Image image mode=RGB size=375x500>,
#  ['A man and a women posing next to one another in front of a table.',
#   'A man and woman hugging in a restaurant',
#   'A man and woman standing next to a table.',
#   'A happy man and woman pose for a picture.',
#   'A man and woman posing for a picture in a sports bar.'])

ins_val2017_data[2] # Error

ins_val2017_data[47] # Error

ins_val2017_data[64] # Error

pk_val2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x483>, [])

pk_val2017_data[47] # Error

pk_val2017_data[64] # Error

test2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x427>, [])

test2017_data[47]
# (<PIL.Image.Image image mode=RGB size=640x406>, [])

test2017_data[64]
# (<PIL.Image.Image image mode=RGB size=640x427>, [])

testdev2017_data[2]
# (<PIL.Image.Image image mode=RGB size=640x427>, [])

testdev2017_data[47]
# (<PIL.Image.Image image mode=RGB size=480x640>, [])

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

import matplotlib.pyplot as plt

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 = (2, 47, 64)

show_images(data=cap_train2017_data, ims=ims,
             main_title="cap_train2017_data")
show_images(data=cap_val2017_data, ims=ims, 
             main_title="cap_val2017_data")
show_images(data=test2017_data, ims=ims,
            main_title="test2017_data")
show_images(data=testdev2017_data, ims=ims, 
            main_title="testdev2017_data")

image description

image description

image description

image description

以上就是PyTorch 中的 CocoCaptions (2)的详细内容,更多请关注知识资源分享宝库其它相关文章!

版权声明

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

分享:

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

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

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

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

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

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

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