python类squared_difference()的实例源码

train_conv_lstm.py 文件源码 项目:CIKM2017 作者: heliarmk 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def regression_loss(reg_preds, reg_labels):
    rmse = tf.sqrt(tf.reduce_mean(tf.squared_difference(reg_labels, reg_preds)))
    tf.add_to_collection('losses', rmse)
    return rmse, tf.add_n(tf.get_collection("losses"), name="total_loss")
train.py 文件源码 项目:CIKM2017 作者: heliarmk 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def regression_loss(reg_preds, reg_labels):
    rmse = tf.sqrt(tf.reduce_mean(tf.squared_difference(reg_labels, reg_preds)))
    tf.add_to_collection('losses', rmse)
    return tf.add_n(tf.get_collection('losses'), name="total_loss")
face_point_with_decay.py 文件源码 项目:Face_Point 作者: EllenSimith 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def loss(bbox_widths, preds, points, batch_size=100):
  """loss function based on paper, returns a tensor of batch_size.
  """
  diff = tf.squared_difference(preds, points)
  dist = []
  for i in range(5):
    dist.append(tf.reshape(tf.reduce_sum(diff[:,2*i:2*i+2], 1), [batch_size, 1]))
  dist = tf.reduce_sum(tf.sqrt(tf.concat(1, dist)), 1)
  error = tf.div(dist, bbox_widths)
  return error
PWL_fail1.py 文件源码 项目:failures_of_DL 作者: shakedshammah 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create_loss(self):
        self._Y_placeholder = tf.placeholder(tf.float32, shape=(None, self._n))
        self._loss = tf.reduce_mean(tf.reduce_sum(tf.squared_difference(self._p, self._Y_placeholder), reduction_indices=[1]))
PWL_fail1.py 文件源码 项目:failures_of_DL 作者: shakedshammah 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def create_loss(self):
        self._Y_placeholder = tf.placeholder(tf.float32, shape=(None, self._n))
        self._loss = tf.reduce_mean(
            tf.squared_difference(self._p, self._Y_placeholder))
PWL_fail1.py 文件源码 项目:failures_of_DL 作者: shakedshammah 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def create_loss(self):
        h1 = affine("affine4", self._p, 100)
        h2 = affine("affine5", h1, 100)
        self._f = affine("affine6", h2, self._n, relu=False)
        self._loss = tf.reduce_mean(tf.squared_difference(self._f, self._f_placeholder))
lista_network.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def _get_cost(self, outputs):
        """Construct the cost function from the outputs of the last layer. This
        will be used through SGD to train the network.

        Parameters
        ----------
        outputs: tuple fo tensors (n_out)
            a tuple of tensor containing the output from the last layer of the
            network

        Returns
        -------
        cost: a tensor computing the cost function of the network.
        reg: a tensor for computing regularization of the parameters.
            It should be None if no regularization is needed.
        """
        Zk, X, lmbd = outputs

        with tf.name_scope("reconstruction_zD"):
            rec = tf.matmul(Zk, tf.constant(self.D))

        with tf.name_scope("norm_2"):
            Er = tf.multiply(
                tf.constant(.5, dtype=tf.float32),
                tf.reduce_mean(tf.reduce_sum(tf.squared_difference(rec, X),
                                             reduction_indices=[1])))

        with tf.name_scope("norm_1"):
            l1 = lmbd * tf.reduce_mean(tf.reduce_sum(
                tf.abs(Zk), reduction_indices=[1]))

        return tf.add(Er, l1, name="cost")
lfista_network.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _get_cost(self, outputs):
        """Construct the cost function from the outputs of the last layer. This
        will be used through SGD to train the network.

        Parameters
        ----------
        outputs: tuple fo tensors (n_out)
            a tuple of tensor containing the output from the last layer of the
            network

        Returns
        -------
        cost: a tensor computing the cost function of the network.
        reg: a tensor for computing regularisation of the parameters.
            It should be 0 if no regularization is needed.
        """
        Zk, _, X, lmbd = outputs

        with tf.name_scope("reconstruction_zD"):
            rec = tf.matmul(Zk, tf.constant(self.D))

        with tf.name_scope("norm_2"):
            Er = .5*tf.reduce_mean(tf.reduce_sum(
                tf.squared_difference(rec, X), reduction_indices=[1]))

        with tf.name_scope("norm_1"):
            l1 = lmbd*tf.reduce_mean(tf.reduce_sum(
                tf.abs(Zk), reduction_indices=[1]))

        return tf.add(Er, l1, name="cost")
ista_tf.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _get_step(self, inputs):
        Z, X, lmbd = self.inputs
        K, p = self.D.shape
        L = self.L
        with tf.name_scope("step_ISTA"):
            self.S = tf.constant(np.eye(K, dtype=np.float32) - self.S0/L,
                                 shape=[K, K], name='S')
            self.We = tf.constant(self.D.T / L, shape=[p, K],
                                  dtype=tf.float32, name='We')
            B = tf.matmul(X, self.We, name='B')
            hk = tf.matmul(Z, self.S) + B
            step = soft_thresholding(hk, lmbd / L)
            dz = tf.reduce_mean(tf.reduce_sum(
                tf.squared_difference(step, Z), reduction_indices=[1]))
        return step, dz
