【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用

这篇具有很好参考价值的文章主要介绍了【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用

作者:安静到无声 个人主页

数据加载程序示意图

【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用,手把手实现Image captioning,人工智能

使用方法

示例代码

#%%

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.tensorboard import SummaryWriter



import numpy as np

import time
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0' ##from six.moves import cPickle
import traceback
from collections import defaultdict

import captioning.utils.opts as opts
import captioning.models as models
from captioning.data.dataloader import *
import skimage.io
import captioning.utils.eval_utils as eval_utils
import captioning.utils.misc as utils
from captioning.utils.rewards import init_scorer, get_self_critical_reward
from captioning.modules.loss_wrapper import LossWrapper

import sys
sys.path.append("..")
import time
#%%


opt = opts.parse_opt()
opt.input_json = '/home/lihuanyu/code/07ImageCaptioning/data/cocotalk.json'
opt.input_label_h5 = '/home/lihuanyu/code/07ImageCaptioning/data/cocotalk_label.h5'
opt.input_fc_dir = '/home/lihuanyu/code/07ImageCaptioning/data/cocotalk_fc'
opt.input_att_dir = '/home/lihuanyu/code/07ImageCaptioning/data/cocotalk_att'
opt.batch_size = 1
opt.train_only = 1

opt.use_att = True
opt.use_att = True
opt.use_box = 0

#%%
print(opt.input_json)
print(opt.batch_size)  #批量化为16
loader = DataLoader(opt)  # 数据加载
#打印字内容
#print(loader.get_vocab())  #返回字典
for i in range(2):
    data = loader.get_batch('train')
    print('———————————————————※输入的信息特征※——————————————————')  #[1,2048] 全连接特征
    print('全连接特征【fc_feats】的形状:', data['fc_feats'].shape)  #[1,2048] 全连接特征
    print('全连接特征【att_feats】的形状:', data['att_feats'].shape)  #[1,2048] 注意力特征
    print('att_masks', data['att_masks'])
    print('含有的信息infos:', data['infos'])  #infos [{'ix': 117986, 'id': 495956, 'file_path': 'train2014/COCO_train2014_000000495956.jpg'}]
    print('———————————————————※标签信息※——————————————————')  #[1,2048] 全连接特征
    print('labels', data['labels'])     #添加了一些0
    print('gts:', data['gts'])          #没有添加的原始句子
    print('masks', data['masks'])
    print('———————————————————※记录遍历的位置※——————————————————')  #[1,2048] 全连接特征
    print('bounds', data['bounds'])
    time.sleep(1)
    print(data.keys())

输出结果:

Hugginface transformers not installed; please visit https://github.com/huggingface/transformers
meshed-memory-transformer not installed; please run `pip install git+https://github.com/ruotianluo/meshed-memory-transformer.git`
Warning: coco-caption not available
cider or coco-caption missing
/home/lihuanyu/code/07ImageCaptioning/data/cocotalk.json
1
是否使用【注意力特征[use_fc]: True
是否使用【注意力特征[use_att]: True
是否在注意力特征中使用【检测框特征[use_box]: 0
DataLoader loading json file:  /home/lihuanyu/code/07ImageCaptioning/data/cocotalk.json
vocab size is  9487
DataLoader loading h5 file:  /home/lihuanyu/code/07ImageCaptioning/data/cocotalk_fc /home/lihuanyu/code/07ImageCaptioning/data/cocotalk_att data/cocotalk_box /home/lihuanyu/code/07ImageCaptioning/data/cocotalk_label.h5
max sequence length in data is 16
read 123287 image features
assigned 82783 images to split train(训练集有多少图片)
assigned 5000 images to split val(验证集有多少图片)
assigned 5000 images to split test(测试集有多少图片)
———————————————————※输入的信息特征※——————————————————
全连接特征【fc_feats】的形状: torch.Size([1, 2048])
全连接特征【att_feats】的形状: torch.Size([1, 196, 2048])
att_masks None
含有的信息infos: [{'ix': 60494, 'id': 46065, 'file_path': 'train2014/COCO_train2014_000000046065.jpg'}]
———————————————————※标签信息※——————————————————
labels tensor([[[   0,    1,  271,   17, 7068,   35,   98,    6,    1,  102,    3,
           912,    0,    0,    0,    0,    0,    0],
         [   0,  995, 2309, 2308,  609,    6,    1,  271,  119,  912,    0,
             0,    0,    0,    0,    0,    0,    0],
         [   0, 2309, 9487,  179,   98,    6,    1,   46,  271,    0,    0,
             0,    0,    0,    0,    0,    0,    0],
         [   0,  182,   35,  995, 7068,    6,    1,  271,    3,   60,  678,
            32,   14,   29,    0,    0,    0,    0],
         [   0,  995,  915,   17, 2309, 3130,    6,    1,   46,  271,    0,
             0,    0,    0,    0,    0,    0,    0]]])
