解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for

简介: 解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for

问题描述

使用tensorboard显示图像出现问题

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-96-71fff8c3a347> in <module>
      2 grid = torchvision.utils.make_grid(img)
      3 
----> 4 logger.add_images('images', grid, 0)
D:\Anaconda\lib\site-packages\torch\utils\tensorboard\writer.py in add_images(self, tag, img_tensor, global_step, walltime, dataformats)
    599             img_tensor = workspace.FetchBlob(img_tensor)
    600         self._get_file_writer().add_summary(
--> 601             image(tag, img_tensor, dataformats=dataformats), global_step, walltime)
    602 
    603     def add_image_with_boxes(self, tag, img_tensor, box_tensor, global_step=None,
D:\Anaconda\lib\site-packages\torch\utils\tensorboard\summary.py in image(tag, tensor, rescale, dataformats)
    394     """
    395     tensor = make_np(tensor)
--> 396     tensor = convert_to_HWC(tensor, dataformats)
    397     # Do not assume that user passes in values in [0, 255], use data type to detect
    398     scale_factor = _calc_scale_factor(tensor)
D:\Anaconda\lib\site-packages\torch\utils\tensorboard\_utils.py in convert_to_HWC(tensor, input_format)
     99         input_format: {}".format(input_format)
    100     assert(len(tensor.shape) == len(input_format)), "size of input tensor and input format are different. \
--> 101         tensor shape: {}, input_format: {}".format(tensor.shape, input_format)
    102     input_format = input_format.upper()
    103 
AssertionError: size of input tensor and input format are different.         tensor shape: (3, 138, 274), input_format: NCHW

解决方案:

logger.add_image('images', grid, 0)


目录
相关文章
[AssertionError: nput tensor input format are different]
分析到这儿就明白了。input tensor虽然格式也是CHW, 但它还有一个batch维度,所以报错。
208 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
986 0
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
3020 0
|
并行计算
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the
600 0
成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor Placeholder:0 , which has shape
成功解决ValueError: Cannot feed value of shape (1, 10, 4) for Tensor Placeholder:0 , which has shape
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
771 0
|
6月前
|
机器学习/深度学习 PyTorch 算法框架/工具
【Pytorch】Expected hidden[0] size (2, 136, 256), got [2, 256, 256]
文章解决了PyTorch中LSTM模型因输入数据的批次大小不一致导致的“Expected hidden[0] size”错误,并提供了两种解决方案:调整批次大小或在DataLoader中设置drop_last=True来丢弃最后一个不足批次大小的数据。
125 1
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
1242 0

热门文章

最新文章