当前位置:网站首页>Dataloader parameter collate_ Use of FN
Dataloader parameter collate_ Use of FN
2022-06-28 03:25:00 【xx_ xjm】
In short , This parameter is used to set dataloader The last output batch Content ;dataloader One time from dataset obtain batch Size data , But the data itself is fragmented , Take the picture for example , For example, we batch by 8, Then we get 8 individual [3,256,256](256 Shape for picture , Set it up casually ) The tensor of size , adopt collate_fn This parameter translates to a shape of [8,3,256,256] Tensor of as dataloader Output .
In general , This parameter does not need to be set , What is an unusual situation , For example, when the data length is different , The most obvious one is NLP The length of the sentence in the example , Every batch The sentences inside are different in length , If you use the default collate_fn Method , You may report a mistake , In this case, you need to customize collate_fn Parameters .
Rewriting this parameter is simple , Is to customize a function , Suppose we name this function here my_collate_fn(batch), Be careful , There can only be one input variable batch,batch Contains dataset Inside getitem All values returned .
take vqa Task as an example , such as dataset Of getitem Return the data of one picture at a time data,label, And corresponding question,answer, If we set dataloader Get... At one time 8 Size batch, Then the my_collate_fn The variable of is a list, This list contain 8 individual [data, label, question, answer], If you want to use the default collate_fn, Requirements , this 8 individual [data, label, question, answer] Inside , The shape of each variable is the same , That is to say 8 individual data In the same shape ,8 individual label In the same shape ,8 individual question The shape of the ,8 individual answer The shape of , In this way, the default collate_fn Parameters , Otherwise, an error will be reported . If not, you need to customize collate_fn Parameters
Examples are as follows , At this point, the customized vqa_collate_fn The input is list by 8 The variable of , Let's look at the third element of each of these variables individually , You can find , The first 0 And the 1 The length of the third element of the variables is different , In this case, if the default collate_fn You're going to report a mistake , And in here, , In our custom functions , We put the third element of each variable in a list It goes straight back to :
The example comes from ALBEF

边栏推荐
- mysql获取当前时间是一年的第多少天
- A16z: metauniverse unlocks new opportunities in game infrastructure
- Is it reliable to invest in the inter-bank certificate of deposit fund? Is the inter-bank certificate of deposit fund safe
- Built in functions for MySQL database operations
- 没错,是水的一篇
- 嵌入式软件开发中必备软件工具
- 根据Explain查看sql执行计划,对SQL进行优化
- What are the good practices of cloud cost optimization?
- In the digital era, enterprises must do well in user information security
- JS clear the object and its value:
猜你喜欢

【小程序】使用font-awesome字体图标的解决文案(图文)

Why is the service implementation class always red

2022 safety officer-c certificate examination question bank simulated examination platform operation

访问网站提示:您未被授权查看该页恢复办法

数字化时代,企业须做好用户信息安全

Inference optimization implementation of tensorrt model

Idea auto generate code

GAMES104 作业2-ColorGrading

Import an excel file, solve the problem of skipping blank cells without reading and moving the subscript forward, and return_ BLANK_ AS_ Null red

Relative path writing of files
随机推荐
Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
音视频技术开发周刊 | 251
__getitem__和__setitem__
Ten years' experience of Software Engineer
Redis搭建集群【简单】
2022 electrician (elementary) recurrent training question bank and online simulation examination
数的每一位平方和
文件的相对路径写法
2022 operation of simulated examination platform of special operation certificate examination question bank for safety management personnel of hazardous chemical business units
无代码软件发展简史及未来趋势
crond BAD FILE MODE /etc/cron. d
买股票通过券商经理的开户链接开户资金是否安全?想开户炒股
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices
Flow based depth generation model
RichView TRVStyle ParaStyles
2022安全员-C证考试题库模拟考试平台操作
Etcd database source code analysis -- network layer server rafthandler between clusters
Is it reliable to invest in the inter-bank certificate of deposit fund? Is the inter-bank certificate of deposit fund safe
Redis cluster setup [simple]