Metadata-Version: 2.1
Name: pu4c
Version: 1.5.0
Summary: A python utils package for castle945
Home-page: https://github.com/castle945
Author: castle945
Author-email: castle945@njust.edu.cn
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Pyro5
Requires-Dist: rich
Requires-Dist: pyyaml
Requires-Dist: numpy

# castle945 的 Python 工具包

[![PyPI - Version](https://img.shields.io/pypi/v/pu4c)](https://pypi.org/project/pu4c/) ![PyPI - Downloads](https://img.shields.io/pypi/dm/pu4c) [![Coverage Status](https://coveralls.io/repos/github/castle945/pyutils4castle945/badge.svg?branch=main)](https://coveralls.io/github/castle945/pyutils4castle945?branch=main)

### 介绍

castle945 的 Python 工具包，主要功能包括：深度学习单元测试工具集、三维数据可视化等

#### 设计思路

1. 模块内文件组织：工具函数写到如 `utils/common_utils.py`，模块的主要功能实现写到如 `dictdb.py`，个人偏好的端口号等默认参数配置（可按需更改）写到 `config.py`
2. 模块接口暴露规则：函数尽量全暴露到包名下，直接 `pu4c.xxx` 以简化调用和减少接口变动
3. 快速导包：保证 `import pu4c` 快速执行，这要求函数内导包，① 对于大型依赖库的工具函数如 open3d_utils.py 可以正常文件头导包，但不暴露到包名下即只能 `from pu4c.cv.open3d_utils import xxx` ② 对于其他文件内，大型依赖库只在函数内部导包（Python 导包有缓存机制，多次导入与单次导入耗时一致）
4. 依赖随用随装：安装时尽量不依赖其他库，使用时安装缺失的依赖库即可正常运行

### 安装

```bash
# pip 安装使用
pip install pu4c

# 源码安装
pip install -e .

# 执行单元测试
pip install pytest coverage
mkdir work_dirs/
pytest tests/
# 本地运行并查看单元测试覆盖率
coverage run --source=pu4c -m pytest tests/
coverage report
# 手动上传到 coveralls(因为 CI/CD 则需要测试数据文件，比较大)
pip install coveralls
export COVERALLS_REPO_TOKEN=XXXXX # 登录/AddRepo/StartUploadingCoverage/...
coveralls

# 打包上传 pypi
pip install setuptools wheel twine
python3 setup.py sdist bdist_wheel
twine upload dist/*
pip install pu4c -i https://pypi.org/simple
```

### 快速入门

#### 服务器端数据在本地界面中可视化

```bash
# 本地计算机作为 RPC 服务端
python -c "import pu4c; pu4c.start_rpc_server()"
ssh user@ip -R 30570:localhost:30570   # SSH 转发并在使用过程中保持终端 ssh 连接不断开，端口配置位于 pu4c/config.py，参数 -R remote_port:localhost:local_port
ssh user2@ip2 -R 30570:localhost:30570 # 可选，支持同时将多台服务器的端口转发到本机的同一个端口
# autossh -M 0 -fNT -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure yes" -L 9117:localhost:9117 -R 30570:localhost:30570 -R 30571:localhost:30571 amax4090

# 服务器作为 RPC 客户端，可在交互式终端（如调试终端）中使用
import pu4c
pu4c.cloud_viewer(filepath="/datasets/KITTI/object/training/velodyne/000000.bin", num_features=4, rpc=True) # 置 rpc=True 进行远程函数调用

# 注意
# 如果远程函数调用时使用了文件路径作为参数需要确保 RPC 服务器上存在该文件，可以通过 nfs 挂载到相同路径，或者修改 rpc 装饰器修改路径前缀
```

| ![demo_det3d.png](docs/demo_det3d.png) | ![demo_seg3d.png](docs/demo_seg3d.png) | ![demo_occ3d.png](docs/demo_occ3d.png) |
| :----------------------------------: | :----------------------------------: | :----------------------------------: |
|          三维目标检测可视化          |          三维语义分割可视化          |          三维占据预测可视化          |

### 许可证

本代码采用 [GPL-3.0](LICENSE) 许可发布，这意味着你可以自由复制和分发软件，无论个人使用还是商业用途，但修改后的源码不可闭源且必须以相同的许可证发布
