Holding all the data handled by the network. So a layer will receive this class and return a similar block as a output that will be used by the next layer in the chain.
@author Daniel Persson (mailto.woden@gmail.com)
Holding all the data handled by the network. So a layer will receive this class and return a similar block as a output that will be used by the next layer in the chain.
@author Daniel Persson (mailto.woden@gmail.com)
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| SetValues | 1 | 把整块数据写入 DataBlock.w,并声明值数据的设备端缓存已失效 |
| SetGradients | 1 | 把整块数据写入 DataBlock.dw,并声明梯度数据的设备端缓存已失效 |
| MarkValueModified | 1 | 声明值数据的设备端缓存已失效(就地改写 DataBlock.w 之后必须调用) |
| MarkGradientModified | 1 | 声明梯度数据的设备端缓存已失效(就地改写 DataBlock.dw 之后必须调用) |
| MarkHostModified | 1 | 对已创建的视图逐个推进版本号(未创建的视图本来就没有显存副本,无需处理) |
| .ctor | 4 | Creates an empty block, used by the deserializer. |
| ToString | 1 | Returns a short diagnostic description of the block. |
| addImageData | 3 | Prepares the input by copying the pixels into the weight vector and normalizing them into [-0.5, 0.5]. |
| getWeight | 2 | Gets the weight at the given three dimensional coordinate. |
| setWeight | 2 | get DataBlock.w |
| addWeight | 1 | Adds a value to the weight at the given three dimensional coordinate. |
| getGradient | 2 | Gets the gradient at the given three dimensional coordinate. |
| setGradient | 3 | Replaces the whole gradient vector with the given values. |
| addGradient | 2 | Adds a value to the gradient at the given flat index. |
| subGradient | 1 | Subtracts a value from the gradient at the given flat index. |
| mulGradient | 1 | val * DataBlock.Gradients |
| cloneAndZero | 1 | Creates a new block with the same shape and trace but with all weights zeroed. |
| clone | 1 | make a copy of DataBlock.w or DataBlock.Weights |
| clearGradient | 1 | just set DataBlock.dw vector to zero |
| addFrom | 1 | Copies the weights of another block into this one. |
| addFromScaled | 1 | Copies the weights of another block into this one, scaled by a constant factor. |
03 Properties
| Name | Overloads | Summary |
|---|---|---|
| SX | 1 | Gets the width of the block. |
| SY | 1 | Gets the height of the block. |
| Depth | 1 | Gets the number of channels (depth) of the block. |
| trace | 1 | Optional diagnostic label that identifies where this block came from. |
| Weights | 1 | the multiple class classify probability weight (or the prediction result) |
| Gradients | 1 | Gets the gradient vector that corresponds one to one with DataBlock.Weights. |
| Value | 1 | 值数据的张量视图(零拷贝,与 DataBlock.Weights 共享同一份底层存储)。 形状为 (SY, SX, Depth),正好对应索引公式 (SX*y + x)*Depth + depth。 |
| Grad | 1 | 梯度数据的张量视图(零拷贝,与 DataBlock.Gradients 共享同一份底层存储)。 |
| TensorShape4D | 1 | 把本块当作单样本图像时的四维形状 (N=1, H=SY, W=SX, C=Depth) |
| Value4D | 1 | 值数据的四维视图 (1, SY, SX, Depth):供卷积/池化算子使用 |
| Grad4D | 1 | 梯度数据的四维视图 (1, SY, SX, Depth):作为卷积/池化的 gradOutput |
| Value2D | 1 | 值数据的二维列向量视图 (n, 1):供矩阵乘使用 |
| Grad2D | 1 | 梯度数据的二维列向量视图 (n, 1):作为矩阵乘的 gradOutput |
04 Fields
05 Members
Double())把整块数据写入 DataBlock.w,并声明值数据的设备端缓存已失效
Double())把整块数据写入 DataBlock.dw,并声明梯度数据的设备端缓存已失效
声明值数据的设备端缓存已失效(就地改写 DataBlock.w 之后必须调用)
需要把本块持有的全部视图都标记一遍:三维的 DataBlock.Value、四维的 DataBlock.Value4D、 二维的 DataBlock.Value2D。它们各自持有独立的版本号,少标一个就会出现 "某个算子读到旧值"的静默错误。 由于视图都由本块缓存,这里已经不需要再调用全局的 Tensor.InvalidateAllDeviceCaches, 失效粒度从"所有张量"收敛到"本块"。
声明梯度数据的设备端缓存已失效(就地改写 DataBlock.dw 之后必须调用)
Tensor)对已创建的视图逐个推进版本号(未创建的视图本来就没有显存副本,无需处理)
Creates an empty block, used by the deserializer.
Int32, Int32, Int32)Creates a block of the given size with randomly initialized weights.
| Name | Type | Description |
|---|---|---|
sx | Int32 | Width. |
sy | Int32 | Height. |
depth | Int32 | Number of channels. |
Creates a block from a Dimension and a weight initialization value.
| Name | Type | Description |
|---|---|---|
dims | Dimension | The block dimensions. |
depth | Int32 | Number of channels. |
c | Double | The constant used to fill the weights, or |
Int32, Int32, Int32, Double)Creates a block of the given size.
| Name | Type | Description |
|---|---|---|
sx | Int32 | Width. |
sy | Int32 | Height. |
depth | Int32 | Number of channels. |
c | Double | Constant used to initialize the weight vector; when it equals |
Returns a short diagnostic description of the block.
A text that reports the shape, the trace label and the first few weight values.
Byte(), Byte)Prepares the input by copying the pixels into the weight vector and normalizing them into [-0.5, 0.5].
| Name | Type | Description |
|---|---|---|
imgData | Byte() | The raw byte pixel data. |
maxvalue | Byte | The maximum possible channel value, normally 255. |
Double(), Double)Prepares the input by copying the pixels into the weight vector and normalizing them into [-0.5, 0.5].
| Name | Type | Description |
|---|---|---|
imgData | Double() | The raw pixel data. |
maxvalue | Double | The maximum possible channel value. |
Int32(), Int32)Prepares the input by copying the pixels into the weight vector and normalizing them into [-0.5, 0.5].
| Name | Type | Description |
|---|---|---|
imgData | Int32() | The raw integer pixel data. |
maxvalue | Int32 | The maximum possible channel value. |
Int32)set DataBlock.w
| Name | Type | Description |
|---|---|---|
ix | Int32 | - |
Int32, Int32, Int32)Gets the weight at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
The weight value.
Int32, Double)get DataBlock.w
| Name | Type | Description |
|---|---|---|
ix | Int32 | - |
val | Double | - |
Int32, Int32, Int32, Double)Sets the weight at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
val | Double | The value to store. |
Int32, Int32, Int32, Double)Adds a value to the weight at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
val | Double | The value to add. |
Int32, Int32, Int32)Gets the gradient at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
The gradient value.
Int32)get element value from DataBlock.dw
| Name | Type | Description |
|---|---|---|
ix | Int32 | - |
Int32, Int32, Int32, Double)Sets the gradient at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
val | Double | The value to store. |
Int32, Double)set element value to DataBlock.Gradients
set value to DataBlock.dw
| Name | Type | Description |
|---|---|---|
ix | Int32 | - |
val | Double | - |
Double())Replaces the whole gradient vector with the given values.
| Name | Type | Description |
|---|---|---|
val | Double() | The new gradient values. |
Int32, Int32, Int32, Double)Adds a value to the gradient at the given three dimensional coordinate.
| Name | Type | Description |
|---|---|---|
x | Int32 | The column index. |
y | Int32 | The row index. |
depth | Int32 | The channel index. |
val | Double | The value to add. |
Int32, Double)Adds a value to the gradient at the given flat index.
| Name | Type | Description |
|---|---|---|
ix | Int32 | The flat index into the gradient vector. |
val | Double | The value to add. |
Int32, Double)Subtracts a value from the gradient at the given flat index.
| Name | Type | Description |
|---|---|---|
ix | Int32 | The flat index into the gradient vector. |
val | Double | The value to subtract. |
Double)val * DataBlock.Gradients
| Name | Type | Description |
|---|---|---|
val | Double | - |
Creates a new block with the same shape and trace but with all weights zeroed.
A zero filled copy of this block.
make a copy of DataBlock.w or DataBlock.Weights
just set DataBlock.dw vector to zero
Copies the weights of another block into this one.
| Name | Type | Description |
|---|---|---|
db | DataBlock | The source block; it must have the same length. |
Double)Copies the weights of another block into this one, scaled by a constant factor.
| Name | Type | Description |
|---|---|---|
db | DataBlock | The source block; it must have the same length. |
a | Double | The scale factor applied to every source weight. |
Gets the width of the block.
Gets the height of the block.
Gets the number of channels (depth) of the block.
Optional diagnostic label that identifies where this block came from.
the multiple class classify probability weight (or the prediction result)
get DataBlock.w
Gets the gradient vector that corresponds one to one with DataBlock.Weights.
Returns the backing field DataBlock.dw.
值数据的张量视图(零拷贝,与 DataBlock.Weights 共享同一份底层存储)。 形状为 (SY, SX, Depth),正好对应索引公式 (SXy + x)Depth + depth。
梯度数据的张量视图(零拷贝,与 DataBlock.Gradients 共享同一份底层存储)。
把本块当作单样本图像时的四维形状 (N=1, H=SY, W=SX, C=Depth)
值数据的四维视图 (1, SY, SX, Depth):供卷积/池化算子使用
梯度数据的四维视图 (1, SY, SX, Depth):作为卷积/池化的 gradOutput
值数据的二维列向量视图 (n, 1):供矩阵乘使用
梯度数据的二维列向量视图 (n, 1):作为矩阵乘的 gradOutput
backend of DataBlock.Weights
backend of DataBlock.Gradients