提交 eca9870e 编写于 作者: S sunyanfang01

for review

上级 2279d7c4
......@@ -53,6 +53,11 @@ class FasterRCNN(BaseAPI):
]
assert backbone in backbones, "backbone should be one of {}".format(
backbones)
bbox_loss_types = [
'SmoothL1Loss', 'CiouLoss', 'DiouLoss', 'GiouLoss'
]
assert backbone in backbones, "bbox_loss_type should be one of {}".format(
bbox_loss_types)
self.backbone = backbone
self.num_classes = num_classes
self.with_fpn = with_fpn
......@@ -84,6 +89,8 @@ class FasterRCNN(BaseAPI):
layers = 101
variant = 'd'
norm_type = 'affine_channel'
if self.bbox_loss_type != 'SmoothL1Loss':
norm_type = 'bn'
elif backbone_name == 'HRNet_W18':
backbone = paddlex.cv.nets.hrnet.HRNet(
width=18, freeze_norm=True, norm_decay=0., freeze_at=0)
......
......@@ -188,39 +188,25 @@ class BBoxHead(object):
is_cls_agnostic=False,
num_classes=self.num_classes,
use_complete_iou_loss=True)
loss_bbox = loss_obj(
x=bbox_pred,
y=bbox_targets,
inside_weight=bbox_inside_weights,
outside_weight=bbox_outside_weights)
elif self.bbox_loss_type == 'DiouLoss':
from .loss.diou_loss import DiouLoss
loss_obj = DiouLoss(loss_weight=12.,
is_cls_agnostic=False,
num_classes=self.num_classes,
use_complete_iou_loss=False)
loss_bbox = loss_obj(
x=bbox_pred,
y=bbox_targets,
inside_weight=bbox_inside_weights,
outside_weight=bbox_outside_weights)
elif self.bbox_loss_type == 'GiouLoss':
from .loss.giou_loss import GiouLoss
loss_obj = GiouLoss(loss_weight=10.,
is_cls_agnostic=False,
num_classes=self.num_classes)
loss_bbox = loss_obj(
x=bbox_pred,
y=bbox_targets,
inside_weight=bbox_inside_weights,
outside_weight=bbox_outside_weights)
else:
loss_bbox = fluid.layers.smooth_l1(
from .loss.smoothl1_loss import SmoothL1Loss
loss_obj = SmoothL1Loss(self.sigma)
loss_bbox = loss_obj(
x=bbox_pred,
y=bbox_targets,
inside_weight=bbox_inside_weights,
outside_weight=bbox_outside_weights,
sigma=self.sigma)
outside_weight=bbox_outside_weights)
loss_bbox = fluid.layers.reduce_mean(loss_bbox)
return {'loss_cls': loss_cls, 'loss_bbox': loss_bbox}
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
......
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from paddle import fluid
class SmoothL1Loss(object):
'''
SmoothL1 Loss
Args:
sigma (float): Hyper parameter of smooth L1 loss layer.
'''
def __init__(self, sigma):
self.sigma = sigma
def __call__(self,
x,
y,
inside_weight=None,
outside_weight=None):
loss_bbox = fluid.layers.smooth_l1(
x=x,
y=y,
inside_weight=inside_weight,
outside_weight=outside_weight,
sigma=self.sigma)
return loss_bbox
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册