diff --git a/docs/quick_experience/python_use_hub.md b/docs/quick_experience/python_use_hub.md index 1101e3f96297329ef2a6e15b7548a504c9a9b9cf..35d70802a1c34e0ccec84f940ce321afb97f5c1a 100644 --- a/docs/quick_experience/python_use_hub.md +++ b/docs/quick_experience/python_use_hub.md @@ -294,4 +294,3 @@ print("情感分析结果:", res) ## 总结 PaddleHub提供了丰富的预训练模型,包括图像分类、语义模型、视频分类、图像生成、图像分割、文本审核、关键点检测等主流模型,只需要3行Python代码即可快速调用,即时输出预测结果,非常方便。您可以尝试一下,从[预训练模型列表](https://www.paddlepaddle.org.cn/hublist)中选择一些模型体验一下。 - diff --git a/docs/tutorial/how_to_finetune.md b/docs/tutorial/how_to_finetune.md index f14dce53f12dabd23d94e0caf8e423fd7609ea6a..d3e5a38a67d5e35e4eed074dad1bd2bd58d3d8d2 100644 --- a/docs/tutorial/how_to_finetune.md +++ b/docs/tutorial/how_to_finetune.md @@ -374,5 +374,3 @@ for batch_result in results: 交通方便;环境很好;服务态度很好 房间较小 predict=1 19天硬盘就罢工了,算上运来的一周都没用上15天,可就是不能换了。唉,你说这算什么事呀! predict=0 ``` - - diff --git a/docs/tutorial/how_to_load_data.md b/docs/tutorial/how_to_load_data.md index 73e3ae8a068429a9b37fd1efd709bdace1509c32..b11065807da2175f557e755f3ddb6ca3108aef8f 100644 --- a/docs/tutorial/how_to_load_data.md +++ b/docs/tutorial/how_to_load_data.md @@ -71,4 +71,3 @@ label_list.txt内容如下: cat dog ``` - diff --git a/paddlehub/commands/convert.py b/paddlehub/commands/convert.py index 6fed432a4eb501673f8c39c004326b47485bb333..0ff13888c1b1105f893122a230bf093678483599 100644 --- a/paddlehub/commands/convert.py +++ b/paddlehub/commands/convert.py @@ -43,10 +43,8 @@ class ConvertCommand(BaseCommand): add_help=True) self.parser.add_argument('command') self.parser.add_argument('--module_name', '-n') - self.parser.add_argument('--module_version', - '-v', - nargs='?', - default='1.0.0') + self.parser.add_argument( + '--module_version', '-v', nargs='?', default='1.0.0') self.parser.add_argument('--model_dir', '-d') self.parser.add_argument('--output_dir', '-o') @@ -62,27 +60,28 @@ class ConvertCommand(BaseCommand): arcname = os.path.join(self.module, 'assets', file) tfp.add(fullpath, arcname=arcname) - tfp.add(self.model_file, - arcname=os.path.join(self.module, MODULE_FILE)) - tfp.add(self.serving_file, - arcname=os.path.join(self.module, SERVING_FILE)) - tfp.add(self.init_file, - arcname=os.path.join(self.module, INIT_FILE)) + tfp.add( + self.model_file, arcname=os.path.join(self.module, MODULE_FILE)) + tfp.add( + self.serving_file, + arcname=os.path.join(self.module, SERVING_FILE)) + tfp.add( + self.init_file, arcname=os.path.join(self.module, INIT_FILE)) def create_module_py(self): - template_file = open(os.path.join(TMPL_DIR, 'x_model.tmpl'), - 'r', - encoding='utf-8') + template_file = open( + os.path.join(TMPL_DIR, 'x_model.tmpl'), 'r', encoding='utf-8') tmpl = Template(template_file.read()) lines = [] lines.append( - tmpl.substitute(NAME="'{}'".format(self.module), - TYPE="'CV'", - AUTHOR="'Baidu'", - SUMMARY="''", - VERSION="'{}'".format(self.version), - EMAIL="''")) + tmpl.substitute( + NAME="'{}'".format(self.module), + TYPE="'CV'", + AUTHOR="'Baidu'", + SUMMARY="''", + VERSION="'{}'".format(self.version), + EMAIL="''")) # self.model_file = os.path.join(self.dest, MODULE_FILE) self.model_file = os.path.join(self._tmp_dir, MODULE_FILE) if os.path.exists(self.model_file): @@ -101,9 +100,8 @@ class ConvertCommand(BaseCommand): shutil.copyfile(os.path.join(TMPL_DIR, 'init_py.tmpl'), self.init_file) def create_serving_demo_py(self): - template_file = open(os.path.join(TMPL_DIR, 'serving_demo.tmpl'), - 'r', - encoding='utf-8') + template_file = open( + os.path.join(TMPL_DIR, 'serving_demo.tmpl'), 'r', encoding='utf-8') tmpl = Template(template_file.read()) lines = [] diff --git a/paddlehub/tokenizer/tokenizer.py b/paddlehub/tokenizer/tokenizer.py index f2f9111a1fbd974cb6ac1801a604d766228f29b0..3653cfd5d5ae5e645e7e78ae238bb9c5a730761d 100644 --- a/paddlehub/tokenizer/tokenizer.py +++ b/paddlehub/tokenizer/tokenizer.py @@ -78,11 +78,7 @@ class CustomTokenizer(object): def _convert_token_to_id(self, token): """ Converts a token (str) in an id using the vocab. """ - v = self.vocab.get(token, None) - if v: - return v - else: - return 0 + return self.vocab.get(token, None) def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" @@ -211,11 +207,11 @@ class CustomTokenizer(object): return ids elif isinstance(text, (list, tuple)) and len(text) > 0 and isinstance( - text[0], str): + text[0], str): return self.convert_tokens_to_ids(text) elif isinstance(text, (list, tuple)) and len(text) > 0 and isinstance( - text[0], int): + text[0], int): return text else: raise ValueError( @@ -354,7 +350,7 @@ class CustomTokenizer(object): """ out_string = (out_string.replace(" .", ".").replace(" ?", "?").replace( " !", "!").replace(" ,", ",").replace(" ' ", "'").replace( - " n't", - "n't").replace(" 'm", "'m").replace(" 's", "'s").replace( - " 've", "'ve").replace(" 're", "'re")) + " n't", + "n't").replace(" 'm", "'m").replace(" 's", "'s").replace( + " 've", "'ve").replace(" 're", "'re")) return out_string diff --git a/requirements.txt b/requirements.txt index 967b6b0ab62b66865c4794bec68de9e959371709..a6c8bc55b9c7be6101cbf4f1ecc76c44d2f444fe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,9 +10,10 @@ sentencepiece colorlog tqdm nltk +opencv-python # pandas no longer support python2 in version 0.25 and above -pandas ; python_version >= "3" +pandas # gunicorn not support windows gunicorn >= 19.10.0; sys_platform != "win32"