吴恩达深度学习第四课第三周作业(yolo算法车辆检测)问题总结

1.去掉分值低于门槛的boxes

# GRADED FUNCTION: yolo_filter_boxes

def yolo_filter_boxes(box_confidence, boxes, box_class_probs, threshold = .6):
    """Filters YOLO boxes by thresholding on object and class confidence.

    Arguments:
    box_confidence -- tensor of shape (19, 19, 5, 1)
    boxes -- tensor of shape (19, 19, 5, 4)
    box_class_probs -- tensor of shape (19, 19, 5, 80)
    threshold -- real value, if [ highest class probability score < threshold], then get rid of the corresponding box

    Returns:
    scores -- tensor of shape (None,), containing the class probability score for selected boxes
    boxes -- tensor of shape (None, 4), containing (b_x, b_y, b_h, b_w) coordinates of selected boxes
    classes -- tensor of shape (None,), containing the index of the class detected by the selected boxes

    Note: "None" is here because you don't know the exact number of selected boxes, as it depends on the threshold. 
    For example, the actual output size of scores would be (10,) if there are 10 boxes.
    """

    # Step 1: Compute box scores
    ### START CODE HERE ### (≈ 1 line)
    box_scores = box_confidence * box_class_probs
    ### END CODE HERE ###

    # Step 2: Find the box_classes thanks to the max box_scores, keep track of the corresponding score
    ### START CODE HERE ### (≈ 2 lines)
    box_classes = K.argmax(box_scores, axis=-1)
    box_class_scores = K.max(box_scores, axis=-1, keepdims=False)
    ### END CODE HERE ###

    # Step 3: Create a filtering mask based on "box_class_scores" by using "threshold". The mask should have the
    # same dimension as box_class_scores, and be True for the boxes you want to keep (with probability >= threshold)
    ### START CODE HERE ### (≈ 1 line)
    filtering_mask = box_class_scores >= threshold
    ### END CODE HERE ###

    # Step 4: Apply the mask to scores, boxes and classes
    ### START CODE HERE ### (≈ 3 lines)
    scores = tf.boolean_mask(box_class_scores, filtering_mask)
    boxes = tf.boolean_mask(boxes, filtering_mask)
    classes = tf.boolean_mask(box_classes, filtering_mask)
    ### END CODE HERE ###

    return scores, boxes, classes

1.np.max()

矩阵(m,n)求其np.max(),axis=0时即按列求其最值,axis=1时即按行求其最值。

但当矩阵为多维(p, m, n)时较为麻烦。而axis=0,1,或2,参考np.max多维axis的用法

2.np.argmax()

np.argmax返回最值的坐标,维数不同方式不同,参考https://blog.csdn.net/weixin_38145317/article/details/79650188但是博主print(b)的注释是错的,说法没问题,axis=0或1,2的处理方式同np.max()

3.tf.boolean_mask()

假设A矩阵(m,n,p),而mask矩阵(k,l),mask为True的地方保存下来。假设mask矩阵中坐标为(1,2)的元素为true,tf.boolean_mask()函数处理后返回的A矩阵的(1,2,:)

参考

https://blog.csdn.net/addresser/article/details/81281833

https://blog.csdn.net/m0_37393514/article/details/81674489

你可能感兴趣的:(深度学习)