import time
transpose_conv = nn.ConvTranspose2d(
in_channels=3,
out_channels=3,
kernel_size=3,
stride=2,
padding=1,
output_padding=1)
unsample = nn.Upsample(scale_factor=2)
xxxxx = torch.rand(1,3,448,256)
startTime = time.time()
ddd = transpose_conv(xxxxx)
print(ddd.shape)
endTime = time.time()
print(endTime-startTime)
startTime1 = time.time()
eee = unsample(xxxxx)
print(eee.shape)
endTime1 = time.time()
print(endTime1-startTime1)
CPU比较结果:
torch.Size([1, 3, 896, 512])
0.016954421997070312
torch.Size([1, 3, 896, 512])
0.006981372833251953
GPU比较结果(需要在各个模块最后加入.cuda()),平台为1080ti:
torch.Size([1, 3, 896, 512])
0.2690904140472412
torch.Size([1, 3, 896, 512])
0.0017828941345214844