Skip to content

Commit

Permalink
Merge branch 'master' of github.com:alibaba/EasyCV
Browse files Browse the repository at this point in the history
  • Loading branch information
Cathy0908 committed Oct 26, 2023
2 parents b185db3 + db33ced commit 6b1abd2
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
data=data['val'],
dist_eval=True,
evaluators=[
dict(type='ClsEvaluator', topk=(1, 5), class_list=class_list)
dict(type='ClsEvaluator', topk=(1, ), class_list=class_list)
],
)
]
5 changes: 5 additions & 0 deletions easycv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Copyright (c) Alibaba, Inc. and its affiliates.
# flake8: noqa
# isort:skip_file
import os
os.environ['SETUPTOOLS_USE_DISTUTILS'] = 'stdlib'

from .version import __version__, short_version

__all__ = ['__version__', 'short_version']
4 changes: 2 additions & 2 deletions easycv/core/evaluation/custom_cocotools/cocoeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def accumulate(self, p=None):
fps = np.logical_and(
np.logical_not(dtm), np.logical_not(dtIg))

tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float32)
fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float32)
for t, (tp, fp) in enumerate(zip(tp_sum, fp_sum)):
tp = np.array(tp)
fp = np.array(fp)
Expand Down
2 changes: 1 addition & 1 deletion easycv/datasets/face/pipelines/face_keypoint_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def aug_clr_noise_blur(self, img):
skin_factor_list = [0.6, 0.8, 1.0, 1.2, 1.4]
skin_factor = np.random.choice(skin_factor_list)
img_ycrcb_raw[:, :, 0:1] = np.clip(
img_ycrcb_raw[:, :, 0:1].astype(np.float) * skin_factor, 0,
img_ycrcb_raw[:, :, 0:1].astype(np.float32) * skin_factor, 0,
255).astype(np.uint8)
img = cv2.cvtColor(img_ycrcb_raw, cv2.COLOR_YCR_CB2BGR)

Expand Down
4 changes: 2 additions & 2 deletions easycv/datasets/loader/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def set_uniform_indices(self, labels, num_classes):
l, size_per_label, replace=(len(l) <= size_per_label)))
indices = np.array(indices)
np.random.shuffle(indices)
indices = indices[:N].astype(np.int).tolist()
indices = indices[:N].astype(np.int64).tolist()

# add extra samples to make it evenly divisible
assert len(indices) <= self.total_size, \
Expand Down Expand Up @@ -438,7 +438,7 @@ def set_uniform_indices(self, labels, num_classes):
l, size_per_label, replace=(len(l) <= size_per_label)))
indices = np.array(indices)
np.random.shuffle(indices)
indices = indices[:N].astype(np.int)
indices = indices[:N].astype(np.int64)
# repeat
all_size = self.total_size * self.world_size
indices = indices[:all_size]
Expand Down
8 changes: 4 additions & 4 deletions easycv/datasets/video_recognition/pipelines/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _get_train_clips(self, num_frames):
ratio = (num_frames - ori_clip_len + 1.0) / self.num_clips
clip_offsets = np.around(np.arange(self.num_clips) * ratio)
else:
clip_offsets = np.zeros((self.num_clips, ), dtype=np.int)
clip_offsets = np.zeros((self.num_clips, ), dtype=np.int64)

return clip_offsets

Expand All @@ -180,11 +180,11 @@ def _get_test_clips(self, num_frames):
avg_interval = (num_frames - ori_clip_len + 1) / float(self.num_clips)
if num_frames > ori_clip_len - 1:
base_offsets = np.arange(self.num_clips) * avg_interval
clip_offsets = (base_offsets + avg_interval / 2.0).astype(np.int)
clip_offsets = (base_offsets + avg_interval / 2.0).astype(np.int64)
if self.twice_sample:
clip_offsets = np.concatenate([clip_offsets, base_offsets])
else:
clip_offsets = np.zeros((self.num_clips, ), dtype=np.int)
clip_offsets = np.zeros((self.num_clips, ), dtype=np.int64)
return clip_offsets

