在pytorch中使用类似tf.placeholder的方法,能够在不需要管数据预处理的情况下快速得到模型整个pipeline中每一步的输入输出维度与数据类型。
x = Variable(torch.randn(shape).type(dtype), requires_grad=False) #Pytorch
测量模型参数的代码段
if __name__ == '__main__':
x1 = torch.rand(2, 3, 128, 128)
print(x1.shape)
model = Net()
a= model(x1)
print(a.shape)
from thop.profile import profile
name = "our"
total_ops, total_params = profile(model, (x1,))
print("%s | %.4f(M) | %.4f(G) |" % (name, total_params / (1000 ** 2), total_ops / (1000 ** 3)))
第一个参数是计算量,第二个参数是参数的个数