我试着把一张图片加到画板上。
img = Image.open(image_path)
img = (np.asarray(img) / 255.0)
img = torch.from_numpy(img).float()
img = img.cuda().permute(2, 0, 1)
img = img.cuda().unsqueeze(0)
writer.add_image('Original', img)但这是个错误。
张量形状:{},input_format:{}".format(tensor.shape,input_format) AssertionError:输入张量的大小和输入格式不同。张量形状:(1,3,420,629),input_format: CHW
发布于 2022-03-31 14:33:33
看起来像使用函数来添加单个图像,但是您正在添加一批大小为1的图像。如果您不想用img重塑/扁平/混乱,请尝试指定dataformats参数并使用add_images
writer.add_images('Original', img, dataformats='NCHW')img_tensor:默认为(N,3,H,W)(N,3,H,W)。如果指定了数据格式,则将接受其他形状。例如NCHW或NHWC。
源图像
https://stackoverflow.com/questions/67094398
复制相似问题