Before installing the service module, you need to prepare the inference model and put it in the correct path. The default model path is:
```
Model structure file: ./inference/cls_infer.pdmodel
Model parameters file: ./inference/cls_infer.pdiparams
Model structure file: PaddleClas/inference/inference.pdmodel
Model parameters file: PaddleClas/inference/inference.pdiparams
```
**The model path can be found and modified in `params.py`.** More models provided by PaddleClas can be obtained from the [model library](../../docs/en/models/models_intro_en.md). You can also use models trained by yourself.
* The model file path can be viewed and modified in `PaddleClas/deploy/hubserving/clas/params.py`.
It should be noted that the prefix of model structure file and model parameters file must be `inference`.
* More models provided by PaddleClas can be obtained from the [model library](../../docs/en/models/models_intro_en.md). You can also use models trained by yourself.
### 3. Install Service Module
* On Linux platform, the examples are as follows.
```shell
hub install deploy/hubserving/clas/
cd PaddleClas/deploy
hub install hubserving/clas/
```
* On Windows platform, the examples are as follows.
```shell
hub install deploy\hubserving\clas\
cd PaddleClas\deploy
hub install hubserving\clas\
```
### 4. Start service
...
...
@@ -103,32 +109,30 @@ Wherein, the format of `config.json` is as follows:
For example, use GPU card No. 3 to start the 2-stage series service:
-**image_path**: Test image path, can be a single image path or an image directory path
-**top_k**: [**Optional**] Return the top `top_k` 's scores ,default by `1`.
-**batch_size**: [**Optional**] batch_size. Default by `1`.
-**resize_short**: [**Optional**] Resize the input image according to short size. Default by `256`.
-**resize**: [**Optional**] Resize the input image. Default by `224`.
-**normalize**: [**Optional**] Whether normalize the input image. Default by `True`.
**Notice**:
If you want to use `Transformer series models`, such as `DeiT_***_384`, `ViT_***_384`, etc., please pay attention to the input size of model, and need to set `--resize_short=384`, `--resize=384`.
└─ float: The time cost of predicting the picture, unit second
```
**Note:** If you need to add, delete or modify the returned fields, you can modify the file `module.py` of the corresponding module. For the complete process, refer to the user-defined modification service module in the next section.
**Note:** If you need to add, delete or modify the returned fields, you can modify the corresponding module. For the details, refer to the user-defined modification service module in the next section.
## User defined service module modification
If you need to modify the service logic, the following steps are generally required:
...
...
@@ -151,20 +155,41 @@ If you need to modify the service logic, the following steps are generally requi
```shell
hub serving stop --port/-p XXXX
```
2. Modify the code in the corresponding files, like `module.py` and `params.py`, according to the actual needs.
For example, if you need to replace the model used by the deployed service, you need to modify model path parameters `cfg.model_file` and `cfg.params_file` in `params.py`. Of course, other related parameters may need to be modified at the same time. Please modify and debug according to the actual situation.
After modifying and installing (`hub install deploy/hubserving/clas/`) and before deploying, you can use `python deploy/hubserving/clas/test.py` to test the installed service module.
2. Modify the code in the corresponding files, like `module.py` and `params.py`, according to the actual needs. You need re-install(hub install hubserving/clas/) and re-deploy after modifing `module.py`.
After modifying and installing and before deploying, you can use `python hubserving/clas/module.py` to test the installed service module.
For example, if you need to replace the model used by the deployed service, you need to modify model path parameters `cfg.model_file` and `cfg.params_file` in `params.py`. Of course, other related parameters may need to be modified at the same time. Please modify and debug according to the actual situation.
3. Uninstall old service module
```shell
hub uninstall clas_system
```
4. Install modified service module
```shell
hub install deploy/hubserving/clas/
hub install hubserving/clas/
```
5. Restart service
```shell
hub serving start -m clas_system
```
**Note**:
Common parameters can be modified in params.py:
* Directory of model files(include model structure file and model parameters file):
```python
"inference_model_dir":
```
* The number of Top-k results returned during post-processing:
```python
'topk':
```
* Mapping file corresponding to label and class ID during post-processing:
```python
'class_id_map_file':
```
In order to avoid unnecessary delay and be able to predict in batch, the preprocessing (include resize, crop and other) is completed in the client, so modify [test_hubserving.py](./test_hubserving.py#L35-L52) if necessary.