0
点赞
收藏
分享

微信扫一扫

mxnet.gluon.data.vision.transforms.ToTensor


import mxnet
print(help(mxnet.gluon.data.vision.transforms.ToTensor))

由下可见,小小的ToTensor竟实现了这么多转换:

1、数值类型:uint8 ——> float32

2、数值范围:[0, 255] ——> [0,  1]

3、矩阵格式:(H x W x C) or (N x H x W x C)  ——>(C x H x W) or (N x H x W x C)  PS:H为高,W为宽,C为通道,N为batch

至于做这么多转换的原因是,这是MXNet处理图像时指定的格式,便于处理

输出:

Help on class ToTensor in module mxnet.gluon.data.vision.transforms:

class ToTensor(mxnet.gluon.block.HybridBlock)
| Converts an image NDArray or batch of image NDArray to a tensor NDArray.
|
| Converts an image NDArray of shape (H x W x C) in the range
| [0, 255] to a float32 tensor NDArray of shape (C x H x W) in
| the range [0, 1].
|
| If batch input, converts a batch image NDArray of shape (N x H x W x C) in the
| range [0, 255] to a float32 tensor NDArray of shape (N x C x H x W).
|
| Inputs:
| - **data**: input tensor with (H x W x C) or (N x H x W x C) shape and uint8 type.
|
| Outputs:
| - **out**: output tensor with (C x H x W) or (N x H x W x C) shape and float32 type.
|
| Examples
| --------
| >>> transformer = vision.transforms.ToTensor()
| >>> image = mx.nd.random.uniform(0, 255, (4, 2, 3)).astype(dtype=np.uint8)
| >>> transformer(image)
| [[[ 0.85490197 0.72156864]
| [ 0.09019608 0.74117649]
| [ 0.61960787 0.92941177]
| [ 0.96470588 0.1882353 ]]
| [[ 0.6156863 0.73725492]
| [ 0.46666667 0.98039216]
| [ 0.44705883 0.45490196]
| [ 0.01960784 0.8509804 ]]
| [[ 0.39607844 0.03137255]
| [ 0.72156864 0.52941179]
| [ 0.16470589 0.7647059 ]
| [ 0.05490196 0.70588237]]]
| <NDArray 3x4x2 @cpu(0)>

 

举报

相关推荐

0 条评论