LOD_CN.md 1.3 KB
Newer Older
T
11  
Thomas Young 已提交
1 2
# Lod字段说明

T
TeslaZhao 已提交
3
(简体中文|[English](LOD_EN.md))
T
11  
Thomas Young 已提交
4 5 6

## 概念

H
fix doc  
HexToString 已提交
7 8 9
Tensor以及Padding的概念说明请参考[PaddlePaddle官网说明](https://www.paddlepaddle.org.cn/documentation/docs/zh/1.8/beginners_guide/basic_concept/tensor.html)

LoD(Level-of-Detail) Tensor是Paddle的高级特性,是对Tensor的一种扩充。LoDTensor通过牺牲灵活性来提升训练的效率,减少padding带来的数据扩充的影响。
T
1  
Thomas Young 已提交
10 11 12

**注:** 对于大部分用户来说,无需关注LoDTensor的用法,目前Serving中仅支持一维Lod的用法。

T
11  
Thomas Young 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25

## 使用

**前提:** 首先您的预测模型需要支持变长Tensor的输入。


以视觉任务为例,在视觉任务中,时常需要处理视频和图像这些元素是高维的对象,假设现存的一个mini-batch包含3个视频,分别有3个,1个和2个帧。
每个帧都具有相同大小:640x480,则这个mini-batch可以被表示为:
```
3     1  2
口口口 口 口口
```
最底层tensor大小为(3+1+2)x640x480,每一个 口 表示一个640x480的图像。
T
Thomas Young 已提交
26

T
11  
Thomas Young 已提交
27
那么此时,Tensor的shape为[6,640,480],lod=[0,3,4,6].
T
Thomas Young 已提交
28

T
11  
Thomas Young 已提交
29
其中0为起始值,3-0=3;4-3=1;6-4=2,这三个值正好表示您的变长信息,lod中的最后一个元素6,应等于shape中第一维度的总长度。
T
Thomas Young 已提交
30

T
11  
Thomas Young 已提交
31
lod中记录的变长信息与Tensor中shape的第一维度的信息应按照上述方式对齐。