当前位置: 首页>>代码示例>>Python>>正文


Python backend.minimum方法代码示例

本文整理汇总了Python中keras.backend.minimum方法的典型用法代码示例。如果您正苦于以下问题:Python backend.minimum方法的具体用法?Python backend.minimum怎么用?Python backend.minimum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.backend的用法示例。


在下文中一共展示了backend.minimum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: batch_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def batch_iou(boxes, box):
  """Compute the Intersection-Over-Union of a batch of boxes with another
  box.

  Args:
    box1: 2D array of [cx, cy, width, height].
    box2: a single array of [cx, cy, width, height]
  Returns:
    ious: array of a float number in range [0, 1].
  """
  lr = np.maximum(
      np.minimum(boxes[:,0]+0.5*boxes[:,2], box[0]+0.5*box[2]) - \
      np.maximum(boxes[:,0]-0.5*boxes[:,2], box[0]-0.5*box[2]),
      0
  )
  tb = np.maximum(
      np.minimum(boxes[:,1]+0.5*boxes[:,3], box[1]+0.5*box[3]) - \
      np.maximum(boxes[:,1]-0.5*boxes[:,3], box[1]-0.5*box[3]),
      0
  )
  inter = lr*tb
  union = boxes[:,2]*boxes[:,3] + box[2]*box[3] - inter
  return inter/union 
开发者ID:omni-us,项目名称:squeezedet-keras,代码行数:25,代码来源:utils.py

示例2: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def call(self, x):
        # previous mean
        pre_mean = self.mean
    
        # compute this batch stats
        this_sum = tf.reduce_sum(x, 0)
        this_bs = tf.cast(K.shape(x)[0], 'float32')  # this batch size
        
        # increase count and compute weights
        new_count = self.count + this_bs
        alpha = this_bs/K.minimum(new_count, self.cap)
        
        # compute new mean. Note that once we reach self.cap (e.g. 1000), the 'previous mean' matters less
        new_mean = pre_mean * (1-alpha) + (this_sum/this_bs) * alpha
        
        updates = [(self.count, new_count), (self.mean, new_mean)]
        self.add_update(updates, x)
        
        # the first few 1000 should not matter that much towards this cost
        return K.minimum(1., new_count/self.cap) * K.expand_dims(new_mean, 0) 
开发者ID:voxelmorph,项目名称:voxelmorph,代码行数:22,代码来源:layers.py

示例3: ori_acc_delta_k

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def ori_acc_delta_k(y_true, y_pred, k=10, max_delta=180):
    # get ROI
    label_seg = K.sum(y_true, axis=-1)
    label_seg = K.tf.cast(K.tf.greater(label_seg, 0), K.tf.float32)
    # get pred angle
    angle = K.cast(K.argmax(ori_highest_peak(y_pred, max_delta), axis=-1), dtype=K.tf.float32)*2.0+1.0
    # get gt angle
    angle_t = K.cast(K.argmax(y_true, axis=-1), dtype=K.tf.float32)*2.0+1.0
    # get delta
    angle_delta = K.abs(angle_t - angle)
    acc = K.tf.less_equal(K.minimum(angle_delta, max_delta-angle_delta), k)
    acc = K.cast(acc, dtype=K.tf.float32)
    # apply ROI
    acc = acc*label_seg
    acc = K.sum(acc) / (K.sum(label_seg)+K.epsilon())
    return acc 
开发者ID:luannd,项目名称:MinutiaeNet,代码行数:18,代码来源:CoarseNet_utils.py

