TracerWarning:将张量转换为Python索引可能会导致跟踪不正确

时间:2019-04-11 12:26:53

标签: python pytorch torch

我正在尝试创建跟踪文件。相关代码部分在这里:

def center_crop(self, layer, target_size):
    _, _, layer_height, layer_width = layer.size()

    diff_y = (layer_height - target_size[0]) // 2
    diff_x = (layer_width - target_size[1]) // 2
    return layer[:, :, diff_y:(diff_y + target_size[0]), diff_x:(diff_x + target_size[1])]

def forward(self, x, bridge):

    up = self.up(x)
    crop1 = self.center_crop(bridge, up.shape[2:])
    out = torch.cat([up, crop1], 1)
    out = self.conv_block(out)

它在此行发出警告:

return layer[:, :, diff_y:(diff_y + target_size[0]), diff_x:(diff_x + target_size[1])]

然后,我将此跟踪文件加载到C ++中并预测了测试图像。然后,我将结果与python中的输出进行了比较。我观察到结果非常不同。我想原因是该警告引起的。

0 个答案:

没有答案