提交 d9e5d161 编写于 作者: Z Zeyu Chen

fix error of python runing

上级 efb55496
...@@ -41,6 +41,9 @@ class Module(object): ...@@ -41,6 +41,9 @@ class Module(object):
def __init__(self, module_url=None, module_dir=None): def __init__(self, module_url=None, module_dir=None):
if module_url == None and module_dir == None: if module_url == None and module_dir == None:
raise Exception("Module:module_url and module_dir are None!") raise Exception("Module:module_url and module_dir are None!")
self.module_dir = ""
self.module_name = ""
# donwload module # donwload module
if module_url is not None and module_url.startswith("http"): if module_url is not None and module_url.startswith("http"):
# if it's remote url link, then download and uncompress it # if it's remote url link, then download and uncompress it
...@@ -48,9 +51,9 @@ class Module(object): ...@@ -48,9 +51,9 @@ class Module(object):
module_url) module_url)
elif module_dir is not None: elif module_dir is not None:
# otherwise it's local path, no need to deal with it # otherwise it's local path, no need to deal with it
self.module_dir = module_url self.module_dir = module_dir
# use the path name as module name by default # use the path name as module name by default
self.module_name = module_url.split("/")[-1] self.module_name = module_dir.split("/")[-1]
# load paddle inference model # load paddle inference model
place = fluid.CPUPlace() place = fluid.CPUPlace()
...@@ -66,8 +69,8 @@ class Module(object): ...@@ -66,8 +69,8 @@ class Module(object):
print("fetch_targets") print("fetch_targets")
print(self.fetch_targets) print(self.fetch_targets)
config = ModuleConfig(self.module_dir) self.config = ModuleConfig(self.module_dir)
config.load() self.config.load()
# load assets # load assets
# self.dict = defaultdict(int) # self.dict = defaultdict(int)
# self.dict.setdefault(0) # self.dict.setdefault(0)
...@@ -266,8 +269,8 @@ class ModuleUtils(object): ...@@ -266,8 +269,8 @@ class ModuleUtils(object):
if __name__ == "__main__": if __name__ == "__main__":
module_link = "http://paddlehub.cdn.bcebos.com/word2vec/w2v_saved_inference_module.tar.gz" url = "http://paddlehub.cdn.bcebos.com/word2vec/word2vec-dim16-simple-example-2.tar.gz"
m = Module(module_link) m = Module(module_url=url)
inputs = [["it", "is", "new"], ["hello", "world"]] inputs = [["it", "is", "new"], ["hello", "world"]]
#tensor = m._process_input(inputs) #tensor = m._process_input(inputs)
#print(tensor) #print(tensor)
......
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__all__ = ["mkdir"]
def mkdir(path):
""" the same as the shell command mkdir -p "
"""
if not os.path.exists(path):
os.makedirs(path)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册