jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def create_loss_function(self, is_regression):
        with tf.compat.v1.variable_scope('loss') as scope:
            self.print_ext('Creating loss function and summaries')
            if is_regression:
                prediction = tf.squeeze(tf.cast(self.net.current_V, tf.float32))
                labels = tf.squeeze(self.net.labels)
                
                mse = tf.losses.mean_squared_error(labels, prediction, scope='loss')
                
                total_error = tf.reduce_sum(tf.square(tf.subtract(labels, tf.reduce_mean(labels))))
                unexplained_error = tf.reduce_sum(tf.square(tf.subtract(labels, prediction)))
                R_squared = tf.subtract(float(1), tf.divide(unexplained_error, total_error))
                
                tf.add_to_collection('losses', mse)
                tf.summary.scalar('loss', mse)

                self.max_r2_train = tf.Variable(tf.zeros([]), name="max_r2_train")
                self.max_r2_test = tf.Variable(tf.zeros([]), name="max_r2_test")
                
                max_r2 = tf.cond(self.net.is_training, lambda: tf.assign(self.max_r2_train, tf.maximum(self.max_r2_train, R_squared)), lambda: tf.assign(self.max_r2_test, tf.maximum(self.max_r2_test, R_squared)))
                tf.summary.scalar('max_r2', max_r2)
                tf.summary.scalar('accuracy', R_squared)

                self.reports['r2'] = R_squared
                self.reports['max r2'] = max_r2
                self.reports['mse'] = mse
            else:

                cross_entropy = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=self.net.current_V, labels=self.net.labels))

                correct_prediction = tf.cast(tf.equal(tf.argmax(self.net.current_V, 1), self.net.labels), tf.float32)
                accuracy = tf.reduce_mean(correct_prediction)

                # we have 2 variables that will keep track of the best accuracy obtained in training/testing batch
                # SHOULD ONLY BE USED IF test_batch_size == ALL TEST SAMPLES
                
                self.max_acc_train = tf.Variable(tf.zeros([]), name="max_acc_train")
                self.max_acc_test = tf.Variable(tf.zeros([]), name="max_acc_test")
                max_acc = tf.cond(self.net.is_training, lambda: tf.assign(self.max_acc_train, tf.maximum(self.max_acc_train, accuracy)), lambda: tf.assign(self.max_acc_test, tf.maximum(self.max_acc_test, accuracy)))

                tf.add_to_collection('losses', cross_entropy)
                tf.summary.scalar('accuracy', accuracy)
                tf.summary.scalar('max_accuracy', max_acc)
                tf.summary.scalar('cross_entropy', cross_entropy)
                
                self.reports['accuracy'] = accuracy
                self.reports['max acc.'] = max_acc
                self.reports['cross_entropy'] = cross_entropy
//  [python]
def iou_regression(configs,
                   v_mask,
                   q_mask,
                   vfeats0,
                   qfeats0,
                   drop_rate,
                   mask,
                   dx,
                   dy,
                   y1,
                   y2,
                   reuse=None,
                   name='iou_regression'):
    with tf.variable_scope(name, reuse=tf.AUTO_REUSE):

        outputs = tf.expand_dims(vfeats0, 1)
        # mask = tf.expand_dims(mask, -1)

        selected_feature = tf.multiply(mask, outputs)
        # print(get_shape_list(selected_feature))
        shape = get_shape_list(selected_feature)
        selected_feature = conv1d(tf.reshape(selected_feature,
                                             [-1, shape[-2], shape[-1]]),
                                  dim=shape[-1],
                                  use_bias=True,
                                  reuse=False,
                                  name='dense')
        selected_feature = tf.reshape(selected_feature, shape)
        selected_feature_reduce = tf.reduce_sum(selected_feature, 2)
        mask_reduce = tf.reduce_sum(mask, 2)
        inputs = tf.div(selected_feature_reduce, mask_reduce)

        x_index = tf.cast(tf.reshape(tf.arg_max(y1, 1), [-1, 1]), tf.int32)
        y_index = tf.cast(tf.reshape(tf.arg_max(y2, 1), [-1, 1]), tf.int32)

        union = (tf.minimum(dx, x_index), tf.maximum(dy, y_index))

        inter = (tf.maximum(dx, x_index), tf.minimum(dy, y_index))

        iou = tf.maximum(
            tf.cast((inter[1] - inter[0]), tf.float32) / tf.cast(
                (union[1] - union[0]), tf.float32), 0.0)

        output = tf.layers.dense(inputs, 128, activation=tf.nn.relu)
        logits = tf.squeeze(
            tf.layers.dense(output, 1, activation=tf.nn.sigmoid), -1)

        reg_loss = tf.losses.mean_squared_error(labels=iou, predictions=logits)

        p_x = tf.batch_gather(dx, tf.expand_dims(tf.arg_max(logits, -1), -1))
        p_y = tf.batch_gather(dy, tf.expand_dims(tf.arg_max(logits, -1), -1))

        offset_loss = 0

        return reg_loss, offset_loss, [dx, dy], p_x, p_y
//  [python]
def iou_regression(configs,
                   v_mask,
                   q_mask,
                   vfeats0,
                   qfeats0,
                   drop_rate,
                   mask,
                   dx,
                   dy,
                   y1,
                   y2,
                   reuse=None,
                   name='iou_regression'):
    with tf.variable_scope(name, reuse=tf.AUTO_REUSE):

        outputs = tf.expand_dims(vfeats0, 1)
        # mask = tf.expand_dims(mask, -1)

        selected_feature = tf.multiply(mask, outputs)
        # print(get_shape_list(selected_feature))
        shape = get_shape_list(selected_feature)
        selected_feature = conv1d(tf.reshape(selected_feature,
                                             [-1, shape[-2], shape[-1]]),
                                  dim=shape[-1],
                                  use_bias=True,
                                  reuse=False,
                                  name='dense')
        selected_feature = tf.reshape(selected_feature, shape)
        selected_feature_reduce = tf.reduce_sum(selected_feature, 2)
        mask_reduce = tf.reduce_sum(mask, 2)
        inputs = tf.divide(selected_feature_reduce, mask_reduce)

        x_index = tf.cast(tf.reshape(tf.arg_max(y1, 1), [-1, 1]), tf.int32)
        y_index = tf.cast(tf.reshape(tf.arg_max(y2, 1), [-1, 1]), tf.int32)

        union = (tf.minimum(dx, x_index), tf.maximum(dy, y_index))

        inter = (tf.maximum(dx, x_index), tf.minimum(dy, y_index))

        iou = tf.maximum(
            tf.cast((inter[1] - inter[0]), tf.float32) / tf.cast(
                (union[1] - union[0]), tf.float32), 0.0)

        output = tf.layers.dense(inputs, 128, activation=tf.nn.relu)
        logits = tf.squeeze(
            tf.layers.dense(output, 1, activation=tf.nn.sigmoid), -1)

        reg_loss = tf.losses.mean_squared_error(labels=iou, predictions=logits)

        p_x = tf.batch_gather(dx, tf.expand_dims(tf.arg_max(logits, -1), -1))
        p_y = tf.batch_gather(dy, tf.expand_dims(tf.arg_max(logits, -1), -1))

        offset_loss = 0

        return reg_loss, offset_loss, [dx, dy], p_x, p_y
