Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions docs/how-to-run-in-15-minutes.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ $ conda activate py38
```bash
$ python3 -m pip install pyflow-0.1.0-py38-none-linux_x86_64.whl --force-reinstall
```
完成后应该可以 `import pyflow`

.whl 封装了 `pyflow`和 Rust 可执行文件 `run_with_plugins_python_wrap`。完成后应该可以运行
```bash
$ run_with_plugins_python_wrap --help
run_with_plugins 1.0
megvii
...
$ python3
Python 3.8.3 (default, May 19 2020, 18:47:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyflow
```
.whl 打包了可执行文件 `run_with_plugins`,如果使用 conda 位置应该在

此处常见问题:`error while loading shared libraries: libpython3.8.xxx`。如果使用 conda 只需要
```bash
$ export LD_LIBRARY_PATH=/home/`whoami`/miniconda3/pkgs/python-3.8.11-h12debd9_0_cpython/lib:${LD_LIBRARY_PATH}
```

被封装的内容安装在 miniconda3 路径下,有兴趣不妨确认一下
```bash
$ cd ${HOME}/miniconda3/envs/py38/lib/python3.8/site-packages/pyflow/
$ sudo apt install build-essential -y
Expand All @@ -51,18 +62,12 @@ megvii

## Python“开机自检”

`logical_test` 是 MegFlow/flow-python/examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。
```bash
$ cd ${MegFlow_PATH}/flow-python/examples # 这行必须
$ run_with_plugins -p logical_test
```

`logical_test` 是 examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。

此处常见问题:`error while loading shared libraries: libpython3.8.xxx`。如果使用 conda 只需要
```bash
$ export LD_LIBRARY_PATH=/home/`whoami`/miniconda3/pkgs/python-3.8.11-h12debd9_0_cpython/lib:${LD_LIBRARY_PATH}
$ cd ${MegFlow_PATH}/flow-python/examples
$ run_with_plugins_python_wrap -p logical_test
...
```

> 工作原理:[pyflow](../flow-python/pyflow/__init__.py) 仅是一层接口,由 run_with_plugins “注入”建图/调度/优化等实现。

## Python Built-in Applications
Expand Down
2 changes: 2 additions & 0 deletions flow-python/examples/cat_finder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $ python3
```bash
$ cd flow-python/examples
$ pip3 install -r requires.txt
$ run_with_plugins_python_wrap -c cat_finder/image_cpu.toml -p cat_finder # 如果用 prebuilt 包,不需要用`cargo run --example run_with_plugins --`
$ cargo run --example run_with_plugins -- -c cat_finder/image_gpu.toml -p cat_finder # 有 GPU 的机器执行这个
$ cargo run --example run_with_plugins -- -c cat_finder/image_cpu.toml -p cat_finder # 无 GPU 的 laptop 执行这句
```
Expand Down Expand Up @@ -110,6 +111,7 @@ $ ffmpeg -re -stream_loop -1 -i ${models}/cat_finder_testdata/test1.ts -c copy -
启动视频识别服务
```bash
$ cd flow-python/examples
$ run_with_plugins_python_wrap -c cat_finder/video_cpu.toml -p cat_finder # 如果用 prebuilt 包,不需要用`cargo run --example run_with_plugins --`编译
$ cargo run --example run_with_plugins -- -c cat_finder/video_gpu.toml -p cat_finder # 有 GPU 的机器
$ cargo run --example run_with_plugins -- -c cat_finder/video_cpu.toml -p cat_finder # 无 GPU 的设备用这句
```
Expand Down
3 changes: 2 additions & 1 deletion flow-python/examples/electric_bicycle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ $ pip3 install onnxruntime --user
启动服务
```bash
$ cd flow-python/examples
$ cargo run --example run_with_plugins -- -c electric_bicycle/electric_bicycle.toml -p electric_bicycle
$ run_with_plugins_python_wrap -c electric_bicycle/electric_bicycle.toml -p electric_bicycle # prebuilt 安装用这个,不需要`cargo run`来编译
$ cargo run --example run_with_plugins -- -c electric_bicycle/electric_bicycle.toml -p electric_bicycle # 源码或 docker 安装用这个
```
服务配置文件在`electric_bicycle/electric_bicycle.toml`,解释参考 [how-to-add-graph](../.../../docs/how-to-add-graph.zh.md) 。这里只需要打开 8083 端口服务,操作和[猫猫围栏](../cat_finder/README.zh.md) 近似。

Expand Down
4 changes: 2 additions & 2 deletions flow-python/gen_whl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ python3 whl-py36-setup.py bdist_wheel -p linux-x86_64 -d py36_dist --python-ta

conda activate py37
cargo build --example run_with_plugins --release
ldd pyflow/run_with_plugins
cp ../target/release/examples/run_with_plugins ./pyflow/
ldd pyflow/run_with_plugins
rm -rf ./build
python3 whl-py37-setup.py bdist_wheel -p linux-x86_64 -d py37_dist --python-tag py37

conda activate py38
cargo build --example run_with_plugins --release
ldd pyflow/run_with_plugins
cp ../target/release/examples/run_with_plugins ./pyflow/
ldd pyflow/run_with_plugins
rm -rf ./build
python3 whl-py38-setup.py bdist_wheel -p linux-x86_64 -d py38_dist --python-tag py38

Expand Down
19 changes: 19 additions & 0 deletions flow-python/pyflow/command_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
import subprocess
import pkg_resources
def main():
bin_exist = pkg_resources.resource_exists('pyflow', 'run_with_plugins')
if not bin_exist:
print('cannot find run_with_plugins, exit!')
sys.exit(-1)
bin_path = pkg_resources.resource_filename('pyflow', 'run_with_plugins')

sys.argv[0] = bin_path
ret = subprocess.Popen(sys.argv)
ret.wait()

if __name__ == '__main__':
main()


6 changes: 5 additions & 1 deletion flow-python/whl-py36-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
python_requires='>=3.6,<3.7',
package_data={
"":['run_with_plugins']
}
},
entry_points={
'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'],
},

)

6 changes: 5 additions & 1 deletion flow-python/whl-py37-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
python_requires='>=3.7,<3.8',
package_data={
"":['run_with_plugins']
}
},
entry_points={
'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'],
},

)

6 changes: 5 additions & 1 deletion flow-python/whl-py38-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
python_requires='>=3.8,<3.9',
package_data={
"":['run_with_plugins']
}
},
entry_points={
'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'],
},

)