code: def filter_variables(
      var_list,
      include_patterns=None,
      exclude_patterns=None,
      reg_search=True,
  ):
      """Filter a list of variables using regular expressions.
  
      First includes variables according to the list of include_patterns.
      Afterwards, eliminates variables according to the list of exclude_patterns.
  
      For example, one can obtain a list of variables with the weights of all
      convolutional layers (depending on the network definition) by:
  
      ```python
      variables = tf.contrib.framework.get_model_variables()
      conv_weight_variables = tf.contrib.framework.filter_variables(
          variables,
          include_patterns=['Conv'],
          exclude_patterns=['biases', 'Logits'])
      ```
  
      Args:
        var_list: list of variables.
        include_patterns: list of regular expressions to include. Defaults to None,
          which means all variables are selected according to the include rules. A
          variable is included if it matches any of the include_patterns.
        exclude_patterns: list of regular expressions to exclude. Defaults to None,
          which means all variables are selected according to the exclude rules. A
          variable is excluded if it matches any of the exclude_patterns.
        reg_search: boolean. If True (default), performs re.search to find matches
          (i.e. pattern can match any substring of the variable name). If False,
          performs re.match (i.e. regexp should match from the beginning of the
          variable name).
  
      Returns:
        filtered list of variables.
      """
      if reg_search:
          reg_exp_func = re.search
      else:
          reg_exp_func = re.match
  
      # First include variables.
      if include_patterns is None:
          included_variables = list(var_list)
      else:
          included_variables = []
          for var in var_list:
              if any(
                  reg_exp_func(ptrn, var.name)
                  for ptrn in include_patterns
              ):
                  included_variables.append(var)
  
      # Afterwards, exclude variables.
      if exclude_patterns is None:
          filtered_variables = included_variables
      else:
          filtered_variables = []
          for var in included_variables:
              if not any(
                  reg_exp_func(ptrn, var.name)
                  for ptrn in exclude_patterns
              ):
                  filtered_variables.append(var)
  
      return filtered_variables
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import re
  from .arg_scope import add_arg_scope
  from tensorflow.core.protobuf import saver_pb2
  from tensorflow.python import pywrap_tensorflow
  from tensorflow.python.framework import device
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import resource_loader
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.training import saver
  from tensorflow.python.training import training_util
  from tensorflow.python.util.deprecation import deprecated
label_desc: Use image node_id 24 for calling a global function with example usage: filter_variables(var_list, include_patterns, exclude_patterns, reg_search) and returns: filtered_variables