呉恩達深さ学習第4課第3週作業(yoloアルゴリズム車両検出)問題総括

2864 ワード

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