我正在寻找一种方法来获取图像/目标批次进行分割并返回图像尺寸已更改为与整个批次相同的批次。我已经使用下面的代码尝试过:
def collate_fn_padd(batch):
'''
Padds batch of variable length
note: it converts things ToTensor manually here since the ToTensor transform
assume it takes in images rather than arbitrary tensors.
'''
# separate the image and masks
image_batch,mask_batch = zip(*batch)
# pad the images and masks
image_batch = torch.nn.utils.rnn.pad_sequence(image_batch, batch_first=True)
mask_batch = torch.nn.utils.rnn.pad_sequence(mask_batch, batch_first=True)
# rezip the batch
batch = list(zip(image_batch, mask_batch))
return batch
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误:
RuntimeError: The expanded size of the tensor (650) must match the existing size (439) at non-singleton …
Run Code Online (Sandbox Code Playgroud)