diff --git a/paddle/fluid/pybind/op_function_generator.h b/paddle/fluid/pybind/op_function_generator.h index a4e56d1508038cda5f00af7637a505988fddb4a8..2bfc16c7d5b0fd60768b798f8b1fcd06d71711b2 100644 --- a/paddle/fluid/pybind/op_function_generator.h +++ b/paddle/fluid/pybind/op_function_generator.h @@ -96,6 +96,7 @@ std::map> op_ins_map = { {"nce", {"Input", "Label", "Weight", "Bias", "SampleWeight", "CustomDistProbs", "CustomDistAlias", "CustomDistAliasProbs"}}, + {"yolov3_loss", {"X", "GTBox", "GTLabel", "GTScore"}}, {"check_finite_and_unscale", {"X", "Scale", "FloatStatus"}}, {"group_norm", {"X", "Scale", "Bias"}}, {"linear_chain_crf", {"Emission", "Transition", "Label", "Length"}}, diff --git a/python/paddle/fluid/layers/detection.py b/python/paddle/fluid/layers/detection.py index cbd9712720c1ad4e10407ba381e3c2fb8267643a..75b2b26fb9dfccfa7fd94f096de9c47302c71ed9 100644 --- a/python/paddle/fluid/layers/detection.py +++ b/python/paddle/fluid/layers/detection.py @@ -1072,7 +1072,6 @@ def yolov3_loss(x, anchor_mask=anchor_mask, class_num=80, ignore_thresh=0.7, downsample_ratio=32) """ - helper = LayerHelper('yolov3_loss', **locals()) if not isinstance(x, Variable): raise TypeError("Input x of yolov3_loss must be Variable") @@ -1095,8 +1094,16 @@ def yolov3_loss(x, raise TypeError( "Attr use_label_smooth of yolov3_loss must be a bool value") - loss = helper.create_variable_for_type_inference(dtype=x.dtype) + if _non_static_mode(): + attrs = ("anchors", anchors, "anchor_mask", anchor_mask, "class_num", + class_num, "ignore_thresh", ignore_thresh, "downsample_ratio", + downsample_ratio, "use_label_smooth", use_label_smooth, + "scale_x_y", scale_x_y) + loss, _, _ = _C_ops.yolov3_loss(x, gt_box, gt_label, gt_score, *attrs) + return loss + helper = LayerHelper('yolov3_loss', **locals()) + loss = helper.create_variable_for_type_inference(dtype=x.dtype) objectness_mask = helper.create_variable_for_type_inference(dtype='int32') gt_match_mask = helper.create_variable_for_type_inference(dtype='int32') diff --git a/python/paddle/vision/ops.py b/python/paddle/vision/ops.py index 7836545c738cae1eca35f2dc2face9ae1bc27399..00bd6ed38a3adf3a8bbcb2f6d13476962bb03b9d 100644 --- a/python/paddle/vision/ops.py +++ b/python/paddle/vision/ops.py @@ -194,10 +194,10 @@ def yolo_loss(x, scale_x_y=1.) """ - if _non_static_mode() and gt_score is None: + if _non_static_mode(): loss, _, _ = _C_ops.yolov3_loss( - x, gt_box, gt_label, 'anchors', anchors, 'anchor_mask', anchor_mask, - 'class_num', class_num, 'ignore_thresh', ignore_thresh, + x, gt_box, gt_label, gt_score, 'anchors', anchors, 'anchor_mask', + anchor_mask, 'class_num', class_num, 'ignore_thresh', ignore_thresh, 'downsample_ratio', downsample_ratio, 'use_label_smooth', use_label_smooth, 'scale_x_y', scale_x_y) return loss