gts: [array([[   1,  271,   17, 7068,   35,   98,    6,    1,  102,    3,  912,
           0,    0,    0,    0,    0],
       [ 995, 2309, 2308,  609,    6,    1,  271,  119,  912,    0,    0,
           0,    0,    0,    0,    0],
       [2309, 9487,  179,   98,    6,    1,   46,  271,    0,    0,    0,
           0,    0,    0,    0,    0],
       [ 182,   35,  995, 7068,    6,    1,  271,    3,   60,  678,   32,
          14,   29,    0,    0,    0],
       [ 995,  915,   17, 2309, 3130,    6,    1,   46,  271,    0,    0,
           0,    0,    0,    0,    0]], dtype=uint32)]
masks tensor([[[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,
          0.]]])
———————————————————※记录遍历的位置※——————————————————
bounds {'it_pos_now': 1, 'it_max': 82783, 'wrapped': False}
dict_keys(['fc_feats', 'att_feats', 'att_masks', 'labels', 'masks', 'gts', 'bounds', 'infos'])
———————————————————※输入的信息特征※——————————————————
全连接特征【fc_feats】的形状: torch.Size([1, 2048])
全连接特征【att_feats】的形状: torch.Size([1, 196, 2048])
att_masks None
含有的信息infos: [{'ix': 106440, 'id': 151264, 'file_path': 'train2014/COCO_train2014_000000151264.jpg'}]
———————————————————※标签信息※——————————————————
labels tensor([[[   0,    1,  230,    6,   14,  230,  237,   32, 1086,  627,    0,
             0,    0,    0,    0,    0,    0,    0],
         [   0,    1, 6035,  230,   35,  274,  127,  225, 1598,  335,    1,
           940,    0,    0,    0,    0,    0,    0],
         [   0,    1,  230,   35,  900,   32,  307,  756,   61,  607,    0,
             0,    0,    0,    0,    0,    0,    0],
         [   0,    1,  230,   35,   98,   79,    1,  230,  224,    0,    0,
             0,    0,    0,    0,    0,    0,    0],
         [   0,    1,   46, 1109,  230, 1596,  245,    1,  224,    0,    0,
             0,    0,    0,    0,    0,    0,    0]]])
gts: [array([[   1,  230,    6,   14,  230,  237,   32, 1086,  627,    0,    0,
           0,    0,    0,    0,    0],
       [   1, 6035,  230,   35,  274,  127,  225, 1598,  335,    1,  940,
           0,    0,    0,    0,    0],
       [   1,  230,   35,  900,   32,  307,  756,   61,  607,    0,    0,
           0,    0,    0,    0,    0],
       [   1,  230,   35,   98,   79,    1,  230,  224,    0,    0,    0,
           0,    0,    0,    0,    0],
       [   1,   46, 1109,  230, 1596,  245,    1,  224,    0,    0,    0,
           0,    0,    0,    0,    0]], dtype=uint32)]
masks tensor([[[1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0.,
          0.],
         [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0.,
          0.]]])
———————————————————※记录遍历的位置※——————————————————
bounds {'it_pos_now': 2, 'it_max': 82783, 'wrapped': False}
dict_keys(['fc_feats', 'att_feats', 'att_masks', 'labels', 'masks', 'gts', 'bounds', 'infos'])

推荐专栏

🔥 手把手实现Image captioning

💯CNN模型压缩

💖模式识别与人工智能(程序与算法)

🔥FPGA—Verilog与Hls学习与实践

💯基于Pytorch的自然语言处理入门与实践文章来源地址https://www.toymoban.com/news/detail-641650.html

