torch学习入坑(1)
记录一下第一个坑,防止自己忘记。
在用torchvision.utils.make_grid处理完图片之后,维度会变为三维,如果需要使用tf.summary.image ,需要增加batch size 的那一维,需要用到的函数为 tf.expand_dims。
注意:
1、torchvision.utils.make_grid函数
输入:Tensor of shape (B x C x H x W)
输出:多个图片拼接成的一个大图 三维 没有batch size 那一维
like this:
以下解释来自官网
链接http://pytorch.org/docs/master/torchvision/utils.html
torchvision.utils.make_grid(tensor, nrow=8, padding=2, normalize=False, range=None, scale_each=False, pad_value=0)
scale_each=False, pad_value=0)
作用:Make a grid of images.
Parameters:
tensor (Tensor or list) – 4D mini-batch Tensor of shape (B x C x H x W) or a list of images all of the same size.
nrow (int, optional) – Number of images displayed in each row of the grid. The Final grid size is (B / nrow, nrow). Default is 8.
padding (int, optional) – amount of padding. Default is 2.
normalize (bool, optional) – If True, shift the image to the range (0, 1), by subtracting the minimum and dividing by the maximum pixel value.
range (tuple, optional) – tuple (min, max) where min and max are numbers, then these numbers are used to normalize the image. By default,