2

我首先看到了 luatorch[cpuType]中的用法,例如 fb.resnest.torch 的文件dataloader.lua

batch = torch[cpuType](sz, nCrops, table.unpack(imageSize))

我没有找到任何语法解释。怎么理解?

PS:cpuType是在文件中定义的self.cpuType,我猜是 .

更新:根据我的测试,torch['FloatTensor']相当于torch.FloatTensor.

4

2 回答 2

0

我认为这torch[cpuType]torch.cpuType.

代码(https://github.com/facebook/fb.resnet.torch/blob/master/dataloader.lua#L51-L57)似乎说cpuType可以采用几个不同的值,即DoubleTensor,FloatTensorHalfTensor. 因此,该符号创建了torch.DoubleTensorortorch.FloatTensortorch.HalfTensor。它是一种更紧凑的符号,例如

if cpuType == 'torch.DoubleTensor' then
    batch = torch.DoubleTensor(sz, nCrops, table.unpack(imageSize))
elseif cpuType == 'torch.FloatTensor' then
    batch = torch.FloatTensor(sz, nCrops, table.unpack(imageSize))
elseif cpuType == 'torch.HalfTensor' then
    batch = torch.HalfTensor(sz, nCrops, table.unpack(imageSize))
于 2017-07-19T21:25:50.400 回答
0

From my knowledge in pytorch, which is pretty much very similar to Lua Torch (I tried lua torch too), I would say it specifies where you want this tensor to be stored. Note that torch cannot perform an operation stored two different processing unit. There are methods to move data between cpu (netŧ.cpu()) and gpu [net.cuda()].

于 2017-07-18T18:12:35.813 回答