【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用
【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用
作者:安静到无声 个人主页
数据加载程序示意图

使用方法
示例代码
#%%from __future__ import absolute_import
from __future__ import division
from __future__ import print_functionimport torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.tensorboard import SummaryWriterimport numpy as npimport time
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0' ##from six.moves import cPickle
import traceback
from collections import defaultdictimport 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 LossWrapperimport 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 = 1opt.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']) #添加了一些0print('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的自然语言处理入门与实践

相关文章:
【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用
【Image captioning】ruotianluo/self-critical.pytorch之1—数据集的加载与使用 作者:安静到无声 个人主页 数据加载程序示意图 使用方法 示例代码 #%%from __future__ import absolute_import from __future__ import division from __future__ import print_…...
研发工程师玩转Kubernetes——就绪探针(Readiness Probe)和服务(Service)
在《研发工程师玩转Kubernetes——启动、存活和就绪探针》中,我们讲了就绪探针和服务之间的特殊关系。就绪探针检测失败并不代表整个程序处于“非存活”状态,可能只是短暂临时的不可以提供服务,比如CPU阶段性占满,导致就绪探针检测…...
最新Kali Linux安装教程:从零开始打造网络安全之旅
Kali Linux,全称为Kali Linux Distribution,是一个操作系统(2013-03-13诞生),是一款基于Debian的Linux发行版,基于包含了约600个安全工具,省去了繁琐的安装、编译、配置、更新步骤,为所有工具运行提供了一个…...
excel填数据转json格式
定制化比较严重,按需更改 excel文件如下 代码 # -*- coding: utf-8 -*- import oss2 import shutil import sys import xlwt import xlrd import json from datetime import datetime, timedeltafile1 "C:\\Users\\cxy\\Desktop\\generate.xls" #打开表…...
解决echarts和v-show一起使用canvas宽高改变
本来是想没有数据显示暂无数据的,结果显示成了这样 1.把V-show改成v-if <template><divclass"chart1"ref"chart1"v-if"!nodata"style"width: 100%; height: 100%"></div><el-empty description&quo…...
typescript 中的数据类型有哪些?
目录 1. 介绍2.总结 话不多说 直接开冲 干干干! 1. 介绍 typescript 的数据类型主要有如下: boolean(布尔类型)number(数字类型)string(字符串类型)array(数组类型&…...
RabbitMQ-消息中间件学习记录(what-how-why)
什么是消息中间件 简单的来说就是消息队列中间件,生产者发送消息到中间件,消息中间件用于保存消息并发送消息到消费者。 消息中间件RabbitMQ的基本组件 1)producer -生产者 2)customer -消费者 3)broker (经纪人)- MQ…...
前端HTML进阶
day02:列表、表格、表单 目标:掌握嵌套关系标签的写法,使用列表标签布局网页 01-列表 作用:布局内容排列整齐的区域。 列表分类:无序列表、有序列表、定义列表。 无序列表 作用:布局排列整齐的不需要规…...
Python“牵手”lazada商品详情页数据采集方法,lazadaAPI接口申请指南
lazada详情接口 API 是开放平台提供的一种 API 接口,它可以帮助开发者获取商品的详细信息,包括商品的标题、描述、图片等信息。在电商平台的开发中,详情接口API是非常常用的 API,因此本文将详细介绍详情接口 API 的使用。 一、la…...
买机票系统---(java实现)
/* * 案例 * 卖机票 * 需求:机票价格按照淡季和旺季,头等舱和经济舱收费,输入机票原价,月份和头等舱或经济舱 * 旺季(5-10月):头等舱9折,经济舱8.5折 * 淡季(11-来年4月&…...
“new出对象“原理的深层解密
🎈个人主页:🎈 :✨✨✨初阶牛✨✨✨ 🐻推荐专栏1: 🍔🍟🌯C语言初阶 🐻推荐专栏2: 🍔🍟🌯C语言进阶 🔑个人信条: 🌵知行合一 …...
Java基础篇--SecureRandom(安全随机)类
java.security.SecureRandom类是Java中用于生成安全的随机数的一个类。与普通的Random类不同,它提供了一种可信赖的随机数生成器,用于生成具有高度随机性的随机数。 SecureRandom类的实例使用了更加安全的随机数生成算法,这些算法通常经过密…...
论文复现--关于多视角动作捕捉工具箱 --XRMoCap的研究
分类:动作捕捉 github地址:https://github.com/openxrlab/xrmocap 所需环境: Ubuntu18.04,conda22.9.0,CUDA11.4 目录 环境配置 环境配置 conda create -n XRmocap python3.7 -y conda activate XRmocap# install ffm…...
Spring Profile与PropertyPlaceholderConfigurer实现项目多环境配置切换
最近考虑项目在不同环境下配置的切换,使用profile注解搭配PropertyPlaceholderConfigurer实现对配置文件的切换,简单写了个demo记录下实现。 基本知识介绍 Profile Profile通过对bean进行修饰,来限定spring在bean管理时的初始化情况&#…...
ansible入门
ansible入门 一.ansible 背景介绍 Ansible 是一个广受欢迎的 IT 自动化系统。可以用来处理配置管理、应用自动化部署、云资源配给、网络 自动化和多借点部署等任务。其也可以使得复杂的变更如带负载均衡的零停机滚动更新更加容易。Ansible.com 1.1 自动化运维概念 1.1.1 运维…...
用Node.js吭哧吭哧撸一个运动主页
简单唠唠 某乎问题:人这一生,应该养成哪些好习惯? 问题链接:https://www.zhihu.com/question/460674063 如果我来回答肯定会有定期运动的字眼。 平日里也有煅练的习惯,时间久了后一直想把运动数据公开,…...
【C++】STL---vector
STL---vector 一、vector 的介绍二、vector 的模拟实现1. 容量相关的接口(1)size(2)capacity(3)reserve(4)resize(5)empty 2. [] 重载3. 迭代器4. 修改数据相…...
机器学习:基本介绍
机器学习介绍 Hnad-crafted rules Hand-crafted rules,叫做人设定的规则。那假设今天要设计一个机器人,可以帮忙打开或关掉音乐,那做法可能是这样: 设立一条规则,就是写一段程序。如果输入的句子里面看到**“turn of…...
基于长短期神经网络LSTM的碳排量预测,基于LSTM的碳排放量预测
目录 背影 摘要 LSTM的基本定义 LSTM实现的步骤 基于长短期神经网络LSTM的碳排放量预测 完整代码: 基于长短期神经网络LSTM的碳排放量预测,基于LSTM的碳排放量预测资源-CSDN文库 https://download.csdn.net/download/abc991835105/88184632 效果图 结果分析 展望 参考论文 背…...
超短脉冲激光自聚焦效应
前言与目录 强激光引起自聚焦效应机理 超短脉冲激光在脆性材料内部加工时引起的自聚焦效应,这是一种非线性光学现象,主要涉及光学克尔效应和材料的非线性光学特性。 自聚焦效应可以产生局部的强光场,对材料产生非线性响应,可能…...
【杂谈】-递归进化:人工智能的自我改进与监管挑战
递归进化:人工智能的自我改进与监管挑战 文章目录 递归进化:人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管?3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...
<6>-MySQL表的增删查改
目录 一,create(创建表) 二,retrieve(查询表) 1,select列 2,where条件 三,update(更新表) 四,delete(删除表…...
线程与协程
1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指:像函数调用/返回一样轻量地完成任务切换。 举例说明: 当你在程序中写一个函数调用: funcA() 然后 funcA 执行完后返回&…...
蓝桥杯 2024 15届国赛 A组 儿童节快乐
P10576 [蓝桥杯 2024 国 A] 儿童节快乐 题目描述 五彩斑斓的气球在蓝天下悠然飘荡,轻快的音乐在耳边持续回荡,小朋友们手牵着手一同畅快欢笑。在这样一片安乐祥和的氛围下,六一来了。 今天是六一儿童节,小蓝老师为了让大家在节…...
Java多线程实现之Thread类深度解析
Java多线程实现之Thread类深度解析 一、多线程基础概念1.1 什么是线程1.2 多线程的优势1.3 Java多线程模型 二、Thread类的基本结构与构造函数2.1 Thread类的继承关系2.2 构造函数 三、创建和启动线程3.1 继承Thread类创建线程3.2 实现Runnable接口创建线程 四、Thread类的核心…...
算法:模拟
1.替换所有的问号 1576. 替换所有的问号 - 力扣(LeetCode) 遍历字符串:通过外层循环逐一检查每个字符。遇到 ? 时处理: 内层循环遍历小写字母(a 到 z)。对每个字母检查是否满足: 与…...
基于Java+VUE+MariaDB实现(Web)仿小米商城
仿小米商城 环境安装 nodejs maven JDK11 运行 mvn clean install -DskipTestscd adminmvn spring-boot:runcd ../webmvn spring-boot:runcd ../xiaomi-store-admin-vuenpm installnpm run servecd ../xiaomi-store-vuenpm installnpm run serve 注意:运行前…...
给网站添加live2d看板娘
给网站添加live2d看板娘 参考文献: stevenjoezhang/live2d-widget: 把萌萌哒的看板娘抱回家 (ノ≧∇≦)ノ | Live2D widget for web platformEikanya/Live2d-model: Live2d model collectionzenghongtu/live2d-model-assets 前言 网站环境如下,文章也主…...
LangFlow技术架构分析
🔧 LangFlow 的可视化技术栈 前端节点编辑器 底层框架:基于 (一个现代化的 React 节点绘图库) 功能: 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...
