SH-Alg 功能添加流程
2019-10-18 本文已影响0人
SnorlaxSE
新建分支
Step1: 无特殊情况,从dev/master
添加新分支dev/username/ToolID
Step2: git pull
代码
Alg/submodule/NewTool
_NewToolFunc.py
# 提供_NewTool.py需要的功能函数
_NewTool.py
from MeDas.Alg.common import *
from ._NewToolFunc import *
if os.environ.get('__NewTool_BACKEND__', '') == 'herculer':
pass
class NewTool(ToolObject):
"""
@brief 新工具功能简介
"""
@staticmethod
def version():
return (0, 1, 0, 0, 'develop')
@property
def inputs(self) -> [ParamPlug]:
return [
ImagePlug('parameter1'), # ImagePlug() 支持nii | dcm | numpy,不支持PNG路径
FrontEndPlugM('parameter2', typ=float, default=0)
FrontEndPlugM('parameter3', typ=str, default='replace')
]
@property
def output_constructor(self):
return ImageCons() # VariableCons
def kernel(self, parameter1, parameter2, parameter3):
ToolLogger.info('Enter')
# 功能实现
# ...
ToolLogger.info('Exit')
return Image_cons # Variable_cons
__init__.py
from ._NewTool import NewTool
UnitTest
test_VisualFeature.py
from MeDas.Alg.common.test import *
from MeDas.Alg.submodule.NewTool._NewTool import NewTool
class NewToolTest(MeDasTestCase):
def succ(self, out):
print("NewTool_Test OUT", out)
def fail(self, error):
self.fail('catch error %s' % error)
def test_NewTool_result(self):
data = np.asarray([[[8, 4, 10], [7, 4, 3], [4, 0, 3]],
[[4, 2, 4], [5, 1, 3], [8, 7, 5]]])
result = VisualFeatureTest().set_params(img_tensor=data, submodule=pretrained_module,
target_layer=extract_layer, savedir=savedir).run()\
.get_result().with_succ(self.succ).with_fail(self.fail)
print(result)
ERROR
-
Error Expected object of scalar type Long but got scalar type Float for argument #2 'weight' catched
解决方案: 输入的img_arr = img_arr.astype(np.float32
)