当前位置:网站首页>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

边栏推荐
- 嵌入式软件开发中必备软件工具
- 买股票应该下载什么软件最好最安全?
- Tardigrade:Trino 解决 ETL 场景的方案
- Thesis reading: General advantageous transformers
- Apache——阿帕奇簡介
- TensorRT 模型推理优化实现
- 爱普生L3153打印机如何清洗喷头
- matlab习题 —— 符号运算相关练习
- Hot! Yolov6's fast and accurate target detection framework is open source (with source code download)
- Brief history and future trend of codeless software
猜你喜欢

Excel知识技能汇总

音视频技术开发周刊 | 251

项目实战!手把手教你 Jmeter 性能测试

collections.defaultdict()的使用

基于流的深度生成模型

PPT制作小技巧

业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!

论文阅读:Generative Adversarial Transformers

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

Redis搭建集群【简单】
随机推荐
Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
In the digital era, enterprises must do well in user information security
Apache - about Apache
Apache, IIS6, ii7 independent IP host shielding restricts IP access
[postgraduate] bit by bit
View the SQL execution plan according to explain and optimize the SQL
Apache——阿帕奇簡介
【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
Ten reasons for system performance failure
【小游戏】跑酷
将PCAP转换为Json文件的神器:joy(安装篇)
RichView TRVStyle ParaStyles
新手开哪家的证券账户是比较好?股票开户安全吗
无代码软件发展简史及未来趋势
Use js programming questions [split] in Niuke
导致系统性能失败的十个原因
A16z: metauniverse unlocks new opportunities in game infrastructure
CMU puts forward a new NLP paradigm - reconstructing pre training, and achieving 134 high scores in college entrance examination English
Build your own website (17)
新手开哪家的证券账户是比较好?炒股开户安全吗