def _sample_clips(self, num_frames):
Expand Down Expand Up @@ -259,7 +259,7 @@ def __call__(self, results):
start_index = results['start_index']
frame_inds = np.concatenate(frame_inds) + start_index

results['frame_inds'] = frame_inds.astype(np.int)
results['frame_inds'] = frame_inds.astype(np.int64)
results['clip_len'] = self.clip_len
results['frame_interval'] = self.frame_interval
results['num_clips'] = self.num_clips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, results):
inds = np.arange(start, start + self.clip_len)
inds = np.mod(inds, num_frames)

results['frame_inds'] = inds.astype(np.int)
results['frame_inds'] = inds.astype(np.int64)
results['clip_len'] = self.clip_len
results['frame_interval'] = None
results['num_clips'] = self.num_clips
Expand Down
2 changes: 1 addition & 1 deletion easycv/file/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .file_io import IO
from .utils import is_oss_path
from .utils import get_oss_config, is_oss_path

io = IO()
8 changes: 4 additions & 4 deletions easycv/models/ocr/postprocess/db_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def box_score_fast(self, bitmap, _box):
'''
h, w = bitmap.shape[:2]
box = _box.copy()
xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int), 0, w - 1)
xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int), 0, w - 1)
ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int), 0, h - 1)
ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int), 0, h - 1)
xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int32), 0, w - 1)
xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int32), 0, w - 1)
ymin = np.clip(np.floor(box[:, 1].min()).astype(np.int32), 0, h - 1)
ymax = np.clip(np.ceil(box[:, 1].max()).astype(np.int32), 0, h - 1)

mask = np.zeros((ymax - ymin + 1, xmax - xmin + 1), dtype=np.uint8)
box[:, 0] = box[:, 0] - xmin
Expand Down
2 changes: 1 addition & 1 deletion easycv/models/utils/pos_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_1d_sincos_pos_embed_from_grid(embed_dim, pos):
out: (M, D)
"""
assert embed_dim % 2 == 0
omega = np.arange(embed_dim // 2, dtype=np.float)
omega = np.arange(embed_dim // 2, dtype=np.float32)
omega /= embed_dim / 2.
omega = 1. / 10000**omega # (D/2,)

Expand Down
2 changes: 1 addition & 1 deletion easycv/predictors/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def process_single(self, inputs):
ids = ids[legal_indices]
labels = np.array([id % 1000 for id in ids], dtype=np.int64)
segms = (pan_results[None] == ids[:, None, None])
masks = [it.astype(np.int) for it in segms]
masks = [it.astype(np.int32) for it in segms]
labels_txt = np.array(self.classes)[labels].tolist()

output['masks'] = masks
Expand Down
2 changes: 1 addition & 1 deletion easycv/thirdparty/mot/bytetrack/byte_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class STrack(BaseTrack):
def __init__(self, tlwh, score):

# wait activate
self._tlwh = np.asarray(tlwh, dtype=np.float)
self._tlwh = np.asarray(tlwh, dtype=np.float32)
self.kalman_filter = None
self.mean, self.covariance = None, None
self.is_activated = False
Expand Down
12 changes: 6 additions & 6 deletions easycv/thirdparty/mot/bytetrack/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def ious(atlbrs, btlbrs):
:rtype ious np.ndarray
"""
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float)
ious = np.zeros((len(atlbrs), len(btlbrs)), dtype=np.float32)
if ious.size == 0:
return ious

from cython_bbox import bbox_overlaps as bbox_ious

ious = bbox_ious(
np.ascontiguousarray(atlbrs, dtype=np.float),
np.ascontiguousarray(btlbrs, dtype=np.float))
np.ascontiguousarray(atlbrs, dtype=np.float32),
np.ascontiguousarray(btlbrs, dtype=np.float32))

return ious

Expand Down Expand Up @@ -151,15 +151,15 @@ def embedding_distance(tracks, detections, metric='cosine'):
:return: cost_matrix np.ndarray
"""

cost_matrix = np.zeros((len(tracks), len(detections)), dtype=np.float)
cost_matrix = np.zeros((len(tracks), len(detections)), dtype=np.float32)
if cost_matrix.size == 0:
return cost_matrix
det_features = np.asarray([track.curr_feat for track in detections],
dtype=np.float)
dtype=np.float32)
#for i, track in enumerate(tracks):
#cost_matrix[i, :] = np.maximum(0.0, cdist(track.smooth_feat.reshape(1,-1), det_features, metric))
track_features = np.asarray([track.smooth_feat for track in tracks],
dtype=np.float)
dtype=np.float32)
cost_matrix = np.maximum(0.0, cdist(track_features, det_features,
metric)) # Nomalized features
return cost_matrix
Expand Down
5 changes: 0 additions & 5 deletions easycv/toolkit/modelscope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# flake8: noqa
# isort:skip_file
import os
os.environ['SETUPTOOLS_USE_DISTUTILS'] = 'stdlib'

from . import models, msdatasets, pipelines, trainers
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __call__(self, inputs) -> Any:
legal_indices = ids != len(self.predict_op.CLASSES) # for VOID label
ids = ids[legal_indices]
segms = (semantic_result[None] == ids[:, None, None])
masks = [it.astype(np.int) for it in segms]
masks = [it.astype(np.int32) for it in segms]
labels_txt = np.array(self.predict_op.CLASSES)[ids].tolist()

results = {
Expand Down
4 changes: 2 additions & 2 deletions easycv/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# GENERATED VERSION FILE
# TIME: Thu Nov 5 14:17:50 2020

__version__ = '0.11.2'
short_version = '0.11.2'
__version__ = '0.11.4'
short_version = '0.11.4'
1 change: 1 addition & 0 deletions requirements/runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rapidfuzz
scikit-image
scikit-learn
seaborn
shapely==1.8.4
tensorboard
thop
timm==0.5.4
Expand Down
52 changes: 39 additions & 13 deletions tests/test_core/evaluation/test_coco_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def testCocoWrappers(self):
def testExportGroundtruthToCOCO(self):
image_ids = ['first', 'second']
groundtruth_boxes = [
np.array([[100, 100, 200, 200]], np.float),
np.array([[50, 50, 100, 100]], np.float)
np.array([[100, 100, 200, 200]], np.float32),
np.array([[50, 50, 100, 100]], np.float32)
]
groundtruth_classes = [
np.array([1], np.int32),
Expand Down Expand Up @@ -126,12 +126,12 @@ def testExportGroundtruthToCOCO(self):
def testExportDetectionsToCOCO(self):
image_ids = ['first', 'second']
detections_boxes = [
np.array([[100, 100, 200, 200]], np.float),
np.array([[50, 50, 100, 100]], np.float)
np.array([[100, 100, 200, 200]], np.float32),
np.array([[50, 50, 100, 100]], np.float32)
]
detections_scores = [
np.array([.8], np.float),
np.array([.7], np.float)
np.array([.8], np.float32),
np.array([.7], np.float32)
]
detections_classes = [np.array([1], np.int32), np.array([1], np.int32)]
categories = [{
Expand All @@ -152,15 +152,28 @@ def testExportDetectionsToCOCO(self):
detections_classes,
categories,
output_path=output_path)
self.assertListEqual(result, self._detections_list)

self.assertEqual(len(result), len(detections_boxes))
self.assertEqual(len(detections_boxes), len(detections_boxes))

score_list = []
for i in range(len(detections_boxes)):
score = self._detections_list[i].pop('score')
score_list.append(score)
self.assertAlmostEqual(result[i].pop('score'), score)
self.assertDictEqual(result[i], self._detections_list[i])

with io.open(output_path, 'r') as f:
written_result = f.read()
# The json output should have floats written to 4 digits of precision.
matcher = re.compile(r'"bbox":\s+\[\n\s+\d+.\d\d\d\d,',
re.MULTILINE)
self.assertTrue(matcher.findall(written_result))
written_result = json.loads(written_result)
self.assertAlmostEqual(result, written_result)
for i in range(len(result)):
self.assertAlmostEqual(written_result[i].pop('score'),
score_list[i])
self.assertDictEqual(result[i], written_result[i])

def testExportSegmentsToCOCO(self):
image_ids = ['first', 'second']
Expand All @@ -176,7 +189,10 @@ def testExportSegmentsToCOCO(self):
for i, detection_mask in enumerate(detection_masks):
detection_masks[i] = detection_mask[:, :, :, None]

detection_scores = [np.array([.8], np.float), np.array([.7], np.float)]
detection_scores = [
np.array([.8], np.float32),
np.array([.7], np.float32)
]
detection_classes = [np.array([1], np.int32), np.array([1], np.int32)]

categories = [{
Expand All @@ -202,7 +218,12 @@ def testExportSegmentsToCOCO(self):
written_result = json.loads(written_result)
mask_load = mask.decode([written_result[0]['segmentation']])
self.assertTrue(np.allclose(mask_load, detection_masks[0]))
self.assertAlmostEqual(result, written_result)
self.assertEqual(len(result), len(detection_masks))
self.assertEqual(len(written_result), len(detection_masks))
for i in range(len(detection_masks)):
self.assertAlmostEqual(result[i].pop('score'),
written_result[i].pop('score'))
self.assertDictEqual(result[i], written_result[i])

def testExportKeypointsToCOCO(self):
image_ids = ['first', 'second']
Expand All @@ -216,8 +237,8 @@ def testExportKeypointsToCOCO(self):
]

detection_scores = [
np.array([.8, 0.2], np.float),
np.array([.7, 0.3], np.float)
np.array([.8, 0.2], np.float32),
np.array([.7, 0.3], np.float32)
]
detection_classes = [
np.array([1, 1], np.int32),
Expand Down Expand Up @@ -248,7 +269,12 @@ def testExportKeypointsToCOCO(self):
with io.open(output_path, 'r') as f:
written_result = f.read()
written_result = json.loads(written_result)
self.assertAlmostEqual(result, written_result)
self.assertEqual(len(result), 4)
self.assertEqual(len(written_result), 4)
for i in range(4):
self.assertAlmostEqual(result[i].pop('score'),
written_result[i].pop('score'))
self.assertDictEqual(result[i], written_result[i])

def testSingleImageDetectionBoxesExport(self):
boxes = np.array([[0, 0, 1, 1], [0, 0, .5, .5], [.5, .5, 1, 1]],
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/detection/yolox/test_yolox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def test_yolox(self):
}
output = model(imgs, mode='train', **kwargs)
self.assertEqual(output['img_h'].cpu().numpy(),
np.array(640, dtype=np.float))
np.array(640, dtype=np.float32))
self.assertEqual(output['img_w'].cpu().numpy(),
np.array(640, dtype=np.float))
np.array(640, dtype=np.float32))
self.assertEqual(output['total_loss'].shape, torch.Size([]))
self.assertEqual(output['iou_l'].shape, torch.Size([]))
self.assertEqual(output['conf_l'].shape, torch.Size([]))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/detection/yolox_edge/test_yolox_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_yolox_edge(self):
}
output = model(imgs, mode='train', **kwargs)
self.assertEqual(output['img_h'].cpu().numpy(),
np.array(640, dtype=np.float))
np.array(640, dtype=np.float32))
self.assertEqual(output['img_w'].cpu().numpy(),
np.array(640, dtype=np.float))
np.array(640, dtype=np.float32))
self.assertEqual(output['total_loss'].shape, torch.Size([]))
self.assertEqual(output['iou_l'].shape, torch.Size([]))
self.assertEqual(output['conf_l'].shape, torch.Size([]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.utils.cv.image_utils import panoptic_seg_masks_to_image
from modelscope.utils.demo_utils import DemoCompatibilityCheck
from modelscope.utils.test_utils import test_level
from tests.ut_config import BASE_LOCAL_PATH


class EasyCVPanopticSegmentationPipelineTest(unittest.TestCase,
DemoCompatibilityCheck):
class EasyCVPanopticSegmentationPipelineTest(unittest.TestCase):
img_path = os.path.join(
BASE_LOCAL_PATH, 'data/test_images/image_semantic_segmentation.jpg')

Expand All @@ -32,10 +30,6 @@ def test_r50(self):
cv2.imwrite(tmp_save_path, draw_img)
print('print ' + self.model_id + ' success')

@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_demo_compatibility(self):
self.compatibility_check()


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 6b1abd2

Please sign in to comment.