示例4: box_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def box_iou(b1, b2):
    '''Return iou tensor

    Parameters
    ----------
    b1: tensor, shape=(i1,...,iN, 4), xywh
    b2: tensor, shape=(j, 4), xywh

    Returns
    -------
    iou: tensor, shape=(i1,...,iN, j)

    '''

    # Expand dim to apply broadcasting.
    b1 = K.expand_dims(b1, -2)
    b1_xy = b1[..., :2]
    b1_wh = b1[..., 2:4]
    b1_wh_half = b1_wh/2.
    b1_mins = b1_xy - b1_wh_half
    b1_maxes = b1_xy + b1_wh_half

    # Expand dim to apply broadcasting.
    b2 = K.expand_dims(b2, 0)
    b2_xy = b2[..., :2]
    b2_wh = b2[..., 2:4]
    b2_wh_half = b2_wh/2.
    b2_mins = b2_xy - b2_wh_half
    b2_maxes = b2_xy + b2_wh_half

    intersect_mins = K.maximum(b1_mins, b2_mins)
    intersect_maxes = K.minimum(b1_maxes, b2_maxes)
    intersect_wh = K.maximum(intersect_maxes - intersect_mins, 0.)
    intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1]
    b1_area = b1_wh[..., 0] * b1_wh[..., 1]
    b2_area = b2_wh[..., 0] * b2_wh[..., 1]
    iou = intersect_area / (b1_area + b2_area - intersect_area)

    return iou 
开发者ID:bing0037,项目名称:keras-yolo3,代码行数:41,代码来源:model.py

示例5: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def call(self,x):
        y_pred=x[0]
        y_recont_gt=x[1] 
        y_prob_pred=tf.squeeze(x[2],axis=3) 
        y_prob_gt=x[3]
        visible = tf.cast(y_prob_gt > 0.5,y_pred.dtype)
        visible = tf.squeeze(visible,axis=3) 
        #generate transformed values using sym
        if(len(self.sym)>1):
            #if(True):
            for sym_id,transform in enumerate(self.sym): #3x3 matrix
                tf_mat=tf.convert_to_tensor(transform,y_recont_gt.dtype)
                y_gt_transformed = tf.transpose(tf.matmul(tf_mat,tf.transpose(tf.reshape(y_recont_gt,[-1,3]))))
                y_gt_transformed = tf.reshape(y_gt_transformed,[-1,128,128,3])
                loss_xyz_temp = K.sum(K.abs(y_gt_transformed-y_pred),axis=3)/3
                loss_sum=K.sum(loss_xyz_temp,axis=[1,2])
                if(sym_id>0):
                    loss_sums = tf.concat([loss_sums,tf.expand_dims(loss_sum,axis=0)],axis=0)
                    loss_xyzs=  tf.concat([loss_xyzs,tf.expand_dims(loss_xyz_temp,axis=0)],axis=0)
                else:
                    loss_sums = tf.expand_dims(loss_sum,axis=0) 
                    loss_xyzs = tf.expand_dims(loss_xyz_temp,axis=0)
            
            min_values = tf.reduce_min(loss_sums,axis=0,keepdims=True) 
            loss_switch = tf.cast(tf.equal(loss_sums,min_values),y_pred.dtype)
            loss_xyz = tf.expand_dims(tf.expand_dims(loss_switch,axis=2),axis=3)*loss_xyzs
            loss_xyz = K.sum(loss_xyz,axis=0) 
        else:
            loss_xyz = K.sum(K.abs(y_recont_gt-y_pred),axis=3)/3
        prob_loss = K.square(y_prob_pred-K.minimum(loss_xyz,1)) 
        loss_invisible = (1-visible)*loss_xyz
        loss_visible = visible*loss_xyz
        loss = loss_visible*3 + loss_invisible+ 0.5*prob_loss 
        loss = K.mean(loss,axis=[1,2])
        return loss 
开发者ID:kirumang,项目名称:Pix2Pose,代码行数:37,代码来源:ae_model.py

