tensorflow统计网络参数量

通过tf.trainable_variables来统计整个网络的参数量

本文列举摘抄了七种方法,但是大同小异,得出的结果也都相同
def count1():
    total_parameters = 0
    for variable in tf.trainable_variables():
        # shape is an array of tf.Dimension
        shape = variable.get_shape()
        # print(shape)
        # print(len(shape))
        variable_parameters = 1
        for dim in shape:
            # print(dim)
            variable_parameters *= dim.value
        # print(variable_parameters)
        total_parameters += variable_parameters
    print(total_parameters)
def count2():
    print np.sum([np.prod(v.get_shape().as_list()) for v in tf.trainable_variables()])
def get_nb_params_shape(shape):
    '''
    Computes the total number of params for a given shap.
    Works for any number of shapes etc [D,F] or [W,H,C] computes D*F and W*H*C.
    '''
    nb_params = 1
    for dim in shape:
        nb_params = nb_params*int(dim)
    return nb_params

def count3():
    tot_nb_params = 0
    for trainable_variable in tf.trainable_variables():
        shape = trainable_variable.get_shape()  # e.g [D,F] or [W,H,C]
        current_nb_params = get_nb_params_shape(shape)
        tot_nb_params = tot_nb_params + current_nb_params
    print tot_nb_params
def count4():
    size = lambda v: reduce(lambda x, y: x * y, v.get_shape().as_list())
    n = sum(size(v) for v in tf.trainable_variables())
    # print "Model size: %dK" % (n / 1000,)
    print n
def count5():
    total_parameters = 0
    # iterating over all variables
    for variable in tf.trainable_variables():
        local_parameters = 1
        shape = variable.get_shape()  # getting shape of a variable
        for i in shape:
            local_parameters *= i.value  # mutiplying dimension values
        total_parameters += local_parameters
    print(total_parameters)
def count6():
    total_parameters = 0
    for variable in tf.trainable_variables():
        variable_parameters = 1
        for dim in variable.get_shape():
            variable_parameters *= dim.value
        total_parameters += variable_parameters

    print("Total number of trainable parameters: %d" % total_parameters)
def count7():
    from functools import reduce
    from operator import mul
    num_params = 0
    for variable in tf.trainable_variables():
        shape = variable.get_shape()
        num_params += reduce(mul, [dim.value for dim in shape], 1)
    print num_params

1.How to count total number of trainable parameters in a tensorflow model?

2.What is the best way to count the total number of parameters in a model in TensorFlow?
3.Number of CNN learnable parameters - Python / TensorFlow

4.tensorflow 获取模型所有参数总和数量

  • 16
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
图像质量评价经典算法是指一些用于评估图像质量的计算机视觉算法。其中,比较常用的算法包括BRISQUE(Blind/Referenceless Image Spatial Quality Evaluator)、RankIQA(Ranking-based Image Quality Assessment)和NIMA(Neural Image Assessment)。 BRISQUE算法是一种无考图像质量评价算法,它基于图像统计特征来估计图像的失真程度。BRISQUE算法首先提取图像的局部特征,如高斯滤波器响应、梯度直方图等。然后,通过学习训练样本的统计模型,计算得到图像的质量得分。 RankIQA算法是一种基于排序的图像质量评价算法,它利用图像之间的相对比较关系来估计图像的质量。RankIQA算法首先将图像库中的图像两两配对,并利用人工标注的图像质量分级来训练机器学习模型。然后,通过该模型,对待评估图像对进行排序,得到图像的质量得分。 NIMA算法是一种基于神经网络的图像质量评价算法,它利用深度学习模型学习图像质量的特征表示。NIMA算法首先使用一个卷积神经网络提取图像的特征表示,然后通过全连接层将提取的特征映射到一个维度为10的质量空间。最后,通过对训练集中的图像进行打分,使用最大似然估计方法优化网络参数,得到图像的质量得分。 这些经典的图像质量评价算法代码可以在开源的机器学习框架中找到,如TensorFlow、PyTorch等。也可以在相关论文的项目网站或GitHub上下载到对应的实现代码。使用这些算法代码,我们可以方便地在大量图像数据集上评估图像的质量,为图像处理和图像相关任务提供有力的支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值