Skip to content

[Feat] Support saving and loading models in different formats #3758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)
[![Version](https://img.shields.io/github/release/PaddlePaddle/PaddleSeg.svg)](https://github.com/PaddlePaddle/PaddleSeg/releases)
![python version](https://img.shields.io/badge/python-3.6+-orange.svg)
![python version](https://img.shields.io/badge/python-3.8+-orange.svg)
![support os](https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-yellow.svg)
![stars](https://img.shields.io/github/stars/PaddlePaddle/PaddleSeg?color=ccf)
</div>
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ English | [简体中文](README_CN.md)

[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)
[![Version](https://img.shields.io/github/release/PaddlePaddle/PaddleSeg.svg)](https://github.com/PaddlePaddle/PaddleSeg/releases)
![python version](https://img.shields.io/badge/python-3.6+-orange.svg)
![python version](https://img.shields.io/badge/python-3.8+-orange.svg)
![support os](https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-yellow.svg)
![stars](https://img.shields.io/github/stars/PaddlePaddle/PaddleSeg?color=ccf)

2 changes: 1 addition & 1 deletion deploy/python/collect_dynamic_shape.py
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ def collect_dynamic_shape(args):

# prepare config
cfg = DeployConfig(args.config)
pred_cfg = PredictConfig(cfg.model, cfg.params)
pred_cfg = PredictConfig(cfg.model_dir, cfg.model_prefix)
pred_cfg.enable_use_gpu(1000, 0)
pred_cfg.collect_shape_range_info(args.dynamic_shape_path)

4 changes: 2 additions & 2 deletions deploy/python/infer.py
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ def auto_tune(args, imgs, img_nums):
num = min(len(imgs), img_nums)

cfg = DeployConfig(args.cfg)
pred_cfg = PredictConfig(cfg.model, cfg.params)
pred_cfg = PredictConfig(cfg.model_dir, cfg.model_prefix)
pred_cfg.enable_use_gpu(100, 0)
if not args.print_detail:
pred_cfg.disable_glog_info()
@@ -139,7 +139,7 @@ def __init__(self, args):
logger=logger)

def _init_base_config(self):
self.pred_cfg = PredictConfig(self.cfg.model, self.cfg.params)
self.pred_cfg = PredictConfig(self.cfg.model_dir, self.cfg.model_prefix)
if not self.args.print_detail:
self.pred_cfg.disable_glog_info()
self.pred_cfg.enable_memory_optim()
2 changes: 1 addition & 1 deletion deploy/python/infer_dataset.py
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ def auto_tune(args, dataset, img_nums):
num = min(len(dataset), img_nums)

cfg = DeployConfig(args.cfg)
pred_cfg = PredictConfig(cfg.model, cfg.params)
pred_cfg = PredictConfig(cfg.model_dir, cfg.model_prefix)
pred_cfg.enable_use_gpu(100, 0)
if not args.print_detail:
pred_cfg.disable_glog_info()
6 changes: 3 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -8,20 +8,20 @@ English | [简体中文](install_cn.md)
- pip/pip3(9.0.1+),64-bit version
- CUDA >= 10.2
- cuDNN >= 7.6
- PaddlePaddle (the version >= 2.4)
- PaddlePaddle (the version >= 3.0.0b0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仿照PaddleNLP,接口变更后不再支持旧版本Paddle。


## 2 Installation

### 2.1 Install PaddlePaddle

Please refer to the [installation doc](https://www.paddlepaddle.org.cn/documentation/docs/en/install/index_en.html) to install PaddlePaddle (the version >= 2.4).
Please refer to the [installation doc](https://www.paddlepaddle.org.cn/documentation/docs/en/install/index_en.html) to install PaddlePaddle (the version >= 3.0.0b0).

Highly recommend you install the GPU version of PaddlePaddle, due to the large overhead of segmentation models, otherwise, it could be out of memory while running the models.

For example, run the following command to install Paddle with pip for Linux, CUDA 10.2.

```
python -m pip install paddlepaddle-gpu==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install paddlepaddle-gpu==3.0.0b0 -i https://pypi.tuna.tsinghua.edu.cn/simple
```


6 changes: 3 additions & 3 deletions docs/install_cn.md
Original file line number Diff line number Diff line change
@@ -9,18 +9,18 @@
- pip/pip3(9.0.1+),64位版本
- CUDA >= 10.2
- cuDNN >= 7.6
- PaddlePaddle (版本==2.5)
- PaddlePaddle (版本>=3.0.0b0)

## 2 本地安装说明

### 2.1 安装PaddlePaddle

请参考[快速安装文档](https://www.paddlepaddle.org.cn/install/quick)或者[详细安装文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/install/index_cn.html),安装PaddlePaddle (要求不低于2.4版本,推荐安装最新版本)。
请参考[快速安装文档](https://www.paddlepaddle.org.cn/install/quick)或者[详细安装文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/install/index_cn.html),安装PaddlePaddle (要求不低于3.0.0b0版本,推荐安装最新版本)。

比如Linux、CUDA 10.2,使用pip安装GPU版本,执行如下命令。

```
python -m pip install paddlepaddle-gpu==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install paddlepaddle-gpu==3.0.0b0 -i https://pypi.tuna.tsinghua.edu.cn/simple
```

使用如下命令验证PaddlePaddle是否安装成功,并且查看版本。
8 changes: 4 additions & 4 deletions paddleseg/deploy/infer.py
Original file line number Diff line number Diff line change
@@ -34,12 +34,12 @@ def transforms(self):
return self._transforms

@property
def model(self):
return os.path.join(self._dir, self.dic['Deploy']['model'])
def model_dir(self):
return self._dir

@property
def params(self):
return os.path.join(self._dir, self.dic['Deploy']['params'])
def model_prefix(self):
return self.dic['Deploy']['model_prefix']

@staticmethod
def load_transforms(t_list):
2 changes: 1 addition & 1 deletion paddleseg/models/backbones/efficientformerv2.py
Original file line number Diff line number Diff line change
@@ -203,7 +203,7 @@ def forward_tokens(self, x):
def forward(self, x):
x = self.patch_embed(x)
x = self.forward_tokens(x)
if self.mode is not 'multi_scale':
if self.mode != 'multi_scale':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

顺带修复bug,与PR主题无关。

x = [
paddle.concat(
[
3 changes: 1 addition & 2 deletions tools/export.py
Original file line number Diff line number Diff line change
@@ -97,8 +97,7 @@ def main(args):
# TODO add test config
deploy_info = {
'Deploy': {
'model': save_name + '.pdmodel',
'params': save_name + '.pdiparams',
'model_prefix': save_name,
'transforms': transforms,
'input_shape': shape,
'output_op': args.output_op,