//  [python]
def drop_connect(inputs, is_training, drop_connect_rate):
  """Apply drop connect.

  Args:
    inputs: `Tensor` input tensor.
    is_training: `bool` if True, the model is in training mode.
    drop_connect_rate: `float` drop connect rate.

  Returns:
    A output tensor, which should have the same shape as input.
  """
  if not is_training or drop_connect_rate is None or drop_connect_rate == 0:
    return inputs

  keep_prob = 1.0 - drop_connect_rate
  batch_size = tf.shape(inputs)[0]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
  binary_tensor = tf.floor(random_tensor)
  output = tf.div(inputs, keep_prob) * binary_tensor
  return output
//  [python]
def drop_connect(inputs, is_training, drop_connect_rate):
  """Apply drop connect.

  Args:
    inputs: `Tensor` input tensor.
    is_training: `bool` if True, the model is in training mode.
    drop_connect_rate: `float` drop connect rate.

  Returns:
    A output tensor, which should have the same shape as input.
  """
  if not is_training or drop_connect_rate is None or drop_connect_rate == 0:
    return inputs

  keep_prob = 1.0 - drop_connect_rate
  batch_size = tf.shape(inputs)[0]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
  binary_tensor = tf.floor(random_tensor)
  output = tf.divide(inputs, keep_prob) * binary_tensor
  return output
//  [python]
def apply_gradients(self, gradvars, *args, **kwargs):
        v_list = [tf.norm(tensor=v, ord=2) for _, v in gradvars]
        g_list = [tf.norm(tensor=g, ord=2) if g is not None else 0.0 for g, _ in gradvars]
        v_norms = tf.stack(v_list)
        g_norms = tf.stack(g_list)
        zeds = tf.zeros_like(v_norms)
        # assign epsilon if weights or grads = 0, to avoid division by zero
        # also prevent biases to get stuck at initialization (0.)
        cond = tf.logical_and(tf.not_equal(v_norms, zeds), tf.not_equal(g_norms, zeds))
        true_vals = tf.scalar_mul(self._eta, tf.div(v_norms, g_norms))
        false_vals = tf.fill(tf.shape(v_norms), self._epsilon)
        larc_local_lr = tf.where(cond, true_vals, false_vals)
        if self._clip:
            ones = tf.ones_like(v_norms)
            lr = tf.fill(tf.shape(v_norms), self._learning_rate)
            # We need gradients to compute local learning rate,
            # so compute_gradients from initial optimizer have to called
            # for which learning rate is already fixed
            # We then have to scale the gradients instead of the learning rate.
            larc_local_lr = tf.minimum(tf.div(larc_local_lr, lr), ones)
        gradvars = [
            (tf.multiply(larc_local_lr[i], g), v) if g is not None else (None, v)
            for i, (g, v) in enumerate(gradvars)
        ]
        return self._optimizer.apply_gradients(gradvars, *args, **kwargs)
//  [python]
def apply_gradients(self, gradvars, *args, **kwargs):
        v_list = [tf.norm(tensor=v, ord=2) for _, v in gradvars]
        g_list = [tf.norm(tensor=g, ord=2) if g is not None else 0.0 for g, _ in gradvars]
        v_norms = tf.stack(v_list)
        g_norms = tf.stack(g_list)
        zeds = tf.zeros_like(v_norms)
        # assign epsilon if weights or grads = 0, to avoid division by zero
        # also prevent biases to get stuck at initialization (0.)
        cond = tf.logical_and(tf.not_equal(v_norms, zeds), tf.not_equal(g_norms, zeds))
        true_vals = tf.scalar_mul(self._eta, tf.divide(v_norms, g_norms))
        false_vals = tf.fill(tf.shape(v_norms), self._epsilon)
        larc_local_lr = tf.where(cond, true_vals, false_vals)
        if self._clip:
            ones = tf.ones_like(v_norms)
            lr = tf.fill(tf.shape(v_norms), self._learning_rate)
            # We need gradients to compute local learning rate,
            # so compute_gradients from initial optimizer have to called
            # for which learning rate is already fixed
            # We then have to scale the gradients instead of the learning rate.
            larc_local_lr = tf.minimum(tf.divide(larc_local_lr, lr), ones)
        gradvars = [
            (tf.multiply(larc_local_lr[i], g), v) if g is not None else (None, v)
            for i, (g, v) in enumerate(gradvars)
        ]
        return self._optimizer.apply_gradients(gradvars, *args, **kwargs)
//  [python]
def make_softmax_layer(V, axis=1, name=None):
    V = tf.cast(V, tf.float32)
    with tf.variable_scope(name, default_name='Softmax') as scope:
        max_value = tf.reduce_max(V, axis=axis, keep_dims=True)
        exp = tf.exp(tf.subtract(V, max_value))
        prob = tf.div(exp, tf.reduce_sum(exp, axis=axis, keep_dims=True))
        return prob
//  [python]
def make_softmax_layer(V, axis=1, name=None):
    V = tf.cast(V, tf.float32)
    with tf.variable_scope(name, default_name='Softmax') as scope:
        max_value = tf.reduce_max(V, axis=axis, keep_dims=True)
        exp = tf.exp(tf.subtract(V, max_value))
        prob = tf.divide(exp, tf.reduce_sum(exp, axis=axis, keep_dims=True))
        return prob
