当前位置: 首页 > news >正文

【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宽高改变

本来是想没有数据显示暂无数据的&#xff0c;结果显示成了这样 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.总结 话不多说 直接开冲 干干干&#xff01; 1. 介绍 typescript 的数据类型主要有如下&#xff1a; boolean&#xff08;布尔类型&#xff09;number&#xff08;数字类型&#xff09;string&#xff08;字符串类型&#xff09;array&#xff08;数组类型&…...

计算机网络 应用层 C/S方式(客户/服务方式) P2P方式(对等方式)

...

RabbitMQ-消息中间件学习记录(what-how-why)

什么是消息中间件 简单的来说就是消息队列中间件&#xff0c;生产者发送消息到中间件&#xff0c;消息中间件用于保存消息并发送消息到消费者。 消息中间件RabbitMQ的基本组件 1&#xff09;producer -生产者 2&#xff09;customer -消费者 3&#xff09;broker (经纪人)- MQ…...

前端HTML进阶

day02&#xff1a;列表、表格、表单 目标&#xff1a;掌握嵌套关系标签的写法&#xff0c;使用列表标签布局网页 01-列表 作用&#xff1a;布局内容排列整齐的区域。 列表分类&#xff1a;无序列表、有序列表、定义列表。 无序列表 作用&#xff1a;布局排列整齐的不需要规…...

Python“牵手”lazada商品详情页数据采集方法,lazadaAPI接口申请指南

lazada详情接口 API 是开放平台提供的一种 API 接口&#xff0c;它可以帮助开发者获取商品的详细信息&#xff0c;包括商品的标题、描述、图片等信息。在电商平台的开发中&#xff0c;详情接口API是非常常用的 API&#xff0c;因此本文将详细介绍详情接口 API 的使用。 一、la…...

买机票系统---(java实现)

