提交 b2ccd9ab 编写于 作者: J jiangjiajun

compatible with paddlepaddle lower than 1.8.4

上级 63f88667
...@@ -43,11 +43,6 @@ except: ...@@ -43,11 +43,6 @@ except:
"[WARNING] pycocotools install: https://paddlex.readthedocs.io/zh_CN/develop/install.html#pycocotools" "[WARNING] pycocotools install: https://paddlex.readthedocs.io/zh_CN/develop/install.html#pycocotools"
) )
import paddle
if paddle.__version__ == '0.0.0':
print("[NOTICE]\tYou are using paddlepaddle with version= 0.0.0")
elif paddle.__version__ < '1.8.4':
raise Exception("[ERROR] paddlepaddle-gpu or paddlepaddle >= 1.8.4 is required")
import paddlehub as hub import paddlehub as hub
if hub.version.hub_version < '1.8.2': if hub.version.hub_version < '1.8.2':
raise Exception("[ERROR] paddlehub >= 1.8.2 is required") raise Exception("[ERROR] paddlehub >= 1.8.2 is required")
......
...@@ -18,6 +18,7 @@ import tqdm ...@@ -18,6 +18,7 @@ import tqdm
import os.path as osp import os.path as osp
import numpy as np import numpy as np
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter
from paddle.fluid.optimizer import ExponentialMovingAverage from paddle.fluid.optimizer import ExponentialMovingAverage
...@@ -123,6 +124,9 @@ class PPYOLO(BaseAPI): ...@@ -123,6 +124,9 @@ class PPYOLO(BaseAPI):
self.use_ema = False self.use_ema = False
self.with_dcn_v2 = with_dcn_v2 self.with_dcn_v2 = with_dcn_v2
if paddle.__version__ < '1.8.4' and paddle.__version__ != '0.0.0':
raise Exception("PPYOLO requires paddlepaddle or paddlepaddle-gpu >= 1.8.4")
def _get_backbone(self, backbone_name): def _get_backbone(self, backbone_name):
if backbone_name.startswith('ResNet50_vd'): if backbone_name.startswith('ResNet50_vd'):
backbone = paddlex.cv.nets.ResNet( backbone = paddlex.cv.nets.ResNet(
......
...@@ -16,6 +16,7 @@ from __future__ import absolute_import ...@@ -16,6 +16,7 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import paddle
from paddle import fluid from paddle import fluid
try: try:
from collections.abc import Sequence from collections.abc import Sequence
...@@ -67,19 +68,34 @@ class YOLOv3Loss(object): ...@@ -67,19 +68,34 @@ class YOLOv3Loss(object):
scale_x_y = self.scale_x_y if not isinstance( scale_x_y = self.scale_x_y if not isinstance(
self.scale_x_y, Sequence) else self.scale_x_y[i] self.scale_x_y, Sequence) else self.scale_x_y[i]
anchor_mask = anchor_masks[i] anchor_mask = anchor_masks[i]
loss = fluid.layers.yolov3_loss( if paddle.__version__ < '1.8.4' and paddle.__version__ != '0.0.0':
x=output, loss = fluid.layers.yolov3_loss(
gt_box=gt_box, x=output,
gt_label=gt_label, gt_box=gt_box,
gt_score=gt_score, gt_label=gt_label,
anchors=anchors, gt_score=gt_score,
anchor_mask=anchor_mask, anchors=anchors,
class_num=num_classes, anchor_mask=anchor_mask,
ignore_thresh=self._ignore_thresh, class_num=num_classes,
downsample_ratio=self.downsample[i], ignore_thresh=self._ignore_thresh,
use_label_smooth=self._label_smooth, downsample_ratio=self.downsample[i],
scale_x_y=scale_x_y, use_label_smooth=self._label_smooth,
name=prefix_name + "yolo_loss" + str(i)) name=prefix_name + "yolo_loss" + str(i))
else:
loss = fluid.layers.yolov3_loss(
x=output,
gt_box=gt_box,
gt_label=gt_label,
gt_score=gt_score,
anchors=anchors,
anchor_mask=anchor_mask,
class_num=num_classes,
ignore_thresh=self._ignore_thresh,
downsample_ratio=self.downsample[i],
use_label_smooth=self._label_smooth,
scale_x_y=scale_x_y,
name=prefix_name + "yolo_loss" + str(i))
losses.append(fluid.layers.reduce_mean(loss)) losses.append(fluid.layers.reduce_mean(loss))
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import paddle
from paddle import fluid from paddle import fluid
from paddle.fluid.param_attr import ParamAttr from paddle.fluid.param_attr import ParamAttr
from paddle.fluid.regularizer import L2Decay from paddle.fluid.regularizer import L2Decay
...@@ -407,16 +408,28 @@ class YOLOv3: ...@@ -407,16 +408,28 @@ class YOLOv3:
scale_x_y = self.scale_x_y if not isinstance( scale_x_y = self.scale_x_y if not isinstance(
self.scale_x_y, Sequence) else self.scale_x_y[i] self.scale_x_y, Sequence) else self.scale_x_y[i]
box, score = fluid.layers.yolo_box( if paddle.__version__ < '1.8.4' and paddle.__version__ != '0.0.0':
x=input, box, score = fluid.layers.yolo_box(
img_size=im_size, x=input,
anchors=self.mask_anchors[i], img_size=im_size,
class_num=self.num_classes, anchors=self.mask_anchors[i],
conf_thresh=self.nms.score_threshold, class_num=self.num_classes,
downsample_ratio=self.downsample[i], conf_thresh=self.nms.score_threshold,
name=self.prefix_name + 'yolo_box' + str(i), downsample_ratio=self.downsample[i],
clip_bbox=self.clip_bbox, name=self.prefix_name + 'yolo_box' + str(i),
scale_x_y=self.scale_x_y) clip_bbox=self.clip_bbox)
else:
box, score = fluid.layers.yolo_box(
x=input,
img_size=im_size,
anchors=self.mask_anchors[i],
class_num=self.num_classes,
conf_thresh=self.nms.score_threshold,
downsample_ratio=self.downsample[i],
name=self.prefix_name + 'yolo_box' + str(i),
clip_bbox=self.clip_bbox,
scale_x_y=self.scale_x_y)
boxes.append(box) boxes.append(box)
scores.append(fluid.layers.transpose(score, perm=[0, 2, 1])) scores.append(fluid.layers.transpose(score, perm=[0, 2, 1]))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册