code: def inq_affine(
      inp,
      n_outmaps,
      base_axis=1,
      num_bits=4,
      inq_iterations=(),
      selection_algorithm="random",
      seed=-1,
      w_init=None,
      i_init=None,
      b_init=None,
      fix_parameters=False,
      rng=None,
      with_bias=True,
  ):
      """Incremental Network Quantization Affine Layer
  
      During training, the weights are sequentially quantized to power-of-two
      values, which allows the training of a multiplierless network.
  
      Using `inq_iterations`, one can specify after how many forward passes
      half of the learnable weights are fixed and quantized to powers-of-two.
      After reaching the last value in `inq_iterations`, all weights are fixed.
  
      For more details, please refer to the reference.
  
      Reference:
      Zhou A, Yao A, Guo Y, Xu L, Chen Y. Incremental network quantization:
      Towards lossless CNNs with low-precision weights.
      <https://arxiv.org/abs/1702.03044>
  
      Args:
          inp (~nnabla.Variable): Input N-D array with shape (:math:`M_0 \\times \ldots \\times M_{B-1} \\times D_B \\times \ldots \\times D_N`). Dimensions before and after base_axis are flattened as if it was a matrix.
          n_outmaps (int or :obj:`tuple` of :obj:`int`): Number of output neurons per data.
          base_axis (int): Dimensions up to `base_axis` are treated as the sample dimensions.
          quantize_zero_to (float): Input value at zero is quantized to this value.
          num_bits (int): Number of bits per weight. Value has to be larger than 1 as one bit is already used to code the value "0"
          inq_iterations (tuple of int): Tuple of iteration numbers at which we fix half of the weights.
          selection_algorithm (str): Chooses algorithm that is used to decide which weights are fixed. ("largest_abs" ... fix weights with largest absolute value, "random" ... fix weights randomly)
          seed (int): Random seed for INQ algorithm
          w_init (:obj:`nnabla.initializer.BaseInitializer` or :obj:`numpy.ndarray`): Initializer for weight. By default, it is initialized with :obj:`nnabla.initializer.UniformInitializer` within the range determined by :obj:`nnabla.initializer.calc_uniform_lim_glorot`.
          i_init (:obj:`nnabla.initializer.BaseInitializer` or :obj:`numpy.ndarray`): Initializer for indicators (0 ... learnable, 1 ... fixed). By default, it is initialized with zeros.
          b_init (:obj:`nnabla.initializer.BaseInitializer` or :obj:`numpy.ndarray`): Initializer for bias. By default, it is initialized with zeros if `with_bias` is `True`.
          fix_parameters (bool): When set to `True`, the weight and bias will not be updated.
          rng (numpy.random.RandomState): Random generator for Initializer.
          with_bias (bool): Specify whether to include the bias term.
  
      Returns:
          :class:`~nnabla.Variable`
  
      """
      if not hasattr(n_outmaps, "__iter__"):
          n_outmaps = [n_outmaps]
      n_outmaps = list(n_outmaps)
      n_outmap = int(np.prod(n_outmaps))
      if w_init is None:
          fan_in = np.prod(inp.shape[base_axis:])
          w_init = UniformInitializer(
              calc_uniform_lim_glorot(fan_in, n_outmap), rng=rng
          )
      if i_init is None:
          fan_in = np.prod(inp.shape[base_axis:])
          i_init = ConstantInitializer()
      if b_init is None:
          b_init = ConstantInitializer()
      w = get_parameter_or_create(
          "W",
          [int(np.prod(inp.shape[base_axis:]))] + n_outmaps,
          w_init,
          True,
          not fix_parameters,
      )
      i = get_parameter_or_create(
          "I",
          [int(np.prod(inp.shape[base_axis:]))] + n_outmaps,
          i_init,
          False,
      )
      b = None
      if with_bias:
          b = get_parameter_or_create(
              "b", n_outmaps, b_init, True, not fix_parameters
          )
      return F.inq_affine(
          inp,
          w,
          i,
          b,
          base_axis,
          num_bits,
          inq_iterations,
          selection_algorithm,
          seed,
      )
  
imports: from six import exec_
  import numpy
  import nnabla
  import nnabla.functions
  from nnabla.parameter import get_parameter_or_create, get_parameter
  from nnabla.initializer import calc_uniform_lim_glorot, ConstantInitializer, NormalInitializer, UniformInitializer, WeightNormalizationScaleInitializer
label_desc: Use image node_id 6 for calling a global function with example usage: inq_affine(inp, n_outmaps, base_axis, num_bits, inq_iterations, selection_algorithm, seed, w_init, i_init, b_init, fix_parameters, rng, with_bias) and returns: F