模型加載,從cpu到gpu
self.net.load_state_dict(torch.load(net_path,map_location=lambda storage,loc:storage))
namedetuple給元組起名字
namedtuple('GenericDict',cfg.keys())
np.hanning()
np.hanning(N)
#長爲n的漢寧窗
np.outer()
a = np.arange(4)
array([0, 1, 2, 3])
np.outer(a,(2,1))
array([[0, 0],
[2, 1],
[4, 2],
[6, 3]])
np.outer(a,1)
array([[0],
[1],
[2],
[3]])
torch:
unsqueeze()在指定維度上加一維
squeeze()在指定維度上減一維
np:
title(a,())在指定維度上覆制多次
a.shape
Out[43]: (4,)
torch.from_numpy(a).unsqueeze(1).shape
Out[41]: torch.Size([4, 1])
torch.from_numpy(a).unsqueeze(0).shape
Out[42]: torch.Size([1, 4])
torch.from_numpy(a).squeeze(0).shape
Out[44]: torch.Size([4])
np.tile(a,(2,1)).shape
Out[52]: (2, 4)
np.tile(a,(3,2,1)).shape
Out[51]: (3, 2, 4)