mirror of
https://github.com/open-mmlab/mmsegmentation.git
synced 2025-06-03 22:03:48 +08:00
[Enhancement]Replace numpy ascontiguousarray with torch contiguous to speed-up (#2604)
## Motivation Original motivation was after [MMDetection PR #9533](https://github.com/open-mmlab/mmdetection/pull/9533) With several experiments I found out that if a ndarray is contiguous, numpy.transpose + torch.contiguous perform better, while if not, then use numpy.ascontiguousarray + numpy.transpose ## Modification Replace numpy.ascontiguousarray with torch.contiguous in [PackSegInputs](https://github.com/open-mmlab/mmsegmentation/blob/1.x/mmseg/datasets/transforms/formatting.py) Co-authored-by: MeowZheng <meowzheng@outlook.com>
This commit is contained in:
parent
9b8e8b730c
commit
2e27f8b678
@ -63,8 +63,12 @@ class PackSegInputs(BaseTransform):
|
||||
img = results['img']
|
||||
if len(img.shape) < 3:
|
||||
img = np.expand_dims(img, -1)
|
||||
img = np.ascontiguousarray(img.transpose(2, 0, 1))
|
||||
packed_results['inputs'] = to_tensor(img)
|
||||
if not img.flags.c_contiguous:
|
||||
img = to_tensor(np.ascontiguousarray(img.transpose(2, 0, 1)))
|
||||
else:
|
||||
img = img.transpose(2, 0, 1)
|
||||
img = to_tensor(img).contiguous()
|
||||
packed_results['inputs'] = img
|
||||
|
||||
data_sample = SegDataSample()
|
||||
if 'gt_seg_map' in results:
|
||||
|
Loading…
x
Reference in New Issue
Block a user