//  [python]
def compute_cost(self):
        losses = tf.contrib.legacy_seq2seq.sequence_loss_by_example(
            [tf.reshape(self.pred, [-1], name='reshape_pred')],
            [tf.reshape(self.ys, [-1], name='reshape_target')],
            [tf.ones([self.batch_size * self.n_steps], dtype=tf.float32)],
            average_across_timesteps=True,
            softmax_loss_function=self.ms_error,
            name='losses'
        )
        with tf.name_scope('average_cost'):
            self.cost = tf.div(
                tf.reduce_sum(losses, name='losses_sum'),
                self.batch_size,
                name='average_cost')
            tf.summary.scalar('cost', self.cost)
//  [python]
def compute_cost(self):
        losses = tf.contrib.legacy_seq2seq.sequence_loss_by_example(
            [tf.reshape(self.pred, [-1], name='reshape_pred')],
            [tf.reshape(self.ys, [-1], name='reshape_target')],
            [tf.ones([self.batch_size * self.n_steps], dtype=tf.float32)],
            average_across_timesteps=True,
            softmax_loss_function=self.ms_error,
            name='losses'
        )
        with tf.name_scope('average_cost'):
            self.cost = tf.divide(
                tf.reduce_sum(losses, name='losses_sum'),
                self.batch_size,
                name='average_cost')
            tf.summary.scalar('cost', self.cost)
//  [python]
def _create_average_ops(params):
  """Build moving average ops."""
  tf.logging.info('Creating moving average ops')

  with tf.variable_scope('moving_average'):
    moving_average_step = tf.get_variable(
        'step', [], dtype=tf.float32, trainable=False)

  all_vars = tf.trainable_variables()
  average_pairs = []
  with tf.variable_scope('average'):
    for v in all_vars:
      v_name = utils.strip_var_name(v.name)
      average_v = tf.get_variable(
          v_name, shape=v.shape, dtype=v.dtype,
          initializer=tf.initializers.zeros(), trainable=False)
      average_pairs.append([v, average_v])

  with tf.control_dependencies([tf.assign_add(moving_average_step, 1.0)]):
    update_average_op = []
    mu = tf.cond(
        tf.greater(moving_average_step, params.start_moving_average),
        lambda: tf.div(1., moving_average_step - params.start_moving_average),
        lambda: 0.)
    for v, average_v in average_pairs:
      new_average = mu * v + (1 - mu) * average_v
      with tf.control_dependencies([new_average]):
        update_average_op.append(tf.assign(average_v, new_average))

  assert len(average_pairs) == len(all_vars)
  use_average_op = []
  for i in range(len(average_pairs)):
    v, average_v = average_pairs[i]
    use_average_op.append(tf.assign(v, average_v))

  return update_average_op, mu, use_average_op
//  [python]
def _create_average_ops(params):
  """Build moving average ops."""
  tf.logging.info('Creating moving average ops')

  with tf.variable_scope('moving_average'):
    moving_average_step = tf.get_variable(
        'step', [], dtype=tf.float32, trainable=False)

  all_vars = tf.trainable_variables()
  average_pairs = []
  with tf.variable_scope('average'):
    for v in all_vars:
      v_name = utils.strip_var_name(v.name)
      average_v = tf.get_variable(
          v_name, shape=v.shape, dtype=v.dtype,
          initializer=tf.initializers.zeros(), trainable=False)
      average_pairs.append([v, average_v])

  with tf.control_dependencies([tf.assign_add(moving_average_step, 1.0)]):
    update_average_op = []
    mu = tf.cond(
        tf.greater(moving_average_step, params.start_moving_average),
        lambda: tf.divide(1., moving_average_step - params.start_moving_average),
        lambda: 0.)
    for v, average_v in average_pairs:
      new_average = mu * v + (1 - mu) * average_v
      with tf.control_dependencies([new_average]):
        update_average_op.append(tf.assign(average_v, new_average))

  assert len(average_pairs) == len(all_vars)
  use_average_op = []
  for i in range(len(average_pairs)):
    v, average_v = average_pairs[i]
    use_average_op.append(tf.assign(v, average_v))

  return update_average_op, mu, use_average_op
//  [python]
def _network_template(self, state):
    """Builds the convolutional network used to compute the agent's Q-values.

    Args:
      state: `tf.Tensor`, contains the agent's current state.

    Returns:
      net: _network_type object containing the tensors output by the network.
    """
    net = tf.cast(state, tf.float32)
    net = tf.div(net, 255.)
    net = slim.conv2d(net, 32, [8, 8], stride=4)
    net = slim.conv2d(net, 64, [4, 4], stride=2)
    net = slim.conv2d(net, 64, [3, 3], stride=1)
    net = slim.flatten(net)
    net = fully_connected(net, 512, distribution=self.noise_distribution,
                          scope='fully_connected')
    q_values = fully_connected(net, self.num_actions,
                               activation_fn=None,
                               distribution=self.noise_distribution,
                               scope='fully_connected_1')
    return self._get_network_type()(q_values)
//  [python]
def _network_template(self, state):
    """Builds the convolutional network used to compute the agent's Q-values.

    Args:
      state: `tf.Tensor`, contains the agent's current state.

    Returns:
      net: _network_type object containing the tensors output by the network.
    """
    net = tf.cast(state, tf.float32)
    net = tf.divide(net, 255.)
    net = slim.conv2d(net, 32, [8, 8], stride=4)
    net = slim.conv2d(net, 64, [4, 4], stride=2)
    net = slim.conv2d(net, 64, [3, 3], stride=1)
    net = slim.flatten(net)
    net = fully_connected(net, 512, distribution=self.noise_distribution,
                          scope='fully_connected')
    q_values = fully_connected(net, self.num_actions,
                               activation_fn=None,
                               distribution=self.noise_distribution,
                               scope='fully_connected_1')
    return self._get_network_type()(q_values)
