未验证 提交 a2db134e 编写于 作者: W wuzewu 提交者: GitHub

Merge branch 'develop' into add_photopen_module

...@@ -50,16 +50,16 @@ ...@@ -50,16 +50,16 @@
## 三、模型API预测 ## 三、模型API预测
- ### 1、代码示例 - ### 1、预测代码示例
- ```python - ```python
import paddlehub as hub import paddlehub as hub
import cv2 import cv2
model = hub.Module(name="U2Net_Portrait") model = hub.Module(name="U2Net_Portrait")
result = model.Cartoon_GEN(images=[cv2.imread('/PATH/TO/IMAGE')]) result = model.Portrait_GEN(images=[cv2.imread('/PATH/TO/IMAGE')])
# or # or
# result = model.Cartoon_GEN(paths=['/PATH/TO/IMAGE']) # result = model.Portrait_GEN(paths=['/PATH/TO/IMAGE'])
``` ```
- ### 2、API - ### 2、API
......
...@@ -15,10 +15,11 @@ ...@@ -15,10 +15,11 @@
import os import os
import subprocess import subprocess
import sys
from typing import IO from typing import IO
from paddlehub.utils.utils import Version from paddlehub.utils.utils import Version
from paddlehub.utils.io import discard_oe, typein from paddlehub.utils.io import discard_oe
def get_installed_packages() -> dict: def get_installed_packages() -> dict:
...@@ -40,13 +41,14 @@ def check(package: str, version: str = '') -> bool: ...@@ -40,13 +41,14 @@ def check(package: str, version: str = '') -> bool:
return pdict[package].match(version) return pdict[package].match(version)
def install(package: str, version: str = '', upgrade: bool = False, ostream: IO = None, estream: IO = None) -> bool: def install(package: str, version: str = '', upgrade: bool = False, ostream: IO = sys.stdout,
estream: IO = sys.stderr) -> bool:
'''Install the python package.''' '''Install the python package.'''
package = package.replace(' ', '') package = package.replace(' ', '')
if version: if version:
package = '{}=={}'.format(package, version) package = '{}=={}'.format(package, version)
cmd = 'pip install "{}"'.format(package) cmd = '{} -m pip install "{}"'.format(sys.executable, package)
if upgrade: if upgrade:
cmd += ' --upgrade' cmd += ' --upgrade'
...@@ -59,9 +61,9 @@ def install(package: str, version: str = '', upgrade: bool = False, ostream: IO ...@@ -59,9 +61,9 @@ def install(package: str, version: str = '', upgrade: bool = False, ostream: IO
return result == 0 return result == 0
def install_from_file(file: str, ostream: IO = None, estream: IO = None) -> bool: def install_from_file(file: str, ostream: IO = sys.stdout, estream: IO = sys.stderr) -> bool:
'''Install the python package.''' '''Install the python package.'''
cmd = 'pip install -r {}'.format(file) cmd = '{} -m pip install -r {}'.format(sys.executable, file)
result, content = subprocess.getstatusoutput(cmd) result, content = subprocess.getstatusoutput(cmd)
if result: if result:
...@@ -71,14 +73,13 @@ def install_from_file(file: str, ostream: IO = None, estream: IO = None) -> bool ...@@ -71,14 +73,13 @@ def install_from_file(file: str, ostream: IO = None, estream: IO = None) -> bool
return result == 0 return result == 0
def uninstall(package: str, ostream: IO = None, estream: IO = None) -> bool: def uninstall(package: str, ostream: IO = sys.stdout, estream: IO = sys.stderr) -> bool:
'''Uninstall the python package.''' '''Uninstall the python package.'''
with typein('y'): # type in 'y' to confirm the uninstall operation
# type in 'y' to confirm the uninstall operation cmd = '{} -m pip uninstall {} -y'.format(sys.executable, package)
cmd = 'pip uninstall {}'.format(package) result, content = subprocess.getstatusoutput(cmd)
result, content = subprocess.getstatusoutput(cmd) if result:
if result: estream.write(content)
estream.write(content) else:
else: ostream.write(content)
ostream.write(content)
return result == 0 return result == 0
...@@ -8,7 +8,7 @@ matplotlib ...@@ -8,7 +8,7 @@ matplotlib
opencv-python opencv-python
packaging packaging
paddle2onnx >= 0.5.1 paddle2onnx >= 0.5.1
paddlenlp >= 2.0.0rc5 paddlenlp >= 2.0.0
Pillow Pillow
pyyaml pyyaml
pyzmq pyzmq
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册