inputs = torch.rand(10, 50, 40) lin = CLinear(in_neurons = inputs.shape[-1]/2, n_neurons = 100) output = lin(inputs) print(output.shape)
TypeError: object of type 'float' has no len()
错误原因:
inputs.shape[-1]/2 是一个 float 类型,在CLinear 调用时候用到 len()函数报错
解决办法
取整操作
inputs.shape[-1]//2