//  [python]
def call(self, state):
        """Calculates the distribution of Q-values using the input state tensor."""
        net = tf.cast(state, tf.float32)
        net = tf.div(net, 255.0)
        net = self.conv1(net)
        net = self.conv2(net)
        net = self.conv3(net)
        net = self.flatten(net)
        net = self.dense1(net)
        net = self.dense2(net)
        logits = tf.reshape(net, [-1, self.num_actions, self.num_atoms])
        probabilities = tf.keras.activations.softmax(tf.zeros_like(logits))
        q_values = tf.reduce_mean(logits, axis=2)
        return QuantileNetworkType(q_values, logits, probabilities)
//  [python]
def call(self, state):
        """Calculates the distribution of Q-values using the input state tensor."""
        net = tf.cast(state, tf.float32)
        net = tf.divide(net, 255.0)
        net = self.conv1(net)
        net = self.conv2(net)
        net = self.conv3(net)
        net = self.flatten(net)
        net = self.dense1(net)
        net = self.dense2(net)
        logits = tf.reshape(net, [-1, self.num_actions, self.num_atoms])
        probabilities = tf.keras.activations.softmax(tf.zeros_like(logits))
        q_values = tf.reduce_mean(logits, axis=2)
        return QuantileNetworkType(q_values, logits, probabilities)
//  [python]
def drop_connect(inputs, is_training, survival_prob):
    """Drop the entire conv with given survival probability."""
    # "Deep Networks with Stochastic Depth", https://arxiv.org/pdf/1603.09382.pdf
    if not is_training:
        return inputs

    # Compute tensor.
    batch_size = tf.shape(inputs)[0]
    random_tensor = survival_prob
    random_tensor += tf.random_uniform([batch_size,
                                       1, 1, 1], dtype=inputs.dtype)
    binary_tensor = tf.floor(random_tensor)
    # Unlike conventional way that multiply survival_prob at test time, here we
    # divide survival_prob at training time, such that no addition compute is
    # needed at test time.
    output = tf.div(inputs, survival_prob) * binary_tensor
    return output
//  [python]
def drop_connect(inputs, is_training, survival_prob):
    """Drop the entire conv with given survival probability."""
    # "Deep Networks with Stochastic Depth", https://arxiv.org/pdf/1603.09382.pdf
    if not is_training:
        return inputs

    # Compute tensor.
    batch_size = tf.shape(inputs)[0]
    random_tensor = survival_prob
    random_tensor += tf.random_uniform([batch_size,
                                       1, 1, 1], dtype=inputs.dtype)
    binary_tensor = tf.floor(random_tensor)
    # Unlike conventional way that multiply survival_prob at test time, here we
    # divide survival_prob at training time, such that no addition compute is
    # needed at test time.
    output = tf.divide(inputs, survival_prob) * binary_tensor
    return output
//  [python]
def drop_connect(inputs, is_training, drop_connect_rate):
    """Apply drop connect."""
    if not is_training:
        return inputs

    # Compute keep_prob
    # TODO(tanmingxing): add support for training progress.
    keep_prob = 1.0 - drop_connect_rate

    # Compute drop_connect tensor
    batch_size = tf.shape(inputs)[0]
    random_tensor = keep_prob
    random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
    binary_tensor = tf.floor(random_tensor)
    output = tf.div(inputs, keep_prob) * binary_tensor
    return output
//  [python]
def drop_connect(inputs, is_training, drop_connect_rate):
    """Apply drop connect."""
    if not is_training:
        return inputs

    # Compute keep_prob
    # TODO(tanmingxing): add support for training progress.
    keep_prob = 1.0 - drop_connect_rate

    # Compute drop_connect tensor
    batch_size = tf.shape(inputs)[0]
    random_tensor = keep_prob
    random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
    binary_tensor = tf.floor(random_tensor)
    output = tf.divide(inputs, keep_prob) * binary_tensor
    return output
//  [python]
def drop_path(x, keep_prob):
  """Drops out a whole example hiddenstate with the specified probability."""

  batch_size = tf.shape(x)[0]
  noise_shape = [batch_size, 1, 1, 1]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform(noise_shape, dtype=tf.float32)
  binary_tensor = tf.floor(random_tensor)
  x = tf.div(x, keep_prob) * binary_tensor

  return x
//  [python]
def drop_path(x, keep_prob):
  """Drops out a whole example hiddenstate with the specified probability."""

  batch_size = tf.shape(x)[0]
  noise_shape = [batch_size, 1, 1, 1]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform(noise_shape, dtype=tf.float32)
  binary_tensor = tf.floor(random_tensor)
  x = tf.divide(x, keep_prob) * binary_tensor

  return x
//  [python]
def _network_template(self, state):
    """Builds a convolutional network that outputs Q-value distributions.

    Args:
      state: `tf.Tensor`, contains the agent's current state.

    Returns:
      net: _network_type object containing the tensors output by the network.
    """
    net = tf.cast(state, tf.float32)
    net = tf.div(net, 255.)
    net = slim.conv2d(
        net, int(32 * self.network_size_expansion), [8, 8], stride=4)
    net = slim.conv2d(
        net, int(64 * self.network_size_expansion), [4, 4], stride=2)
    net = slim.conv2d(
        net, int(64 * self.network_size_expansion), [3, 3], stride=1)
    net = slim.flatten(net)
    net = slim.fully_connected(net, int(512 * self.network_size_expansion))

    q_values = []
    for _ in range(self.number_of_gammas):
      gamma_q_value = slim.fully_connected(
          net, self.num_actions, activation_fn=None)
      q_values.append(gamma_q_value)

    # Estimate the hyperbolic discounted q-values
    hyp_q_value = agent_utils.integrate_q_values(q_values,
                                                 self.integral_estimate,
                                                 self.eval_gammas,
                                                 self.number_of_gammas,
                                                 self.gammas)

    return self._get_network_type()(hyp_q_value, q_values)
