Caffe LENET或Imagenet模型中的参数数量 [英] number of parameters in Caffe LENET or Imagenet models

查看:636
本文介绍了Caffe LENET或Imagenet模型中的参数数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算模型中的参数数量。 LENET用于mnist,或ConvNet用于imagent模型等。
在caffe中有任何特定函数返回或保存模型中的参数数量。

How to calculate number of parameters in a model e.g. LENET for mnist, or ConvNet for imagent model etc. Is there any specific function in caffe that returns or saves number of parameters in a model. regards

推荐答案

这是一个python代码片段来计算Caffe模型中的参数数量:

Here is a python snippet to compute the number of parameters in a Caffe model:

import caffe
caffe.set_mode_cpu()
import numpy as np
from numpy import prod, sum
from pprint import pprint

def print_net_parameters (deploy_file):
    print "Net: " + deploy_file
    net = caffe.Net(deploy_file, caffe.TEST)
    print "Layer-wise parameters: "
    pprint([(k, v[0].data.shape) for k, v in net.params.items()])
    print "Total number of parameters: " + str(sum([prod(v[0].data.shape) for k, v in net.params.items()]))

deploy_file = "/home/ubuntu/deploy.prototxt"
print_net_parameters(deploy_file)

# Sample output:
# Net: /home/ubuntu/deploy.prototxt
# Layer-wise parameters: 
#[('conv1', (96, 3, 11, 11)),
# ('conv2', (256, 48, 5, 5)),
# ('conv3', (384, 256, 3, 3)),
# ('conv4', (384, 192, 3, 3)),
# ('conv5', (256, 192, 3, 3)),
# ('fc6', (4096, 9216)),
# ('fc7', (4096, 4096)),
# ('fc8', (819, 4096))]
# Total number of parameters: 60213280

a href =https://gist.github.com/kaushikpavani/a6a32bd87fdfe5529f0e908ed743f779 =nofollow> https://gist.github.com/kaushikpavani/a6a32bd87fdfe5529f0e908ed743f779

https://gist.github.com/kaushikpavani/a6a32bd87fdfe5529f0e908ed743f779

这篇关于Caffe LENET或Imagenet模型中的参数数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