Commit b71a1210 authored by Kai Chen's avatar Kai Chen
Browse files

move from models to core

parent d04fa0f3
from functools import partial
import mmcv import mmcv
import numpy as np import numpy as np
import torch from six.moves import map, zip
__all__ = ['tensor2imgs', 'unique', 'unmap', 'results2json'] __all__ = ['tensor2imgs', 'multi_apply', 'unmap', 'results2json']
def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True): def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
...@@ -17,12 +19,10 @@ def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True): ...@@ -17,12 +19,10 @@ def tensor2imgs(tensor, mean=(0, 0, 0), std=(1, 1, 1), to_rgb=True):
return imgs return imgs
def unique(tensor): def multi_apply(func, *args, **kwargs):
if tensor.is_cuda: pfunc = partial(func, **kwargs) if kwargs else func
u_tensor = np.unique(tensor.cpu().numpy()) map_results = map(pfunc, *args)
return tensor.new_tensor(u_tensor) return tuple(map(list, zip(*map_results)))
else:
return torch.unique(tensor)
def unmap(data, count, inds, fill=0): def unmap(data, count, inds, fill=0):
......
from .conv_module import ConvModule from .conv_module import ConvModule
from .norm import build_norm_layer from .norm import build_norm_layer
from .misc import *
from .weight_init import * from .weight_init import *
__all__ = ['ConvModule', 'build_norm_layer'] __all__ = ['ConvModule', 'build_norm_layer']
from functools import partial
from six.moves import map, zip
def multi_apply(func, *args, **kwargs):
pfunc = partial(func, **kwargs) if kwargs else func
map_results = map(pfunc, *args)
return tuple(map(list, zip(*map_results)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment