# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS" BASIS,
...
@@ -18,7 +18,6 @@ import random
...
@@ -18,7 +18,6 @@ import random
importos.pathasosp
importos.pathasosp
importnumpyasnp
importnumpyasnp
fromPILimportImage,ImageEnhance
fromPILimportImage,ImageEnhance
importutils.loggingaslogging
classClsTransform:
classClsTransform:
...
@@ -49,14 +48,7 @@ class Compose(ClsTransform):
...
@@ -49,14 +48,7 @@ class Compose(ClsTransform):
'must be equal or larger than 1!')
'must be equal or larger than 1!')
self.transforms=transforms
self.transforms=transforms
# 检查transforms里面的操作,目前支持PaddleX定义的或者是imgaug操作
foropinself.transforms:
ifnotisinstance(op,ClsTransform):
importimgaug.augmentersasiaa
ifnotisinstance(op,iaa.Augmenter):
raiseException(
"Elements in transforms should be defined in 'paddlex.cls.transforms' or class of imgaug.augmenters.Augmenter, see docs here: https://paddlex.readthedocs.io/zh_CN/latest/apis/transforms/"
)
def__call__(self,im,label=None):
def__call__(self,im,label=None):
"""
"""
...
@@ -79,18 +71,10 @@ class Compose(ClsTransform):
...
@@ -79,18 +71,10 @@ class Compose(ClsTransform):
raiseTypeError('Can\'t read The image file {}!'.format(im))
raiseTypeError('Can\'t read The image file {}!'.format(im))
im=cv2.cvtColor(im,cv2.COLOR_BGR2RGB)
im=cv2.cvtColor(im,cv2.COLOR_BGR2RGB)
foropinself.transforms:
foropinself.transforms:
ifisinstance(op,ClsTransform):
outputs=op(im,label)
outputs=op(im,label)
im=outputs[0]
im=outputs[0]
iflen(outputs)==2:
iflen(outputs)==2:
label=outputs[1]
label=outputs[1]
else:
importimgaug.augmentersasiaa
ifisinstance(op,iaa.Augmenter):
im=execute_imgaug(op,im)
outputs=(im,)
iflabelisnotNone:
outputs=(im,label)
returnoutputs
returnoutputs
defadd_augmenters(self,augmenters):
defadd_augmenters(self,augmenters):
...
@@ -100,109 +84,10 @@ class Compose(ClsTransform):
...
@@ -100,109 +84,10 @@ class Compose(ClsTransform):
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS" BASIS,
...
@@ -14,14 +14,12 @@
...
@@ -14,14 +14,12 @@
# limitations under the License.
# limitations under the License.
from.opsimport*
from.opsimport*
from.imgaug_supportimportexecute_imgaug
importrandom
importrandom
importos.pathasosp
importos.pathasosp
importnumpyasnp
importnumpyasnp
fromPILimportImage
fromPILimportImage
importcv2
importcv2
fromcollectionsimportOrderedDict
fromcollectionsimportOrderedDict
importutils.loggingaslogging
classSegTransform:
classSegTransform:
...
@@ -53,14 +51,7 @@ class Compose(SegTransform):
...
@@ -53,14 +51,7 @@ class Compose(SegTransform):
'must be equal or larger than 1!')
'must be equal or larger than 1!')
self.transforms=transforms
self.transforms=transforms
self.to_rgb=False
self.to_rgb=False
# 检查transforms里面的操作,目前支持PaddleX定义的或者是imgaug操作
foropinself.transforms:
ifnotisinstance(op,SegTransform):
importimgaug.augmentersasiaa
ifnotisinstance(op,iaa.Augmenter):
raiseException(
"Elements in transforms should be defined in 'paddlex.seg.transforms' or class of imgaug.augmenters.Augmenter, see docs here: https://paddlex.readthedocs.io/zh_CN/latest/apis/transforms/"