'Counts the number of parameters in the model at top level scope.'

def _countModelParameters(self):

    counter = {}
    for v in tf.global_variables():
        name = v.op.name.split('/')[0]
        num_params = v.get_shape().num_elements()
        assert num_params
        counter[name] = (counter.get(name, 0) + num_params)
    return counter