到了这里,关于【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【论文阅读】(DALLE-3)Improving Image Generation with Better Captions

    引用: Betker J, Goh G, Jing L, et al. Improving image generation with better captions[J]. Computer Science. https://cdn. openai. com/papers/dall-e-3. pdf, 2023, 2(3): 8. 论文链接: https://arxiv.org/abs/2212.09748 论文展示了 通过在高度描述性的生成图像captions上训练,可以显著提高文本到图像模型的提示跟随能力 。

    2024年03月12日
    浏览(36)
  • cs231n assignment 3 Q2 Image Captioning with Vanilla RNNs

    image_from_url 里的报错 问题展示 我在运行这段代码的时候就报错了 另一个进程正在使用此文件,文件无法访问 问题解决思路 我一开始以为是img = imread(fname) 里的问题导致文件还在被占用,所以无法释放文件的所有权,导致os.remove(fname)无法删除。 就是我以为img = imread(fname) 是

    2024年02月12日
    浏览(29)
  • cs231n assignmen3 Extra Credit: Image Captioning with LSTMs

    题面 结合课程和上面的讲解,这部分就是让我们来实现lstm的前向操作,具体的操作流程在上面都写好了 解析 看代码注释吧 代码 输出 题面 计算lstm的反向操作 解析 sigmoid求导 Tanh 求导 反向传播讲解可以看这个 然后结合代码注释,想想链式求导法则就好了 代码 输出 题面 让

    2024年02月10日
    浏览(23)
  • 【深度强化学习】(4) Actor-Critic 模型解析,附Pytorch完整代码

    大家好,今天和各位分享一下深度强化学习中的 Actor-Critic 演员评论家算法, Actor-Critic 算法是一种综合了策略迭代和价值迭代的集成算法 。我将使用该模型结合 OpenAI 中的 Gym 环境完成一个小游戏,完整代码可以从我的 GitHub 中获得: https://github.com/LiSir-HIT/Reinforcement-Learning

    2024年02月03日
    浏览(33)
  • Actor-Critic(A2C)算法 原理讲解+pytorch程序实现

    强化学习在人工智能领域中具有广泛的应用,它可以通过与环境互动来学习如何做出最佳决策。本文将介绍一种常用的强化学习算法:Actor-Critic并且附上基于pytorch实现的代码。 Actor-Critic算法是一种基于策略梯度(Policy Gradient)和价值函数(Value Function)的强化学习方法,通常

    2024年02月11日
    浏览(34)
  • Self-supervised 3D Human Pose Estimation from a Single Image

    基于单幅图像的自监督三维人体姿态估计   主页: https://josesosajs.github.io/ imagepose/ 源码:未开源 我们提出了一种新的自我监督的方法预测三维人体姿势从一个单一的图像。预测网络是从描绘处于典型姿势的人的未标记图像的数据集和一组未配对的2D姿势训练的。通过最小化

    2024年02月10日
    浏览(37)
  • 【论文阅读】Self-supervised Image-specific Prototype Exploration for WSSS

    一篇CVPR2022上的论文,用于弱监督分割 Self-supervised Image-specific Prototype Exploration for Weakly Supervised Semantic Segmentation https://github.com/chenqi1126/SIPE https://openaccess.thecvf.com/content/CVPR2022/papers/Chen_Self-Supervised_Image-Specific_Prototype_Exploration_for_Weakly_Supervised_Semantic_Segmentation_CVPR_2022_paper.pdf 现

    2024年02月11日
    浏览(29)
  • 自监督去噪: self2self 原理及实现(Pytorch)

    文章地址:https://ieeexplore.ieee.org/document/9157420 原始代码:https://github.com/scut-mingqinchen/self2self 本文参考代码: https://github.com/JinYize/self2self_pytorch 本文参考博客: https://zhuanlan.zhihu.com/p/361472663 website:https://csyhquan.github.io/ 1. 原理简介 噪声图片 y 可以表示为 干净图片 x 和噪声 n的叠

    2024年02月15日
    浏览(27)
  • 论文阅读:Image-to-Lidar Self-Supervised Distillation for Autonomous Driving Data

    目录 摘要 Motivation 整体架构流程 技术细节 雷达和图像数据的同步 小结 论文地址:  [2203.16258] Image-to-Lidar Self-Supervised Distillation for Autonomous Driving Data (arxiv.org) 论文代码: GitHub - valeoai/SLidR: Official PyTorch implementation of \\\"Image-to-Lidar Self-Supervised Distillation for Autonomous Driving Data\\\"    

    2024年02月08日
    浏览(38)
  • Low-Light Image Enhancement via Self-Reinforced Retinex Projection Model 论文阅读笔记

    这是马龙博士2022年在TMM期刊发表的基于改进的retinex方法去做暗图增强(非深度学习)的一篇论文 文章用一张图展示了其动机,第一行是估计的亮度层,第二列是通常的retinex方法会对估计的亮度层进行RTV约束优化,从而产生平滑的亮度层,然后原图除以亮度层产生照度层作为

    2024年02月16日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包