parameters: (model: Union[tf.Module, tf.keras.Model],
                       trainable_only: bool = False)
return_statement: return total_params
docstring: Count the number of parameters if model is possible.
    Args:
      model: Try to count the number of params in this model.
      trainable_only: Whether to calculate trainable params only. This flag is
        not used when the model has `count_params` attribute.
    Returns:
      The number of parameters or None.
docstring_summary: Count the number of parameters if model is possible.
    Args:
      model: Try to count the number of params in this model.
      trainable_only: Whether to calculate trainable params only. This flag is
        not used when the model has `count_params` attribute.
    Returns:
      The number of parameters or None.
docstring_tokens: Count the number of parameters if model is possible . Args : model : Try to count the number of params in this model . trainable_only : Whether to calculate trainable params only . This flag is not used when the model has count_params attribute . Returns : The number of parameters or None .
function: def try_count_params(model: Union[tf.Module, tf.keras.Model],
                       trainable_only: bool = False):
    """Count the number of parameters if model is possible.
    Args:
      model: Try to count the number of params in this model.
      trainable_only: Whether to calculate trainable params only. This flag is
        not used when the model has `count_params` attribute.
    Returns:
      The number of parameters or None.
    """
    if hasattr(model, 'count_params'):
      try:
        return model.count_params()
      except ValueError:
        logging.info('Number of trainable params unknown, because the build() '
                     'methods in keras layers were not called. This is probably '
                     'because the model was not feed any input, e.g., the max '
                     'train step already reached before this run.')
        return None
    else:
      total_params = 0
      variables = model.trainable_variables if trainable_only else model.variables
      for var in variables:
        shape = tf.shape(var)
        total_params += tf.math.reduce_prod(shape).numpy()
    return total_params
function_tokens: def try_count_params ( model : Union [ tf . Module , tf . keras . Model ] , trainable_only : bool = False ) : if hasattr ( model , 'count_params' ) : try : return model . count_params ( ) except ValueError : logging . info ( 'Number of trainable params unknown, because the build() ' 'methods in keras layers were not called. This is probably ' 'because the model was not feed any input, e.g., the max ' 'train step already reached before this run.' ) return None else : total_params = 0 variables = model . trainable_variables if trainable_only else model . variables for var in variables : shape = tf . shape ( var ) total_params += tf . math . reduce_prod ( shape ) . numpy ( ) return total_params