未验证 提交 f2955696 编写于 作者: W wangxinxin08 提交者: GitHub

[Dygraph]modify operators and batch_operators in data preprocess (#1666)

* modify operators and batch_operators in data preprocess

* import BboxError and ImageError in operators

* modify code according to review

* modify some bugs

* add Gt2Solov2TargetOp in batch_operators

* modify code according to review
上级 d4a6d324
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
from . import operators from . import operators
from . import batch_operators from . import batch_operators
# TODO: operators and batch_operators will be replaced by operator and batch_operator
from .operators import * from .operators import *
from .operator import *
from .batch_operators import * from .batch_operators import *
from .batch_operator import *
__all__ = [] __all__ = []
__all__ += registered_ops __all__ += registered_ops
此差异已折叠。
...@@ -24,7 +24,7 @@ except Exception: ...@@ -24,7 +24,7 @@ except Exception:
import logging import logging
import cv2 import cv2
import numpy as np import numpy as np
from .operators import register_op, BaseOperator from .operator import register_op, BaseOperator
from .op_helper import jaccard_overlap, gaussian2D from .op_helper import jaccard_overlap, gaussian2D
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
此差异已折叠。
...@@ -39,6 +39,7 @@ from PIL import Image, ImageEnhance, ImageDraw ...@@ -39,6 +39,7 @@ from PIL import Image, ImageEnhance, ImageDraw
from ppdet.core.workspace import serializable from ppdet.core.workspace import serializable
from ppdet.modeling.layers import AnchorGrid from ppdet.modeling.layers import AnchorGrid
from .operator import register_op, BaseOperator, BboxError, ImageError
from .op_helper import (satisfy_sample_constraint, filter_and_process, from .op_helper import (satisfy_sample_constraint, filter_and_process,
generate_sample_bbox, clip_bbox, data_anchor_sampling, generate_sample_bbox, clip_bbox, data_anchor_sampling,
...@@ -48,45 +49,6 @@ from .op_helper import (satisfy_sample_constraint, filter_and_process, ...@@ -48,45 +49,6 @@ from .op_helper import (satisfy_sample_constraint, filter_and_process,
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
registered_ops = []
def register_op(cls):
registered_ops.append(cls.__name__)
if not hasattr(BaseOperator, cls.__name__):
setattr(BaseOperator, cls.__name__, cls)
else:
raise KeyError("The {} class has been registered.".format(cls.__name__))
return serializable(cls)
class BboxError(ValueError):
pass
class ImageError(ValueError):
pass
class BaseOperator(object):
def __init__(self, name=None):
if name is None:
name = self.__class__.__name__
self._id = name + '_' + str(uuid.uuid4())[-6:]
def __call__(self, sample, context=None):
""" Process a sample.
Args:
sample (dict): a dict of sample, eg: {'image':xx, 'label': xxx}
context (dict): info about this sample processing
Returns:
result (dict): a processed sample
"""
return sample
def __str__(self):
return str(self._id)
@register_op @register_op
class DecodeImage(BaseOperator): class DecodeImage(BaseOperator):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册