//  [python]
def _network_template(self, state):
    """Builds a convolutional network that outputs Q-value distributions.

    Args:
      state: `tf.Tensor`, contains the agent's current state.

    Returns:
      net: _network_type object containing the tensors output by the network.
    """
    net = tf.cast(state, tf.float32)
    net = tf.divide(net, 255.)
    net = slim.conv2d(
        net, int(32 * self.network_size_expansion), [8, 8], stride=4)
    net = slim.conv2d(
        net, int(64 * self.network_size_expansion), [4, 4], stride=2)
    net = slim.conv2d(
        net, int(64 * self.network_size_expansion), [3, 3], stride=1)
    net = slim.flatten(net)
    net = slim.fully_connected(net, int(512 * self.network_size_expansion))

    q_values = []
    for _ in range(self.number_of_gammas):
      gamma_q_value = slim.fully_connected(
          net, self.num_actions, activation_fn=None)
      q_values.append(gamma_q_value)

    # Estimate the hyperbolic discounted q-values
    hyp_q_value = agent_utils.integrate_q_values(q_values,
                                                 self.integral_estimate,
                                                 self.eval_gammas,
                                                 self.number_of_gammas,
                                                 self.gammas)

    return self._get_network_type()(hyp_q_value, q_values)
//  [python]
def compute_cost(self):
        losses = tensorflow.leagcy_seq2seq.sequence_loss_by_example(
            [tf.reshape(self.pred, [-1], name='reshape_pred')],
            [tf.reshape(self.ys, [-1], name='reshape_target')],
            [tf.ones([self.batch_size * self.n_steps], dtype=tf.float32)],
            average_across_timesteps=True,
            softmax_loss_function=self.ms_error,
            name='losses'
        )
        with tf.name_scope('average_cost'):
            self.cost = tf.div(
                tf.reduce_sum(losses, name='losses_sum'),
                self.batch_size,
                name='average_cost')
            tf.scalar_summary('cost', self.cost)
//  [python]
def compute_cost(self):
        losses = tensorflow.leagcy_seq2seq.sequence_loss_by_example(
            [tf.reshape(self.pred, [-1], name='reshape_pred')],
            [tf.reshape(self.ys, [-1], name='reshape_target')],
            [tf.ones([self.batch_size * self.n_steps], dtype=tf.float32)],
            average_across_timesteps=True,
            softmax_loss_function=self.ms_error,
            name='losses'
        )
        with tf.name_scope('average_cost'):
            self.cost = tf.divide(
                tf.reduce_sum(losses, name='losses_sum'),
                self.batch_size,
                name='average_cost')
            tf.scalar_summary('cost', self.cost)
//  [python]
def reduce_nanmean(tensor, axes=None, keepdims=False, name=None):
  """Take the mean of a tensor, skipping NaNs.

  Args:
    tensor: tensor to reduce.
    axes: optional list of axes to reduce.
    keepdims: optional boolean indicating whether to keep dimensions or not.
    name: optional op name.

  Returns:
    tf.Tensor with reduce values.
  """
  masked = tf.is_nan(tensor)
  valid_tensor = tf.where(masked, tf.zeros_like(tensor), tensor)
  total = tf.reduce_sum(valid_tensor, axes, keepdims=keepdims)
  counts = tf.reduce_sum(tf.cast(tf.logical_not(masked), tensor.dtype),
                         axes, keepdims=keepdims)
  return tf.div(total, counts, name=name)
//  [python]
def reduce_nanmean(tensor, axes=None, keepdims=False, name=None):
  """Take the mean of a tensor, skipping NaNs.

  Args:
    tensor: tensor to reduce.
    axes: optional list of axes to reduce.
    keepdims: optional boolean indicating whether to keep dimensions or not.
    name: optional op name.

  Returns:
    tf.Tensor with reduce values.
  """
  masked = tf.is_nan(tensor)
  valid_tensor = tf.where(masked, tf.zeros_like(tensor), tensor)
  total = tf.reduce_sum(valid_tensor, axes, keepdims=keepdims)
  counts = tf.reduce_sum(tf.cast(tf.logical_not(masked), tensor.dtype),
                         axes, keepdims=keepdims)
  return tf.divide(total, counts, name=name)
