提交 f87e4709 编写于 作者: W wuzewu

Fix the problem that new models such as openpose cannot use command line prediction

上级 f40cdd8e
...@@ -2,5 +2,8 @@ import paddle ...@@ -2,5 +2,8 @@ import paddle
import paddlehub as hub import paddlehub as hub
if __name__ == '__main__': if __name__ == '__main__':
model = hub.Module(name='resnet50_vd_imagenet_ssld', label_list=["roses", "tulips", "daisy", "sunflowers", "dandelion"], load_checkpoint=None) model = hub.Module(
result, feature = model.predict('flower.jpg') name='resnet50_vd_imagenet_ssld',
\ No newline at end of file label_list=["roses", "tulips", "daisy", "sunflowers", "dandelion"],
load_checkpoint=None)
result = model.predict('flower.jpg')
...@@ -66,17 +66,6 @@ def serving(func: Callable) -> Callable: ...@@ -66,17 +66,6 @@ def serving(func: Callable) -> Callable:
class RunModule(object): class RunModule(object):
'''The base class of PaddleHub Module, users can inherit this class to implement to realize custom class.''' '''The base class of PaddleHub Module, users can inherit this class to implement to realize custom class.'''
def __init__(self, *args, **kwargs):
# Avoid module being initialized multiple times
if '_is_initialize' in self.__dict__ and self._is_initialize:
return
super(RunModule, self).__init__()
_run_func_name = self._get_func_name(self.__class__, _module_runnable_func)
self._run_func = getattr(self, _run_func_name) if _run_func_name else None
self._serving_func_name = self._get_func_name(self.__class__, _module_serving_func)
self._is_initialize = True
def _get_func_name(self, current_cls: Generic, module_func_dict: dict) -> Optional[str]: def _get_func_name(self, current_cls: Generic, module_func_dict: dict) -> Optional[str]:
mod = current_cls.__module__ + '.' + current_cls.__name__ mod = current_cls.__module__ + '.' + current_cls.__name__
if mod in module_func_dict: if mod in module_func_dict:
...@@ -116,17 +105,25 @@ class RunModule(object): ...@@ -116,17 +105,25 @@ class RunModule(object):
with open(req_file, 'r') as file: with open(req_file, 'r') as file:
return file.read().split('\n') return file.read().split('\n')
@property
def _run_func_name(self):
return self._get_func_name(self.__class__, _module_runnable_func)
@property
def _run_func(self):
return getattr(self, self._run_func_name) if self._run_func_name else None
@property @property
def is_runnable(self) -> bool: def is_runnable(self) -> bool:
''' '''
Whether the Module is runnable, in other words, whether can we execute the Module through the Whether the Module is runnable, in other words, whether can we execute the Module through the
`hub run` command. `hub run` command.
''' '''
return self._run_func != None return True if self._run_func else False
@property @property
def serving_func_name(self): def serving_func_name(self):
return self._serving_func_name return self._get_func_name(self.__class__, _module_serving_func)
class Module(object): class Module(object):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册