示例6: tensor_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def tensor_iou(box1, box2, input_mask, config):
    """Computes pairwise IOU of two lists of boxes
    
    Arguments:
        box1 {[type]} -- First list of boxes
        box2 {[type]} -- Second list of boxes
        input_mask {[type]} -- Zero-One indicating which boxes to compute
        config {[type]} -- dict containing hyperparameters
    
    Returns:
        [type] -- [description]
    """

    
    xmin = K.maximum(box1[0], box2[0])
    ymin = K.maximum(box1[1], box2[1])
    xmax = K.minimum(box1[2], box2[2])
    ymax = K.minimum(box1[3], box2[3])

    w = K.maximum(0.0, xmax - xmin)
    h = K.maximum(0.0, ymax - ymin)

    intersection = w * h

    w1 = box1[2] - box1[0]
    h1 = box1[3] - box1[1]
    w2 = box2[2] - box2[0]
    h2 = box2[3] - box2[1]

    union = w1 * h1 + w2 * h2 - intersection

    return intersection / (union + config.EPSILON) * K.reshape(input_mask, [config.BATCH_SIZE, config.ANCHORS]) 
开发者ID:omni-us,项目名称:squeezedet-keras,代码行数:34,代码来源:utils.py

示例7: box_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def box_iou(b1, b2):
    # 13,13,3,1,4
    # 计算左上角的坐标和右下角的坐标
    b1 = K.expand_dims(b1, -2)
    b1_xy = b1[..., :2]
    b1_wh = b1[..., 2:4]
    b1_wh_half = b1_wh/2.
    b1_mins = b1_xy - b1_wh_half
    b1_maxes = b1_xy + b1_wh_half

    # 1,n,4
    # 计算左上角和右下角的坐标
    b2 = K.expand_dims(b2, 0)
    b2_xy = b2[..., :2]
    b2_wh = b2[..., 2:4]
    b2_wh_half = b2_wh/2.
    b2_mins = b2_xy - b2_wh_half
    b2_maxes = b2_xy + b2_wh_half

    # 计算重合面积
    intersect_mins = K.maximum(b1_mins, b2_mins)
    intersect_maxes = K.minimum(b1_maxes, b2_maxes)
    intersect_wh = K.maximum(intersect_maxes - intersect_mins, 0.)
    intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1]
    b1_area = b1_wh[..., 0] * b1_wh[..., 1]
    b2_area = b2_wh[..., 0] * b2_wh[..., 1]
    iou = intersect_area / (b1_area + b2_area - intersect_area)

    return iou

#---------------------------------------------------#
#   loss值计算
#---------------------------------------------------# 
开发者ID:bubbliiiing,项目名称:yolo3-keras,代码行数:35,代码来源:loss.py

示例8: emit_Minimum

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def emit_Minimum(self, IR_node, in_scope=False):
        if in_scope:
            code = "{:<15} = K.minimum({}, {})".format(
                IR_node.variable_name,
                self.parent_variable_name(IR_node),
                self.parent_variable_name(IR_node, [1])
            )
            return code
        else:
            return self._emit_merge(IR_node, 'Minimum') 
开发者ID:microsoft,项目名称:MMdnn,代码行数:12,代码来源:keras2_emitter.py

示例9: get_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def get_iou(bbox_base, bbox_target):
    """2つのBoundingBoxのIoU(Intersection Over Union)を取得する。
        https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/
    Args:
        bbox_base (ndarray): 基準になるBoudingBox。
            Its shape is :math:`(N, 4)`.
            2軸目に以下の順でBBoxの座標を保持する。
            :math:`p_{ymin}, p_{xmin}, p_{ymax}, p_{xmax}`.
        bbox_target (ndarray): BoudingBox。
            Its shape is :math:`(K, 4)`.
            2軸目に以下の順でBBoxの座標を保持する。
            :math:`p_{ymin}, p_{xmin}, p_{ymax}, p_{xmax}`.

        bbox_baseの各Box毎にbbox_targetを適用し、IoUを求める。

    Returns:
        ndarray:
        IoU(0 <= IoU <= 1)
        形状は以下の通り。
        :math:`(N, K)`.

    """
    if bbox_base.shape[1] != 4 or bbox_target.shape[1] != 4:
        raise IndexError

    # 交差領域の左上の座標
    # bbox_base[:, None, :]のより次元を増やすことで、
    # bbox_baseとbbox_targetを総当りで評価出来る。
    # (N, K, 2)の座標が得られる
    tl = np.maximum(bbox_base[:, None, :2], bbox_target[:, :2])
    # 交差領域の右下の座標
    # (N, K, 2)の座標が得られる
    br = np.minimum(bbox_base[:, None, 2:], bbox_target[:, 2:])

    # 右下-左下=交差領域の(h, w)が得られる。
    # h*wで交差領域の面積。ただし、交差領域がない(右下 <= 左上)ものは除くため0とする。
    area_i = np.prod(br - tl, axis=2) * \
        np.all(br > tl, axis=2).astype('float32')
    area_base = np.prod(bbox_base[:, 2:] - bbox_base[:, :2], axis=1)
    area_target = np.prod(bbox_target[:, 2:] - bbox_target[:, :2], axis=1)
    return area_i / (area_base[:, None] + area_target - area_i) 