//  [python]
def call(self, state):
    """Calculates the distribution of Q-values using the input state tensor."""
    net = tf.cast(state, tf.float32)
    net = tf.div(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    net = self.dense2(net)
    logits = tf.reshape(net, [-1, self.num_actions, self.num_atoms])
    probabilities = tf.keras.activations.softmax(tf.zeros_like(logits))
    q_values = tf.reduce_mean(logits, axis=2)
    return QuantileNetworkType(q_values, logits, probabilities)
//  [python]
def call(self, state):
    """Calculates the distribution of Q-values using the input state tensor."""
    net = tf.cast(state, tf.float32)
    net = tf.divide(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    net = self.dense2(net)
    logits = tf.reshape(net, [-1, self.num_actions, self.num_atoms])
    probabilities = tf.keras.activations.softmax(tf.zeros_like(logits))
    q_values = tf.reduce_mean(logits, axis=2)
    return QuantileNetworkType(q_values, logits, probabilities)
//  [python]
def tensorflow_angular_error_from_vector(v_true, v_pred):
    """Tensorflow method to calculate angular loss from 3D vector."""
    with tf.name_scope('mean_angular_error'):
        v_true_norm = tf.sqrt(tf.reduce_sum(tf.square(v_true), axis=1))
        v_pred_norm = tf.sqrt(tf.reduce_sum(tf.square(v_pred), axis=1))

        sim = tf.div(tf.reduce_sum(tf.multiply(v_true, v_pred), axis=1),
                     tf.multiply(v_true_norm, v_pred_norm))

        # Floating point precision can cause sim values to be slightly outside of
        # [-1, 1] so we clip values
        sim = tf.clip_by_value(sim, -1.0 + 1e-6, 1.0 - 1e-6)

        ang = tf.scalar_mul(radians_to_degrees, tf.acos(sim))
        return tf.reduce_mean(ang)
//  [python]
def tensorflow_angular_error_from_vector(v_true, v_pred):
    """Tensorflow method to calculate angular loss from 3D vector."""
    with tf.name_scope('mean_angular_error'):
        v_true_norm = tf.sqrt(tf.reduce_sum(tf.square(v_true), axis=1))
        v_pred_norm = tf.sqrt(tf.reduce_sum(tf.square(v_pred), axis=1))

        sim = tf.divide(tf.reduce_sum(tf.multiply(v_true, v_pred), axis=1),
                     tf.multiply(v_true_norm, v_pred_norm))

        # Floating point precision can cause sim values to be slightly outside of
        # [-1, 1] so we clip values
        sim = tf.clip_by_value(sim, -1.0 + 1e-6, 1.0 - 1e-6)

        ang = tf.scalar_mul(radians_to_degrees, tf.acos(sim))
        return tf.reduce_mean(ang)
//  [python]
def max_scoring_span(start_scores, end_scores, max_length, no_answer_bias=0):
  """Compute max scoring span, using the sum of start and end scores.

  Args:
    start_scores: <float32> [batch_size, seq_len]
    end_scores: <float32> [batch_size, seq_len]
    max_length: <int32> Max answer length.
    no_answer_bias: <float32> Log-odds threshold for "no-answer" selection. I.e.
      if log p(span=i,j)/p(span=NULL) > no_answer_bias, then select i, j as the
      span, and NULL otherwise.

  Returns:
    start: <int32> [batch_size]
    end: <int32> [batch_size]
  """
  # Create sparse tensor of size [seq_len].
  seq_len = tensor_utils.shape(start_scores, -1)
  no_answer_bias = tf.scatter_nd([[0]], [no_answer_bias], [seq_len])
  no_answer_bias = tf.cast(no_answer_bias, tf.float32)

  # Apply bias to CLS token logits.
  no_answer_bias = tf.div(no_answer_bias, 2)
  start_scores += tf.expand_dims(no_answer_bias, 0)
  end_scores += tf.expand_dims(no_answer_bias, 0)

  # Compute outer sum, and mask to be upper triangular.
  # This gives a matrix of start[i] + end[j] scores, where j >= i.
  scores = tf.expand_dims(start_scores, 2) + tf.expand_dims(end_scores, 1)
  mask = (1 - tf.matrix_band_part(tf.ones_like(scores), 0, max_length - 1))
  scores -= mask * 1e-4

  def map_fn(inputs):
    flattened = tf.reshape(inputs, [-1])
    argmax = tf.argmax(flattened, output_type=tf.int32)
    indices = tensor_utils.unravel_index_2d(argmax, inputs.shape)
    score = flattened[argmax]
    return indices, score

  # Return i, j indices of max-scoring entry.
  with tf.device("/cpu"):
    endpoints, span_scores = tf.map_fn(
        fn=map_fn, elems=scores, dtype=(tf.int32, tf.float32))
  start = endpoints[:, 0]
  end = endpoints[:, 1]

  return start, end, span_scores
//  [python]
def max_scoring_span(start_scores, end_scores, max_length, no_answer_bias=0):
  """Compute max scoring span, using the sum of start and end scores.

  Args:
    start_scores: <float32> [batch_size, seq_len]
    end_scores: <float32> [batch_size, seq_len]
    max_length: <int32> Max answer length.
    no_answer_bias: <float32> Log-odds threshold for "no-answer" selection. I.e.
      if log p(span=i,j)/p(span=NULL) > no_answer_bias, then select i, j as the
      span, and NULL otherwise.

  Returns:
    start: <int32> [batch_size]
    end: <int32> [batch_size]
  """
  # Create sparse tensor of size [seq_len].
  seq_len = tensor_utils.shape(start_scores, -1)
  no_answer_bias = tf.scatter_nd([[0]], [no_answer_bias], [seq_len])
  no_answer_bias = tf.cast(no_answer_bias, tf.float32)

  # Apply bias to CLS token logits.
  no_answer_bias = tf.divide(no_answer_bias, 2)
  start_scores += tf.expand_dims(no_answer_bias, 0)
  end_scores += tf.expand_dims(no_answer_bias, 0)

  # Compute outer sum, and mask to be upper triangular.
  # This gives a matrix of start[i] + end[j] scores, where j >= i.
  scores = tf.expand_dims(start_scores, 2) + tf.expand_dims(end_scores, 1)
  mask = (1 - tf.matrix_band_part(tf.ones_like(scores), 0, max_length - 1))
  scores -= mask * 1e-4

  def map_fn(inputs):
    flattened = tf.reshape(inputs, [-1])
    argmax = tf.argmax(flattened, output_type=tf.int32)
    indices = tensor_utils.unravel_index_2d(argmax, inputs.shape)
    score = flattened[argmax]
    return indices, score

  # Return i, j indices of max-scoring entry.
  with tf.device("/cpu"):
    endpoints, span_scores = tf.map_fn(
        fn=map_fn, elems=scores, dtype=(tf.int32, tf.float32))
  start = endpoints[:, 0]
  end = endpoints[:, 1]

  return start, end, span_scores
//  [python]
def call(self, state):
    """Creates the output tensor/op given the input state tensor.

    See https://www.tensorflow.org/api_docs/python/tf/keras/Model for more
    information on this. Note that tf.keras.Model implements `call` which is
    wrapped by `__call__` function by tf.keras.Model.

    Args:
      state: Tensor, input tensor.

    Returns:
      collections.namedtuple, output ops (graph mode) or output tensors (eager).
    """
    net = tf.cast(state, tf.float32)
    net = tf.div(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    net = self.dense2(net)
    unordered_q_heads = tf.reshape(net, [-1, self.num_actions, self.num_heads])
    q_heads, q_values = combine_q_functions(
        unordered_q_heads, self._transform_strategy, **self._kwargs)
    return MultiHeadNetworkType(q_heads, unordered_q_heads, q_values)
//  [python]
def call(self, state):
    """Creates the output tensor/op given the input state tensor.

    See https://www.tensorflow.org/api_docs/python/tf/keras/Model for more
    information on this. Note that tf.keras.Model implements `call` which is
    wrapped by `__call__` function by tf.keras.Model.

    Args:
      state: Tensor, input tensor.

    Returns:
      collections.namedtuple, output ops (graph mode) or output tensors (eager).
    """
    net = tf.cast(state, tf.float32)
    net = tf.divide(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    net = self.dense2(net)
    unordered_q_heads = tf.reshape(net, [-1, self.num_actions, self.num_heads])
    q_heads, q_values = combine_q_functions(
        unordered_q_heads, self._transform_strategy, **self._kwargs)
    return MultiHeadNetworkType(q_heads, unordered_q_heads, q_values)
//  [python]
def call(self, state):
    """Creates the output tensor/op given the state tensor as input.

    See https://www.tensorflow.org/api_docs/python/tf/keras/Model for more
    information on this. Note that tf.keras.Model implements `call` which is
    wrapped by `__call__` function by tf.keras.Model.

    Parameters created here will have scope according to the `name` argument
    given at `.__init__()` call.

    Args:
      state: Tensor, input tensor.

    Returns:
      collections.namedtuple, output ops (graph mode) or output tensors (eager).
    """
    net = tf.cast(state, tf.float32)
    net = tf.div(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    return DQNNetworkType(self.dense2(net))
//  [python]
def call(self, state):
    """Creates the output tensor/op given the state tensor as input.

    See https://www.tensorflow.org/api_docs/python/tf/keras/Model for more
    information on this. Note that tf.keras.Model implements `call` which is
    wrapped by `__call__` function by tf.keras.Model.

    Parameters created here will have scope according to the `name` argument
    given at `.__init__()` call.

    Args:
      state: Tensor, input tensor.

    Returns:
      collections.namedtuple, output ops (graph mode) or output tensors (eager).
    """
    net = tf.cast(state, tf.float32)
    net = tf.divide(net, 255.)
    net = self.conv1(net)
    net = self.conv2(net)
    net = self.conv3(net)
    net = self.flatten(net)
    net = self.dense1(net)
    return DQNNetworkType(self.dense2(net))
//  [python]
def mean_pool(inputs, sequence_length=None, axis=1):
    '''
    the mean pool function. 
    inputs.shape = [batch_size, timestep_size, edim]
    sequence_length = [batch_size, 1]
    sequence_length = [[len(sequence)], [], ...]
    '''
    if sequence_length is None:
        return tf.reduce_mean(inputs, axis)
    else:
        return tf.div(tf.reduce_sum(inputs, axis), sequence_length)
//  [python]
def mean_pool(inputs, sequence_length=None, axis=1):
    '''
    the mean pool function. 
    inputs.shape = [batch_size, timestep_size, edim]
    sequence_length = [batch_size, 1]
    sequence_length = [[len(sequence)], [], ...]
    '''
    if sequence_length is None:
        return tf.reduce_mean(inputs, axis)
    else:
        return tf.divide(tf.reduce_sum(inputs, axis), sequence_length)
//  [python]
def loss(self):
        """
        Define loss to be optimized using margin based ranking loss.

        Returns:
            margin based ranking loss
        """
        log.info('Using margin based ranking loss')

        error = tf.subtract(self.train_predictions[:, 1], self.train_predictions[:, 0])
        error_plus_margin = tf.add(error, self.params['margin'])
        after_thresh = tf.maximum(error_plus_margin, 0)
        batch_size = tf.constant(self.params['batch_size'], dtype=tf.float32)

        loss = tf1.div(tf.reduce_sum(after_thresh), batch_size)
        l2 = tf.reduce_sum([tf.nn.l2_loss(var) for var in tf1.trainable_variables()])

        return tf.add(loss, tf.multiply(self.params['lambda'], l2))
//  [python]
def loss(self):
        """
        Define loss to be optimized using margin based ranking loss.

        Returns:
            margin based ranking loss
        """
        log.info('Using margin based ranking loss')

        error = tf.subtract(self.train_predictions[:, 1], self.train_predictions[:, 0])
        error_plus_margin = tf.add(error, self.params['margin'])
        after_thresh = tf.maximum(error_plus_margin, 0)
        batch_size = tf.constant(self.params['batch_size'], dtype=tf.float32)

        loss = tf.divide(tf.reduce_sum(after_thresh), batch_size)
        l2 = tf.reduce_sum([tf.nn.l2_loss(var) for var in tf1.trainable_variables()])

        return tf.add(loss, tf.multiply(self.params['lambda'], l2))
//  [python]
def call(self, inputs, *args, **kwargs):
        """Call MeanShift."""
        std = tf.convert_to_tensor(self.rgb_std, dtype=tf.float32)
        self.weight = tf.convert_to_tensor(np.eye(3).astype(np.float32))
        self.weight = tf.div(self.weight, std)
        self.bias = self.sign * self.rgb_range * tf.convert_to_tensor(self.rgb_mean, dtype=tf.float32)
        self.bias = tf.div(self.bias, std)
        res = tf.einsum('ij, njhw->nihw', self.weight, inputs)
        res = tf.transpose(res, [0, 2, 3, 1])
        res = tf.nn.bias_add(res, self.bias)
        res = tf.transpose(res, [0, 3, 1, 2])
        return res
//  [python]
def call(self, inputs, *args, **kwargs):
        """Call MeanShift."""
        std = tf.convert_to_tensor(self.rgb_std, dtype=tf.float32)
        self.weight = tf.convert_to_tensor(np.eye(3).astype(np.float32))
        self.weight = tf.divide(self.weight, std)
        self.bias = self.sign * self.rgb_range * tf.convert_to_tensor(self.rgb_mean, dtype=tf.float32)
        self.bias = tf.divide(self.bias, std)
        res = tf.einsum('ij, njhw->nihw', self.weight, inputs)
        res = tf.transpose(res, [0, 2, 3, 1])
        res = tf.nn.bias_add(res, self.bias)
        res = tf.transpose(res, [0, 3, 1, 2])
        return res
//  [python]
def drop_path(x, prob):
    """Drop path operation.

    :param x: input feature map
    :type x: torch tensor
    :param prob: dropout probability
    :type prob: float
    :return: output feature map after dropout
    :rtype: torch tensor
    """
    if prob <= 0.:
        return x
    keep = 1. - prob

    bernoulli_random = tf.random.uniform([int(x.get_shape()[0]), 1, 1, 1])
    mask = tf.cast(bernoulli_random < keep, tf.float32)
    x = tf.div(x, keep)
    x = tf.multiply(x, mask)
    return x
//  [python]
def drop_path(x, prob):
    """Drop path operation.

    :param x: input feature map
    :type x: torch tensor
    :param prob: dropout probability
    :type prob: float
    :return: output feature map after dropout
    :rtype: torch tensor
    """
    if prob <= 0.:
        return x
    keep = 1. - prob

    bernoulli_random = tf.random.uniform([int(x.get_shape()[0]), 1, 1, 1])
    mask = tf.cast(bernoulli_random < keep, tf.float32)
    x = tf.divide(x, keep)
    x = tf.multiply(x, mask)
    return x
//  [python]
def stochastic_depth(inputs, is_training, stochastic_depth_rate):
  '''Apply stochastic depth.'''
  if not is_training:
    return inputs

  # Compute keep_prob
  # TODO(tanmingxing): add support for training progress.
  keep_prob = 1.0 - stochastic_depth_rate

  # Compute stochastic_depth tensor
  batch_size = tf.shape(inputs)[0]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
  binary_tensor = tf.floor(random_tensor)
  output = tf.div(inputs, keep_prob) * binary_tensor
  return output
//  [python]
def stochastic_depth(inputs, is_training, stochastic_depth_rate):
  '''Apply stochastic depth.'''
  if not is_training:
    return inputs

  # Compute keep_prob
  # TODO(tanmingxing): add support for training progress.
  keep_prob = 1.0 - stochastic_depth_rate

  # Compute stochastic_depth tensor
  batch_size = tf.shape(inputs)[0]
  random_tensor = keep_prob
  random_tensor += tf.random_uniform([batch_size, 1, 1, 1], dtype=inputs.dtype)
  binary_tensor = tf.floor(random_tensor)
  output = tf.divide(inputs, keep_prob) * binary_tensor
  return output
//  [python]
def _gather_clipped_attributes(
        self, attributes, clipped_index, class_ids_per_polyline
    ):
        """
        Gather the attributes at the corresponding clipped_index.

        Args:
            attributes (tf.Tensor): 1D tensor of shape len(class_ids_per_polyline)
                                    * (npath_attributes + 1).
            clipped_index (tf.Tensor): 1D tensor with length of N holding the index of interest of
                                       the first attribute group.
            class_ids_per_polyline (tf.Tensor): 1D tensor, class ids for each polyline.

        Returns:
            attributes (tf.Tensor): Tensor of shape [1, len(clipped_index)* nattribute_groups].
        """

        def _clip_attributes(attributes, clipped_index, nattribute_groups):
            ncolumns = tf.reshape(tf.shape(input=clipped_index)[0], [1])
            base_index = tf.reshape(
                tf.tile(
                    tf.reshape(tf.range(nattribute_groups), [nattribute_groups, 1]),
                    [1, ncolumns[0]],
                ),
                [-1],
            )

            clipped_index = tf.tile(clipped_index, [nattribute_groups])
            index = tf.stack([base_index, clipped_index], axis=-1)
            reshaped_attributes = tf.reshape(attributes, [nattribute_groups, -1])
            clipped_attributes = tf.gather_nd(reshaped_attributes, index)

            return clipped_attributes

        nattribute_groups = tf.cond(
            pred=tf.equal(tf.shape(input=class_ids_per_polyline)[0], 0),
            true_fn=lambda: 1,
            false_fn=lambda: tf.compat.v1.div(
                tf.shape(input=attributes)[0], tf.shape(input=class_ids_per_polyline)[0]
            ),
        )

        clipped_attributes = tf.cond(
            pred=tf.equal(nattribute_groups, 1),
            true_fn=lambda: tf.gather(attributes, clipped_index),
            false_fn=lambda: _clip_attributes(
                attributes, clipped_index, nattribute_groups
            ),
        )

        return clipped_attributes
//  [python]
def _gather_clipped_attributes(
        self, attributes, clipped_index, class_ids_per_polyline
    ):
        """
        Gather the attributes at the corresponding clipped_index.

        Args:
            attributes (tf.Tensor): 1D tensor of shape len(class_ids_per_polyline)
                                    * (npath_attributes + 1).
            clipped_index (tf.Tensor): 1D tensor with length of N holding the index of interest of
                                       the first attribute group.
            class_ids_per_polyline (tf.Tensor): 1D tensor, class ids for each polyline.

        Returns:
            attributes (tf.Tensor): Tensor of shape [1, len(clipped_index)* nattribute_groups].
        """

        def _clip_attributes(attributes, clipped_index, nattribute_groups):
            ncolumns = tf.reshape(tf.shape(input=clipped_index)[0], [1])
            base_index = tf.reshape(
                tf.tile(
                    tf.reshape(tf.range(nattribute_groups), [nattribute_groups, 1]),
                    [1, ncolumns[0]],
                ),
                [-1],
            )

            clipped_index = tf.tile(clipped_index, [nattribute_groups])
            index = tf.stack([base_index, clipped_index], axis=-1)
            reshaped_attributes = tf.reshape(attributes, [nattribute_groups, -1])
            clipped_attributes = tf.gather_nd(reshaped_attributes, index)

            return clipped_attributes

        nattribute_groups = tf.cond(
            pred=tf.equal(tf.shape(input=class_ids_per_polyline)[0], 0),
            true_fn=lambda: 1,
            false_fn=lambda: tf.divide(
                tf.shape(input=attributes)[0], tf.shape(input=class_ids_per_polyline)[0]
            ),
        )

        clipped_attributes = tf.cond(
            pred=tf.equal(nattribute_groups, 1),
            true_fn=lambda: tf.gather(attributes, clipped_index),
            false_fn=lambda: _clip_attributes(
                attributes, clipped_index, nattribute_groups
            ),
        )

        return clipped_attributes
//  [python]
def create_div_model(self):
          w1 = tf.placeholder(tf.float32, name='w1')
          w2 = tf.placeholder(tf.float32, name='w2')
          feed_dict ={'w1': 8.0, 'w2': 2.0}
          r =tf.div(w1, w2, name='op_div')
          sess = tf.Session()
          _ = tf.Variable(initial_value = 'fake_variable')
          sess.run(tf.global_variables_initializer())
          saver = tf.train.Saver()
          print(f"feed_dict['w1'] : {feed_dict['w1']}")
          print(f"feed_dict['w2'] : {feed_dict['w2']}")
          result = sess.run(r, {w1: feed_dict['w1'], w2: feed_dict['w2']})
          print(f'TF 나눗셈결과: {result}')
          saver.save(sess, os.path.join(self.model,'calculator_div', 'model'),global_step=1000)