Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#212 from LokeZhou/deploy
Browse files Browse the repository at this point in the history
deploy update README
  • Loading branch information
LokeZhou authored Oct 10, 2023
2 parents d9aa791 + 9d7dd33 commit 0715d11
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
16 changes: 9 additions & 7 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ Python端预测部署主要包含两个步骤:
### 2.1 导出预测模型

```bash
cd deploy/groundingdino
# 导出groundingdino模型
python deploy/groundingdino/export.py -dt "GroundingDino/groundingdino-swint-ogc" --output_dir=./output
python export.py \
--dino_type GroundingDino/groundingdino-swint-ogc
```
导出后目录下,包括 `model_state.pdiparams`, `model_state.pdiparams.info`, `model_state.pdmodel`等文件。

### 2.2 基于python的预测

```bash
python deploy/groundingdino/predict.py \
--text_encoder_type GroundingDino/groundingdino-swint-ogc
--model_path output_groundingdino \
--input_image image_you_want_to_detect.jpg \
-output_dir "dir you want to save the output" \
-prompt "Detect Cat"
python predict.py \
--text_encoder_type GroundingDino/groundingdino-swint-ogc \
--model_path output_groundingdino/GroundingDino/groundingdino-swint-ogc \
--input_image https://bj.bcebos.com/v1/paddlenlp/models/community/GroundingDino/000000004505.jpg \
--output_dir ./groundingdino_predict_output \
--prompt "bus"

```
8 changes: 5 additions & 3 deletions deploy/groundingdino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ python setup_ms_deformable_attn_op.py install
```
## 2.2 静态图导出与预测
```bash
cd deploy/groundingdino

#静态图模型导出
python export.py \
--dino_type GroundingDino/groundingdino-swint-ogc
Expand All @@ -25,8 +27,8 @@ python export.py \
python predict.py \
--text_encoder_type GroundingDino/groundingdino-swint-ogc \
--model_path output_groundingdino/GroundingDino/groundingdino-swint-ogc \
--input_image image_you_want_to_detect.jpg \
-output_dir "dir you want to save the output" \
-prompt "Detect Cat"
--input_image https://bj.bcebos.com/v1/paddlenlp/models/community/GroundingDino/000000004505.jpg \
--output_dir ./groundingdino_predict_output \
--prompt "bus"

```
4 changes: 2 additions & 2 deletions deploy/groundingdino/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
ms_deformable_attn = load(
name="deformable_detr_ops",
sources=[
"./paddlemix/models/groundingdino/csrc/ms_deformable_attn_op.cc",
"./paddlemix/models/groundingdino/csrc/ms_deformable_attn_op.cu",
"../../paddlemix/models/groundingdino/csrc/ms_deformable_attn_op.cc",
"../../paddlemix/models/groundingdino/csrc/ms_deformable_attn_op.cu",
],
)

Expand Down
13 changes: 7 additions & 6 deletions deploy/sam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ python export.py --model_type Sam/SamVitH-1024 --input_type points --save_dir s


#bbox 提示词推理
python predict.py
--input_image image_you_want_to_detect.jpg \
--box_prompt 548 372 593 429 443 374 482 418 \
python predict.py \
--input_image https://bj.bcebos.com/v1/paddlenlp/models/community/GroundingDino/000000004505.jpg \
--box_prompt 112 118 513 382 \
--input_type boxs \
--model_name_or_path Sam/SamVitH-1024 \
--cfg sam_export_SamVitH_boxs/deploy.yaml
--cfg Sam/SamVitH-1024_boxs/deploy.yaml


#points 提示词推理
python predict.py \
--input_image mage_you_want_to_detect.jpg \
--input_image https://bj.bcebos.com/v1/paddlenlp/models/community/GroundingDino/000000004505.jpg \
--points_prompt 548 372 \
--input_type points \
--model_name_or_path Sam/SamVitH-1024 \
--cfg sam_export_SamVitH_points/deploy.yaml
--cfg Sam/SamVitH-1024_points/deploy.yaml
```
2 changes: 1 addition & 1 deletion deploy/sam/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(args):
]
model.eval()
model = paddle.jit.to_static(model, input_spec=input_spec)
save_path = args.save_dir + f"_{args.model_type}_{args.input_type}"
save_path = f"{args.model_type}_{args.input_type}"
paddle.jit.save(model, os.path.join(save_path, "model"))

# TODO add test config
Expand Down
3 changes: 1 addition & 2 deletions deploy/sam/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def main(model_args, data_args):
url = data_args.input_image
# read image
if os.path.isfile(url):
# read image

image_pil = Image.open(data_args.input_image).convert("RGB")
else:
image_pil = Image.open(requests.get(url, stream=True).raw).convert("RGB")
Expand All @@ -318,7 +318,6 @@ def main(model_args, data_args):

predictor = Predictor(model_args)

image_pil = Image.open(data_args.input_image).convert("RGB")
seg_masks = predictor.run(image_pil, {"points": data_args.points_prompt, "boxs": data_args.box_prompt})

if model_args.visual:
Expand Down

0 comments on commit 0715d11

Please sign in to comment.