ista_tf.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _get_cost(self, inputs):
        Z, X, lmbd = self.inputs
        with tf.name_scope("Cost"):
            rec = tf.matmul(Z, tf.constant(self.D))
            Er = tf.reduce_mean(
                tf.reduce_sum(tf.squared_difference(rec, X),
                              reduction_indices=[1]))/2
            cost = Er + lmbd * tf.reduce_mean(
                tf.reduce_sum(tf.abs(Z), reduction_indices=[1]))

        return cost
facto_network.py 文件源码 项目:AdaptiveOptim 作者: tomMoral 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_cost(self, outputs):
        """Construct the cost function from the outputs of the last layer. This
        will be used through SGD to train the network.

        Parameters
        ----------
        outputs: tuple fo tensors (n_out)
            a tuple of tensor containing the output from the last layer of the
            network

        Returns
        -------
        cost: a tensor computing the cost function of the network
        reg: a tensor for computing regularisation of the parameters.
            It should be 0 if no regularization is needed.
        """
        Zk, X, lmbd = outputs

        with tf.name_scope("reconstruction_zD"):
            rec = tf.matmul(Zk, tf.constant(self.D))

        with tf.name_scope("norm_2"):
            Er = .5 * tf.reduce_mean(tf.reduce_sum(
                tf.squared_difference(rec, X), reduction_indices=[1]))

        with tf.name_scope("norm_1"):
            l1 = lmbd * tf.reduce_mean(tf.reduce_sum(
                tf.abs(Zk), reduction_indices=[1]))

        cost = tf.add(Er, l1, name="cost")
        return cost
test_boundary_optimization.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_cost_distance(self, l, r, d):
  dd = tf.reduce_sum(tf.squared_difference(l,r), reduction_indices=1);
  dd = tf.squared_difference(dd, d);
  return tf.reduce_mean(dd);
test_boundary_optimization.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def create_cost_spacing(self, c, length, normalized = True):
  c_shape = c.get_shape().as_list();
  c1 = tf.slice(c, [1,0], [-1,-1]);
  c2 = tf.slice(c, [0,0], [c_shape[0]-1,-1]);
  d = tf.sqrt(tf.reduce_sum(tf.squared_difference(c1,c2), reduction_indices = 1));
  if normalized:
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length / (c_shape[0]-1), "float32")));
  else:
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length, "float32")));
machine_vision_b.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def create_cost_distance(l, r, d):
  dd = tf.sqrt(tf.reduce_sum(tf.squared_difference(l,r), reduction_indices=1));
  dd = tf.squared_difference(dd, d);
  return tf.reduce_mean(dd);
machine_vision_c.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_cost_distance(l, r, d):
  dd = tf.sqrt(tf.reduce_sum(tf.squared_difference(l,r), reduction_indices=1));
  dd = tf.squared_difference(dd, d);
  return tf.reduce_mean(dd);
machine_vision_c.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def create_cost_spacing(t, length, normalized = True):
  d = tf.sqrt(tf.reduce_sum(tf.square(t), reduction_indices = 1));
  if normalized:
    s = t.get_shape().as_list();
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length / s[0], "float32")));
  else:
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length, "float32")));
machine_vision_d.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def create_cost_distance(l, r, d):
  dd = tf.sqrt(tf.reduce_sum(tf.squared_difference(l,r), reduction_indices=1));
  dd = tf.squared_difference(dd, d);
  return tf.reduce_mean(dd);
machine_vision_d.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def create_cost_spacing(t, length, normalized = True):
  d = tf.sqrt(tf.reduce_sum(tf.square(t), reduction_indices = 1));
  if normalized:
    s = t.get_shape().as_list();
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length / s[0], "float32")));
  else:
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(length, "float32")));
machine_vision_2.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_cost_spacing(self, c):
    c1 = tf.slice(c, [0,1,0], [-1,-1,-1]);
    c2 = tf.slice(c, [0,0,0], [-1,self.npoints-1,-1]);
    d = tf.sqrt(tf.reduce_sum(tf.squared_difference(c1,c2), reduction_indices = 2));
    return tf.reduce_mean(tf.squared_difference(d, tf.constant(self.model.length / (self.npoints-1), "float32")));
machine_vision_3.py 文件源码 项目:CElegansBehaviour 作者: ChristophKirst 项目源码 文件源码 阅读 58 收藏 0 点赞 0 评论 0
def create_cost_distance(self, l, r, d):
    dd = tf.reduce_sum(tf.squared_difference(l,r), reduction_indices=1);
    dd = tf.squared_difference(dd, d);
    return tf.reduce_mean(dd);


问题


面经


文章

微信
公众号

扫码关注公众号