gpt4 book ai didi

computer-vision - Caffe LENET 或 Imagenet 模型中的参数数量

转载 作者:行者123 更新时间:2023-12-04 06:58:19 24 4
gpt4 key购买 nike

如何计算模型中的参数数量,例如LENET 用于 mnist,或 ConvNet 用于 imagent 模型等。
caffe 中是否有任何特定函数可以返回或保存模型中的参数数量。
问候

最佳答案

这是一个用于计算 Caffe 模型中参数数量的 Python 代码段:

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

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

关于computer-vision - Caffe LENET 或 Imagenet 模型中的参数数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30403590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com