/* * 案例 * 卖机票 * 需求&#xff1a;机票价格按照淡季和旺季&#xff0c;头等舱和经济舱收费&#xff0c;输入机票原价&#xff0c;月份和头等舱或经济舱 * 旺季&#xff08;5-10月&#xff09;&#xff1a;头等舱9折&#xff0c;经济舱8.5折 * 淡季&#xff08;11-来年4月&…...

“new出对象“原理的深层解密

&#x1f388;个人主页:&#x1f388; :✨✨✨初阶牛✨✨✨ &#x1f43b;推荐专栏1: &#x1f354;&#x1f35f;&#x1f32f;C语言初阶 &#x1f43b;推荐专栏2: &#x1f354;&#x1f35f;&#x1f32f;C语言进阶 &#x1f511;个人信条: &#x1f335;知行合一 &#x1f…...

Java基础篇--SecureRandom(安全随机)类

java.security.SecureRandom类是Java中用于生成安全的随机数的一个类。与普通的Random类不同&#xff0c;它提供了一种可信赖的随机数生成器&#xff0c;用于生成具有高度随机性的随机数。 SecureRandom类的实例使用了更加安全的随机数生成算法&#xff0c;这些算法通常经过密…...

论文复现--关于多视角动作捕捉工具箱 --XRMoCap的研究

分类&#xff1a;动作捕捉 github地址&#xff1a;https://github.com/openxrlab/xrmocap 所需环境&#xff1a; Ubuntu18.04&#xff0c;conda22.9.0&#xff0c;CUDA11.4 目录 环境配置 环境配置 conda create -n XRmocap python3.7 -y conda activate XRmocap# install ffm…...

Spring Profile与PropertyPlaceholderConfigurer实现项目多环境配置切换

最近考虑项目在不同环境下配置的切换&#xff0c;使用profile注解搭配PropertyPlaceholderConfigurer实现对配置文件的切换&#xff0c;简单写了个demo记录下实现。 基本知识介绍 Profile Profile通过对bean进行修饰&#xff0c;来限定spring在bean管理时的初始化情况&#…...

ansible入门

ansible入门 一.ansible 背景介绍 Ansible 是一个广受欢迎的 IT 自动化系统。可以用来处理配置管理、应用自动化部署、云资源配给、网络 自动化和多借点部署等任务。其也可以使得复杂的变更如带负载均衡的零停机滚动更新更加容易。Ansible.com 1.1 自动化运维概念 1.1.1 运维…...

用Node.js吭哧吭哧撸一个运动主页

简单唠唠 某乎问题&#xff1a;人这一生&#xff0c;应该养成哪些好习惯&#xff1f; 问题链接&#xff1a;https://www.zhihu.com/question/460674063 如果我来回答肯定会有定期运动的字眼。 平日里也有煅练的习惯&#xff0c;时间久了后一直想把运动数据公开&#xff0c;…...

【C++】STL---vector

STL---vector 一、vector 的介绍二、vector 的模拟实现1. 容量相关的接口&#xff08;1&#xff09;size&#xff08;2&#xff09;capacity&#xff08;3&#xff09;reserve&#xff08;4&#xff09;resize&#xff08;5&#xff09;empty 2. [] 重载3. 迭代器4. 修改数据相…...

机器学习:基本介绍

机器学习介绍 Hnad-crafted rules Hand-crafted rules&#xff0c;叫做人设定的规则。那假设今天要设计一个机器人&#xff0c;可以帮忙打开或关掉音乐&#xff0c;那做法可能是这样&#xff1a; 设立一条规则&#xff0c;就是写一段程序。如果输入的句子里面看到**“turn of…...

基于长短期神经网络LSTM的碳排量预测,基于LSTM的碳排放量预测

目录 背影 摘要 LSTM的基本定义 LSTM实现的步骤 基于长短期神经网络LSTM的碳排放量预测 完整代码: 基于长短期神经网络LSTM的碳排放量预测,基于LSTM的碳排放量预测资源-CSDN文库 https://download.csdn.net/download/abc991835105/88184632 效果图 结果分析 展望 参考论文 背…...

Redis 客户端连接详解

Redis 客户端连接详解 引言 Redis 是一款高性能的内存数据结构存储系统,常用于缓存、会话管理、实时排行榜等功能。客户端连接是 Redis 生态系统中的重要组成部分,本文将详细介绍 Redis 客户端连接的相关知识,包括连接方式、连接配置、连接管理等方面。 Redis 客户端连接…...

终极解决方案:Windows Cleaner免费开源工具,3步彻底解决C盘爆红问题

终极解决方案&#xff1a;Windows Cleaner免费开源工具&#xff0c;3步彻底解决C盘爆红问题 【免费下载链接】WindowsCleaner Windows Cleaner——专治C盘爆红及各种不服&#xff01; 项目地址: https://gitcode.com/gh_mirrors/wi/WindowsCleaner 你是否也经历过这样的…...

ROS机器人仿真架构解析:基于wpr_simulation的移动操作机器人技术实现

ROS机器人仿真架构解析&#xff1a;基于wpr_simulation的移动操作机器人技术实现 【免费下载链接】wpr_simulation 项目地址: https://gitcode.com/gh_mirrors/wp/wpr_simulation 在机器人操作系统(ROS)开发领域&#xff0c;硬件依赖和测试成本一直是制约算法迭代效率的…...

OpenCore Legacy Patcher完整指南:如何让老旧Mac重获新生运行最新macOS

OpenCore Legacy Patcher完整指南&#xff1a;如何让老旧Mac重获新生运行最新macOS 【免费下载链接】OpenCore-Legacy-Patcher Experience macOS just like before 项目地址: https://gitcode.com/GitHub_Trending/op/OpenCore-Legacy-Patcher 想让你的老旧Mac设备重获新…...

如何在macOS上免费安装HSTracker:终极炉石传说套牌追踪器完整指南

如何在macOS上免费安装HSTracker&#xff1a;终极炉石传说套牌追踪器完整指南 【免费下载链接】HSTracker A deck tracker and deck manager for Hearthstone on macOS 项目地址: https://gitcode.com/gh_mirrors/hs/HSTracker 还在为炉石传说对局中记不住对手出牌而烦恼…...

HS2-HF Patch:3分钟解锁Honey Select 2完整游戏体验的技术指南

HS2-HF Patch&#xff1a;3分钟解锁Honey Select 2完整游戏体验的技术指南 【免费下载链接】HS2-HF_Patch Automatically translate, uncensor and update HoneySelect2! 项目地址: https://gitcode.com/gh_mirrors/hs/HS2-HF_Patch HS2-HF Patch是专为Honey Select 2 L…...

机器学习预测细菌耐药性:从全基因组数据到公共卫生预警

1. 项目概述与核心价值抗菌药物耐药性&#xff08;AMR&#xff09;这事儿&#xff0c;现在谁提起来都头疼。它不再是实验室报告上的一个数字&#xff0c;而是直接关系到我们每个人生病了还有没有药可用的现实问题。弯曲杆菌&#xff0c;这个听起来有点拗口的名字&#xff0c;其…...

Label Studio数据源配置全攻略:除了S3和Azure,如何用本地文件夹搭建高效标注流水线?

Label Studio数据存储方案深度对比&#xff1a;从云端到本地的架构选型指南 在机器学习项目的数据标注环节&#xff0c;Label Studio已成为众多团队的首选工具。但面对不同规模、不同安全要求的项目时&#xff0c;如何选择最适合的数据存储方案却让许多技术决策者感到困扰。本文…...

告别内存泄漏!Cocos Creator 2.4+ AssetManager资源释放的完整避坑指南

Cocos Creator 2.4 AssetManager资源释放的完整避坑指南在游戏开发中&#xff0c;资源管理一直是影响性能和稳定性的关键因素。随着Cocos Creator 2.4版本推出全新的AssetManager系统&#xff0c;开发者获得了更强大的资源管理能力&#xff0c;但也面临着新的挑战。本文将深入探…...

基于AIS数据与随机森林的船舶类型智能识别:从特征工程到不平衡数据处理

1. 项目概述与核心价值在海上交通管理、港口调度、渔业监管乃至海上安全监测等领域&#xff0c;快速、准确地识别船舶类型是一项基础且关键的任务。想象一下&#xff0c;一个繁忙的港口调度员面对雷达屏幕上密密麻麻的光点&#xff0c;如果能瞬间知道哪些是庞大的油轮、哪些是灵…...