开发者ID:shtamura,项目名称:maskrcnn,代码行数:43,代码来源:bbox.py

示例10: get_iou_K

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def get_iou_K(bbox_base, bbox_target):
    """2つのBoundingBoxのIoU(Intersection Over Union)を取得する。
        https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/
    Args:
        bbox_base (tensor): 基準になるBoudingBox。
            Its shape is :math:`(N, 4)`.
            2軸目に以下の順でBBoxの座標を保持する。
            :math:`p_{ymin}, p_{xmin}, p_{ymax}, p_{xmax}`.
        bbox_target (tensor): BoudingBox。
            Its shape is :math:`(K, 4)`.
            2軸目に以下の順でBBoxの座標を保持する。
            :math:`p_{ymin}, p_{xmin}, p_{ymax}, p_{xmax}`.

        bbox_baseの各Box毎にbbox_targetを適用し、IoUを求める。

    Returns:
        tensor:
        IoU(0 <= IoU <= 1)
        形状は以下の通り。
        :math:`(N, K)`.

    """
    if bbox_base.shape[1] != 4 or bbox_target.shape[1] != 4:
        raise IndexError

    # 交差領域の左上の座標
    # bbox_base[:, None, :]のより次元を増やすことで、
    # bbox_baseとbbox_targetを総当りで評価出来る。
    # (N, K, 2)の座標が得られる
    tl = K.maximum(bbox_base[:, None, :2], bbox_target[:, :2])
    # 交差領域の右下の座標
    # (N, K, 2)の座標が得られる
    br = K.minimum(bbox_base[:, None, 2:], bbox_target[:, 2:])

    # 右下-左下=交差領域の(h, w)が得られる。
    # h*wで交差領域の面積。ただし、交差領域がない(右下 <= 左上)ものは除くため0とする。
    area_i = K.prod(br - tl, axis=2) * \
        K.cast(K.all(br > tl, axis=2), 'float32')
    area_base = K.prod(bbox_base[:, 2:] - bbox_base[:, :2], axis=1)
    area_target = K.prod(bbox_target[:, 2:] - bbox_target[:, :2], axis=1)
    return area_i / (area_base[:, None] + area_target - area_i) 
开发者ID:shtamura,项目名称:maskrcnn,代码行数:43,代码来源:bbox.py

示例11: update_b

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def update_b(self):
        """
        Get a new value for the bias, relaxing it over time to the true value.
        """

        i = self.get_layer_idx()
        return self.b0 * k.minimum(k.maximum(
            0, 1 - (1 - 2 * self.time / self.duration) * i / 50), 1) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:10,代码来源:temporal_mean_rate_theano.py

示例12: my_logloss

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def my_logloss(act, pred):
    epsilon = 1e-15
    pred = K.maximum(epsilon, pred)
    pred = K.minimum(1 - epsilon, pred)
    ll = K.sum(act * K.log(pred) + (1 - act) * K.log(1 - pred))
    ll = ll * -1.0 / K.shape(act)[0]

    return ll 
