当前位置:网站首页>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
边栏推荐
- 2022 electrician (elementary) recurrent training question bank and online simulation examination
- 买股票通过券商经理的开户链接开户资金是否安全?想开户炒股
- 【522. 最长特殊序列 II】
- CURDATE()和NOW()区别
- R language penalty logistic regression, linear discriminant analysis LDA, generalized additive model GAM, multiple adaptive regression splines Mars, KNN, quadratic discriminant analysis QDA, decision
- windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
- A16z: metauniverse unlocks new opportunities in game infrastructure
- matlab习题 —— 符号运算相关练习
- RichView TRVStyle TextStyles
- Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
猜你喜欢
R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022
测试要掌握的技术有哪些?软件测试必懂的数据库设计大全篇
Excel知识技能汇总
2022年R1快开门式压力容器操作特种作业证考试题库及答案
[iptables & ICMP] description of ICMP Protocol in iptables default policy
matlab习题 —— 数据的基本处理
建立自己的网站(17)
劲爆!YOLOv6又快又准的目标检测框架开源啦(附源代码下载)
元宇宙标准论坛成立
空闲中断无法清除
随机推荐
Is it better for a novice to open a securities account? Is it safe to open a stock trading account
Ten reasons for system performance failure
[issue 21] face to face experience of golang engineer recruited by Zhihu Society
如何编写简洁代码?(上)
s32ds跳转到DefaultISR
Importer un fichier Excel, résoudre le problème de sauter les cellules vides et de ne pas lire, et avancer l'indice, et retourner Blank As NULL Red
Reading makes people quiet
crond BAD FILE MODE /etc/cron.d
Redis搭建集群【简单】
導入Excel文件,解决跳過空白單元格不讀取,並且下標前移的問題,以及RETURN_BLANK_AS_NULL報紅
Apache - about Apache
What are the good practices of cloud cost optimization?
Dataloader参数collate_fn的使用
为什么OpenCV计算的帧率是错误的?
2022电工(初级)复训题库及在线模拟考试
Relative path writing of files
简单ELK配置实现生产级别的日志采集和查询实践
业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!
A16z:元宇宙解锁游戏基础设施中的新机遇
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序