def test_loss_op_for_warmup(setup_y_true_tensor, setup_y_pred_tensor): # 1. build loss function batch_size = 1 warmup_bs = 100 yolo_loss = YoloLoss(grid_size=9, nb_class=4) custom_loss = yolo_loss.custom_loss(batch_size, warmup_bs) # 2. placeholder : (y_true, y_pred) y_true, y_true_value = setup_y_true_tensor y_pred, y_pred_value = setup_y_pred_tensor # 3. loss operation loss_op = custom_loss(y_true, y_pred) # 4. setup feed values for each placeholders (true_boxes, y_true, y_pred true_boxes_value = np.zeros((1, 1, 1, 1, 10, 4)) true_boxes_value[0, 0, 0, 0, 0, :] = [3.46875, 4.78125, 1, 5.625] true_boxes_value[0, 0, 0, 0, 1, :] = [4.484375, 4.875, 1.15625, 5.625] # 5. run loss_op in session # y_true, y_pred�� ���� value�� insert loss_value = run_op(loss_op, feed_dict={ y_true: y_true_value, y_pred: y_pred_value }) assert np.allclose(loss_value, 3.1930623)
def test_loss_op(setup_y_true_tensor, setup_y_pred_tensor, setup_true_boxes_tensor): # 1. build loss function batch_size = 1 warmup_bs = 0 yolo_loss = YoloLoss(grid_size=9, nb_class=4) custom_loss = yolo_loss.custom_loss(batch_size, warmup_bs) # 2. placeholder : (y_true, y_pred) y_true, y_true_value = setup_y_true_tensor y_pred, y_pred_value = setup_y_pred_tensor # 3. loss operation loss_op = custom_loss(y_true, y_pred) # 4. setup feed values for each placeholders (true_boxes, y_true, y_pred _, true_boxes_value = setup_true_boxes_tensor # 5. run loss_op in session # y_true, y_pred�� ���� value�� insert loss_value = run_op(loss_op, feed_dict={ y_true: y_true_value, y_pred: y_pred_value }) assert np.allclose(loss_value, 5.47542)
def create_yolo(architecture, labels, input_size=(224, 224), anchors=[ 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 ], coord_scale=1.0, class_scale=1.0, object_scale=5.0, no_object_scale=1.0, weights=None, strip_size=32): n_classes = len(labels) n_boxes = int(len(anchors) / 2) yolo_network = create_yolo_network(architecture, input_size, n_classes, n_boxes, weights, strip_size=strip_size) yolo_loss = YoloLoss(yolo_network.get_grid_size(), n_classes, anchors, coord_scale, class_scale, object_scale, no_object_scale) yolo_decoder = YoloDecoder(anchors) yolo = YOLO(yolo_network, yolo_loss, yolo_decoder, labels, input_size) return yolo
def test_loss_op(setup_y_true_tensor, setup_y_pred_tensor, setup_true_boxes_tensor): # 1. build loss function batch_size = 1 warmup_bs = 0 yolo_loss = YoloLoss(grid_size=9, nb_class=4) custom_loss = yolo_loss.custom_loss(batch_size, warmup_bs) # 2. placeholder : (y_true, y_pred) y_true, y_true_value = setup_y_true_tensor y_pred, y_pred_value = setup_y_pred_tensor # 3. loss operation loss_op = custom_loss(y_true, y_pred) # 4. setup feed values for each placeholders (true_boxes, y_true, y_pred _, true_boxes_value = setup_true_boxes_tensor # 5. run loss_op in session # y_true, y_pred�� ���� value�� insert loss_value = run_op(loss_op, feed_dict={y_true: y_true_value, y_pred: y_pred_value}) assert np.allclose(loss_value, 5.47542)
def test_loss_op_for_warmup(setup_y_true_tensor, setup_y_pred_tensor): # 1. build loss function batch_size = 1 warmup_bs = 100 yolo_loss = YoloLoss(grid_size=9, nb_class=4) custom_loss = yolo_loss.custom_loss(batch_size, warmup_bs) # 2. placeholder : (y_true, y_pred) y_true, y_true_value = setup_y_true_tensor y_pred, y_pred_value = setup_y_pred_tensor # 3. loss operation loss_op = custom_loss(y_true, y_pred) # 4. setup feed values for each placeholders (true_boxes, y_true, y_pred true_boxes_value = np.zeros((1,1,1,1,10,4)) true_boxes_value[0,0,0,0,0,:] = [3.46875, 4.78125, 1, 5.625] true_boxes_value[0,0,0,0,1,:] = [4.484375, 4.875, 1.15625, 5.625] # 5. run loss_op in session # y_true, y_pred�� ���� value�� insert loss_value = run_op(loss_op, feed_dict={y_true: y_true_value, y_pred: y_pred_value}) assert np.allclose(loss_value, 3.1930623)
def create_yolo(architecture, labels, input_size=416, anchors=[ 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 ], feature_weights_path=None): n_classes = len(labels) n_boxes = int(len(anchors) / 2) yolo_network = create_yolo_network(architecture, input_size, n_classes, n_boxes, feature_weights_path) yolo_loss = YoloLoss(yolo_network.get_grid_size(), n_classes, anchors) yolo_decoder = YoloDecoder(anchors) yolo = YOLO(yolo_network, yolo_loss, yolo_decoder, labels, input_size) return yolo