开发者ID:xjtushilei,项目名称:pCVR,代码行数:10,代码来源:utils.py

示例13: logloss

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def logloss(act, pred):
    '''
    官方给的损失函数
    :param act: 
    :param pred: 
    :return: 
    '''
    epsilon = 1e-15
    pred = sp.maximum(epsilon, pred)
    pred = sp.minimum(1 - epsilon, pred)
    ll = sum(act * sp.log(pred) + sp.subtract(1, act) * sp.log(sp.subtract(1, pred)))
    ll = ll * -1.0 / len(act)
    return ll 
开发者ID:xjtushilei,项目名称:pCVR,代码行数:15,代码来源:utils.py

示例14: box_iou

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def box_iou(b1, b2):
    '''Return iou tensor
    Parameters
    ----------
    b1: tensor, shape=(i1,...,iN, 4), xywh
    b2: tensor, shape=(j, 4), xywh
    Returns
    -------
    iou: tensor, shape=(i1,...,iN, j)
    '''

    # Expand dim to apply broadcasting.
    b1 = K.expand_dims(b1, -2)
    b1_xy = b1[..., :2]
    b1_wh = b1[..., 2:4]
    b1_wh_half = b1_wh/2.
    b1_mins = b1_xy - b1_wh_half
    b1_maxes = b1_xy + b1_wh_half

    # Expand dim to apply broadcasting.
    b2 = K.expand_dims(b2, 0)
    b2_xy = b2[..., :2]
    b2_wh = b2[..., 2:4]
    b2_wh_half = b2_wh/2.
    b2_mins = b2_xy - b2_wh_half
    b2_maxes = b2_xy + b2_wh_half

    intersect_mins = K.maximum(b1_mins, b2_mins)
    intersect_maxes = K.minimum(b1_maxes, b2_maxes)
    intersect_wh = K.maximum(intersect_maxes - intersect_mins, 0.)
    intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1]
    b1_area = b1_wh[..., 0] * b1_wh[..., 1]
    b2_area = b2_wh[..., 0] * b2_wh[..., 1]
    iou = intersect_area / (b1_area + b2_area - intersect_area)

    return iou 
开发者ID:TianzhongSong,项目名称:keras-FP16-test,代码行数:38,代码来源:yolo3.py

示例15: __call__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import minimum [as 别名]
def __call__(self, inputs, enc_output, context_attn_mask=None):
        """

        :param inputs: [N, T_t]
        :param enc_output: [N, T_s, dim_model]
        :param context_attn_mask: [N, T_t, T_s]
        :return:
        """

        seq_emb = self.seq_embedding(inputs)  # [N, T_t, dim_model]
        pos_emb = self.pos_embedding(inputs)

        output = Add()([seq_emb, pos_emb])  # [N, T_t, dim_model]

        self_attention_padding_mask = Lambda(lambda x: padding_mask(x, x),
                                             name="self_attention_padding_mask")(inputs)  # [N, T_t, T_t]
        seq_mask = Lambda(lambda x: sequence_mask(x),
                          name="sequence_mask")(inputs)
        # self_attn_mask = Add(name="self_attn_mask")([self_attention_padding_mask, seq_mask])  # [N, T_t, T_t]
        self_attn_mask = Lambda(lambda x: K.minimum(x[0], x[1]))(
            [self_attention_padding_mask, seq_mask])  # [N, T_t, T_t]

        self_attentions = []
        context_attentions = []
        for decoder in self.decoder_layers:
            output, self_attn, context_attn = decoder(output, enc_output, self_attn_mask, context_attn_mask)
            self_attentions.append(self_attn)
            context_attentions.append(context_attn)

        return output, self_attentions, context_attentions 
开发者ID:GlassyWing,项目名称:transformer-keras,代码行数:32,代码来源:core.py


注:本文中的keras.backend.minimum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。