Pytorch中,变量参数,用numel得到参数数目,累加
def get_parameter_number(net):
total_num = sum(p.numel() for p in net.parameters())
trainable_num = sum(p.numel() for p in net.parameters() if p.requires_grad)
return {'Total': total_num, 'Trainable': trainable_num}
Keras中,直接使用model的summary函数
model = k_model()
model.summary()