提交 b0683058 编写于 作者: W walloollaw 提交者: qingqing01

Fix bug in unittests of ppdet.data.tests (#2894)

上级 cc2c52ed
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
# limitations under the License. # limitations under the License.
import numpy as np import numpy as np
import matplotlib
matplotlib.use('Agg')
from pycocotools.coco import COCO from pycocotools.coco import COCO
import logging import logging
......
...@@ -23,7 +23,7 @@ TRANSFORM: ...@@ -23,7 +23,7 @@ TRANSFORM:
- OP: ResizeImage - OP: ResizeImage
TARGET_SIZE: 800 TARGET_SIZE: 800
MAX_SIZE: 1333 MAX_SIZE: 1333
- OP: Rgb2Bgr - OP: Permute
TO_BGR: False TO_BGR: False
- OP: ArrangeRCNN - OP: ArrangeRCNN
BATCH_SIZE: 1 BATCH_SIZE: 1
......
...@@ -19,7 +19,7 @@ TRANSFORM: ...@@ -19,7 +19,7 @@ TRANSFORM:
- OP: ResizeImage - OP: ResizeImage
TARGET_SIZE: 800 TARGET_SIZE: 800
MAX_SIZE: 1333 MAX_SIZE: 1333
- OP: Rgb2Bgr - OP: Permute
TO_BGR: False TO_BGR: False
- OP: ArrangeRCNN - OP: ArrangeRCNN
BATCH_SIZE: 1 BATCH_SIZE: 1
......
...@@ -3,10 +3,6 @@ import os ...@@ -3,10 +3,6 @@ import os
import six import six
import logging import logging
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
if path not in sys.path:
sys.path.insert(0, path)
prefix = os.path.dirname(os.path.abspath(__file__)) prefix = os.path.dirname(os.path.abspath(__file__))
#coco data for testing #coco data for testing
......
...@@ -51,7 +51,7 @@ class TestLoader(unittest.TestCase): ...@@ -51,7 +51,7 @@ class TestLoader(unittest.TestCase):
def test_load_coco_in_json(self): def test_load_coco_in_json(self):
""" test loading COCO data in json file """ test loading COCO data in json file
""" """
from data.source.coco_loader import load from ppdet.data.source.coco_loader import load
if not os.path.exists(self.anno_path): if not os.path.exists(self.anno_path):
logging.warn('not found %s, so skip this test' % (self.anno_path)) logging.warn('not found %s, so skip this test' % (self.anno_path))
return return
...@@ -71,7 +71,7 @@ class TestLoader(unittest.TestCase): ...@@ -71,7 +71,7 @@ class TestLoader(unittest.TestCase):
return return
samples = 10 samples = 10
from data.source.loader import load_roidb from ppdet.data.source.loader import load_roidb
records, cname2cid = load_roidb(anno_path, samples) records, cname2cid = load_roidb(anno_path, samples)
self.assertEqual(len(records), samples) self.assertEqual(len(records), samples)
self.assertGreater(len(cname2cid), 0) self.assertGreater(len(cname2cid), 0)
...@@ -79,7 +79,7 @@ class TestLoader(unittest.TestCase): ...@@ -79,7 +79,7 @@ class TestLoader(unittest.TestCase):
def test_load_voc_in_xml(self): def test_load_voc_in_xml(self):
""" test loading VOC data in xml files """ test loading VOC data in xml files
""" """
from data.source.voc_loader import load from ppdet.data.source.voc_loader import load
if not os.path.exists(self.anno_path1): if not os.path.exists(self.anno_path1):
logging.warn('not found %s, so skip this test' % (self.anno_path1)) logging.warn('not found %s, so skip this test' % (self.anno_path1))
return return
...@@ -98,7 +98,7 @@ class TestLoader(unittest.TestCase): ...@@ -98,7 +98,7 @@ class TestLoader(unittest.TestCase):
return return
samples = 3 samples = 3
from loader import load_roidb from ppdet.data.source.loader import load_roidb
records, cname2cid = load_roidb(anno_path, samples) records, cname2cid = load_roidb(anno_path, samples)
self.assertEqual(len(records), samples) self.assertEqual(len(records), samples)
self.assertGreater(len(cname2cid), 0) self.assertGreater(len(cname2cid), 0)
......
...@@ -3,7 +3,7 @@ import unittest ...@@ -3,7 +3,7 @@ import unittest
import logging import logging
import numpy as np import numpy as np
import set_env import set_env
from data import transform as tf import ppdet.data.transform as tf
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
...@@ -47,7 +47,7 @@ class TestBase(unittest.TestCase): ...@@ -47,7 +47,7 @@ class TestBase(unittest.TestCase):
'target_size': 300, 'target_size': 300,
'max_size': 1333 'max_size': 1333
}] }]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
data = self.sample.copy() data = self.sample.copy()
result0 = mapper(data) result0 = mapper(data)
...@@ -55,14 +55,14 @@ class TestBase(unittest.TestCase): ...@@ -55,14 +55,14 @@ class TestBase(unittest.TestCase):
self.assertEqual(len(result0['image'].shape), 3) self.assertEqual(len(result0['image'].shape), 3)
# RandFlipImage # RandFlipImage
ops_conf = [{'op': 'RandomFlipImage'}] ops_conf = [{'op': 'RandomFlipImage'}]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
result1 = mapper(result0) result1 = mapper(result0)
self.assertEqual(result1['image'].shape, result0['image'].shape) self.assertEqual(result1['image'].shape, result0['image'].shape)
self.assertEqual(result1['gt_bbox'].shape, result0['gt_bbox'].shape) self.assertEqual(result1['gt_bbox'].shape, result0['gt_bbox'].shape)
# NormalizeImage # NormalizeImage
ops_conf = [{'op': 'NormalizeImage', 'is_channel_first': False}] ops_conf = [{'op': 'NormalizeImage', 'is_channel_first': False}]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
result2 = mapper(result1) result2 = mapper(result1)
im1 = result1['image'] im1 = result1['image']
...@@ -71,7 +71,7 @@ class TestBase(unittest.TestCase): ...@@ -71,7 +71,7 @@ class TestBase(unittest.TestCase):
self.assertEqual(count, im1.shape[0] * im1.shape[1], im1.shape[2]) self.assertEqual(count, im1.shape[0] * im1.shape[1], im1.shape[2])
# ArrangeSample # ArrangeSample
ops_conf = [{'op': 'ArrangeRCNN'}] ops_conf = [{'op': 'ArrangeRCNN'}]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
result3 = mapper(result2) result3 = mapper(result2)
self.assertEqual(type(result3), tuple) self.assertEqual(type(result3), tuple)
...@@ -93,7 +93,7 @@ class TestBase(unittest.TestCase): ...@@ -93,7 +93,7 @@ class TestBase(unittest.TestCase):
[1, 50, 0.3, 1.0, 0.5, 2.0, 0.9, 0.0], [1, 50, 0.3, 1.0, 0.5, 2.0, 0.9, 0.0],
[1, 50, 0.3, 1.0, 0.5, 2.0, 0.0, 1.0]] [1, 50, 0.3, 1.0, 0.5, 2.0, 0.0, 1.0]]
}] }]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
data = self.sample.copy() data = self.sample.copy()
result = mapper(data) result = mapper(data)
...@@ -111,7 +111,7 @@ class TestBase(unittest.TestCase): ...@@ -111,7 +111,7 @@ class TestBase(unittest.TestCase):
'max_ratio': 1.5, 'max_ratio': 1.5,
'prob': 1 'prob': 1
}] }]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
data = self.sample.copy() data = self.sample.copy()
result = mapper(data) result = mapper(data)
...@@ -130,7 +130,7 @@ class TestBase(unittest.TestCase): ...@@ -130,7 +130,7 @@ class TestBase(unittest.TestCase):
'op': 'RandomInterpImage', 'op': 'RandomInterpImage',
'target_size': 608 'target_size': 608
}] }]
mapper = tf.build(ops_conf) mapper = tf.build_mapper(ops_conf)
self.assertTrue(mapper is not None) self.assertTrue(mapper is not None)
data = self.sample.copy() data = self.sample.copy()
result = mapper(data) result = mapper(data)
......
...@@ -7,7 +7,7 @@ import numpy as np ...@@ -7,7 +7,7 @@ import numpy as np
import yaml import yaml
import set_env import set_env
from data import Reader from ppdet.data.reader import Reader
class TestReader(unittest.TestCase): class TestReader(unittest.TestCase):
......
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
import logging import logging
import set_env import set_env
from data import build_source from ppdet.data.source import build_source
class TestRoiDbSource(unittest.TestCase): class TestRoiDbSource(unittest.TestCase):
......
...@@ -6,8 +6,8 @@ import logging ...@@ -6,8 +6,8 @@ import logging
import numpy as np import numpy as np
import set_env import set_env
from data import build_source import ppdet.data.transform as tf
from data import transform as tf from ppdet.data.source import build_source
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -53,7 +53,7 @@ class TestTransformer(unittest.TestCase): ...@@ -53,7 +53,7 @@ class TestTransformer(unittest.TestCase):
def test_map(self): def test_map(self):
""" test transformer.map """ test transformer.map
""" """
mapper = tf.build(self.ops) mapper = tf.build_mapper(self.ops)
ds = build_source(self.sc_config) ds = build_source(self.sc_config)
mapped_ds = tf.map(ds, mapper) mapped_ds = tf.map(ds, mapper)
ct = 0 ct = 0
...@@ -66,7 +66,7 @@ class TestTransformer(unittest.TestCase): ...@@ -66,7 +66,7 @@ class TestTransformer(unittest.TestCase):
def test_parallel_map(self): def test_parallel_map(self):
""" test transformer.map with concurrent workers """ test transformer.map with concurrent workers
""" """
mapper = tf.build(self.ops) mapper = tf.build_mapper(self.ops)
ds = build_source(self.sc_config) ds = build_source(self.sc_config)
worker_conf = {'WORKER_NUM': 2, 'use_process': True} worker_conf = {'WORKER_NUM': 2, 'use_process': True}
mapped_ds = tf.map(ds, mapper, worker_conf) mapped_ds = tf.map(ds, mapper, worker_conf)
...@@ -91,7 +91,7 @@ class TestTransformer(unittest.TestCase): ...@@ -91,7 +91,7 @@ class TestTransformer(unittest.TestCase):
""" test batched dataset """ test batched dataset
""" """
batchsize = 2 batchsize = 2
mapper = tf.build(self.ops) mapper = tf.build_mapper(self.ops)
ds = build_source(self.sc_config) ds = build_source(self.sc_config)
mapped_ds = tf.map(ds, mapper) mapped_ds = tf.map(ds, mapper)
batched_ds = tf.batch(mapped_ds, batchsize, True) batched_ds = tf.batch(mapped_ds, batchsize, True)
......
...@@ -17,6 +17,7 @@ from __future__ import print_function ...@@ -17,6 +17,7 @@ from __future__ import print_function
import copy import copy
import logging import logging
import traceback
from .transformer import MappedDataset, BatchedDataset from .transformer import MappedDataset, BatchedDataset
from .post_map import build_post_map from .post_map import build_post_map
...@@ -76,7 +77,10 @@ def build_mapper(ops, context=None): ...@@ -76,7 +77,10 @@ def build_mapper(ops, context=None):
out = f(sample, ctx) out = f(sample, ctx)
sample = out sample = out
except Exception as e: except Exception as e:
logger.warn("fail to map op [{}] with error: {}".format(f, e)) stack_info = traceback.format_exc()
logger.warn("fail to map op [{}] with error: {} and stack:\n{}".format(f, e, str(stack_info)))
raise e
return out return out
_mapper.ops = op_repr _mapper.ops = op_repr
......
...@@ -540,7 +540,9 @@ class CropImage(BaseOperator): ...@@ -540,7 +540,9 @@ class CropImage(BaseOperator):
gt_class = sample['gt_class'] gt_class = sample['gt_class']
im_width = sample['w'] im_width = sample['w']
im_height = sample['h'] im_height = sample['h']
gt_score = sample['gt_score'] gt_score = None
if 'gt_score' in sample:
gt_score = sample['gt_score']
sampled_bbox = [] sampled_bbox = []
gt_bbox = gt_bbox.tolist() gt_bbox = gt_bbox.tolist()
for sampler in self.batch_sampler: for sampler in self.batch_sampler:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册