mirror of https://github.com/JDAI-CV/fast-reid.git
fix model deploy problems
parent
ff8a958fff
commit
dbf1604231
|
@ -2,9 +2,18 @@
|
|||
|
||||
We provide a command line tool to run a simple demo of builtin models.
|
||||
|
||||
You can run this command to get cosine similarites between different images
|
||||
You can run this command to get rank visualization results by cosine similarites between different images.
|
||||
|
||||
```bash
|
||||
cd demo/
|
||||
sh run_demo.sh
|
||||
```shell script
|
||||
python3 demo/visualize_result.py --config-file logs/dukemtmc/mgn_R50-ibn/config.yaml \
|
||||
--parallel --vis-label --dataset-name 'DukeMTMC' --output logs/mgn_duke_vis \
|
||||
--opts MODEL.WEIGHTS logs/dukemtmc/mgn_R50-ibn/model_final.pth
|
||||
```
|
||||
|
||||
You can also run this command to extract image features.
|
||||
|
||||
```shell script
|
||||
python3 demo/demo.py --config-file logs/dukemtmc/sbs_R50/config.yaml \
|
||||
--parallel --input tools/deploy/test_data/*.jpg --output sbs_R50_feat \
|
||||
--opts MODEL.WEIGHTS logs/dukemtmc/sbs_R50/model_final.pth
|
||||
```
|
|
@ -14,7 +14,7 @@ import numpy as np
|
|||
import tqdm
|
||||
from torch.backends import cudnn
|
||||
|
||||
sys.path.append('..')
|
||||
sys.path.append('.')
|
||||
|
||||
from fastreid.config import get_cfg
|
||||
from fastreid.utils.logger import setup_logger
|
||||
|
@ -86,4 +86,4 @@ if __name__ == '__main__':
|
|||
img = cv2.imread(path)
|
||||
feat = demo.run_on_image(img)
|
||||
feat = feat.numpy()
|
||||
np.save(os.path.join(args.output, os.path.basename(path) + '.npy'), feat)
|
||||
np.save(os.path.join(args.output, os.path.basename(path).split('.')[0] + '.npy'), feat)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
python demo/visualize_result.py --config-file logs/dukemtmc/mgn_R50-ibn/config.yaml \
|
||||
--parallel --vis-label --dataset-name 'DukeMTMC' --output logs/mgn_duke_vis \
|
||||
--opts MODEL.WEIGHTS logs/dukemtmc/mgn_R50-ibn/model_final.pth
|
|
@ -18,14 +18,16 @@ This is a tiny example for converting fastreid-baseline in `meta_arch` to Caffe
|
|||
1. Run `caffe_export.py` to get the converted Caffe model,
|
||||
|
||||
```bash
|
||||
python caffe_export.py --config-file root-path/market1501/bagtricks_R50/config.yml --name baseline_R50 --output outputs/caffe_model --opts MODEL.WEIGHTS root-path/logs/market1501/bagtricks_R50/model_final.pth
|
||||
python tools/deploy/caffe_export.py --config-file configs/market1501/bagtricks_R50/config.yml --name baseline_R50 --output caffe_R50_model --opts MODEL.WEIGHTS logs/market1501/bagtricks_R50/model_final.pth
|
||||
```
|
||||
|
||||
then you can check the Caffe model and prototxt in `outputs/caffe_model`.
|
||||
then you can check the Caffe model and prototxt in `./caffe_R50_model`.
|
||||
|
||||
2. Change `prototxt` following next two steps:
|
||||
2. Change `prototxt` following next three steps:
|
||||
|
||||
1) Modify `avg_pooling` in `baseline_R50.prototxt`
|
||||
1) Modify `MaxPooling` in `baseline_R50.prototxt` and delete `ceil_mode: false`.
|
||||
|
||||
2) Add `avg_pooling` in `baseline_R50.prototxt`
|
||||
|
||||
```prototxt
|
||||
layer {
|
||||
|
|
|
@ -10,7 +10,7 @@ import sys
|
|||
|
||||
import torch
|
||||
|
||||
sys.path.append('../../')
|
||||
sys.path.append('.')
|
||||
|
||||
import pytorch_to_caffe
|
||||
from fastreid.config import get_cfg
|
||||
|
@ -20,8 +20,8 @@ from fastreid.utils.checkpoint import Checkpointer
|
|||
from fastreid.utils.logger import setup_logger
|
||||
|
||||
# import some modules added in project like this below
|
||||
# sys.path.append('../projects/FastCls')
|
||||
# from fastcls import *
|
||||
# sys.path.append("projects/PartialReID")
|
||||
# from partialreid import *
|
||||
|
||||
setup_logger(name='fastreid')
|
||||
logger = logging.getLogger("fastreid.caffe_export")
|
||||
|
@ -29,7 +29,6 @@ logger = logging.getLogger("fastreid.caffe_export")
|
|||
|
||||
def setup_cfg(args):
|
||||
cfg = get_cfg()
|
||||
# add_cls_config(cfg)
|
||||
cfg.merge_from_file(args.config_file)
|
||||
cfg.merge_from_list(args.opts)
|
||||
cfg.freeze()
|
||||
|
@ -69,8 +68,7 @@ if __name__ == '__main__':
|
|||
|
||||
cfg.defrost()
|
||||
cfg.MODEL.BACKBONE.PRETRAIN = False
|
||||
if cfg.MODEL.HEADS.POOL_LAYER == 'FastGlobalAvgPool':
|
||||
cfg.MODEL.HEADS.POOL_LAYER = 'GlobalAvgPool'
|
||||
cfg.MODEL.HEADS.POOL_LAYER = "Identity"
|
||||
cfg.MODEL.BACKBONE.WITH_NL = False
|
||||
|
||||
model = build_model(cfg)
|
||||
|
|
|
@ -91,5 +91,5 @@ if __name__ == "__main__":
|
|||
net.blobs["blob1"].data[...] = image
|
||||
feat = net.forward()["output"]
|
||||
feat = normalize(feat[..., 0, 0], axis=1)
|
||||
np.save(os.path.join(args.output, path.replace('.jpg', '.npy').split('/')[-1]), feat)
|
||||
np.save(os.path.join(args.output, os.path.basename(path).split('.')[0] + '.npy'), feat)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
@contact: sherlockliao01@gmail.com
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import argparse
|
||||
import io
|
||||
|
@ -15,7 +16,7 @@ import torch
|
|||
from onnxsim import simplify
|
||||
from torch.onnx import OperatorExportTypes
|
||||
|
||||
sys.path.append('../../')
|
||||
sys.path.append('.')
|
||||
|
||||
from fastreid.config import get_cfg
|
||||
from fastreid.modeling.meta_arch import build_model
|
||||
|
@ -24,10 +25,12 @@ from fastreid.utils.checkpoint import Checkpointer
|
|||
from fastreid.utils.logger import setup_logger
|
||||
|
||||
# import some modules added in project like this below
|
||||
# sys.path.append('../../projects/FastDistill')
|
||||
# sys.path.append("projects/FastDistill")
|
||||
# from fastdistill import *
|
||||
|
||||
logger = setup_logger(name='onnx_export')
|
||||
|
||||
setup_logger(name="fastreid")
|
||||
logger = logging.getLogger("fastreid.onnx_export")
|
||||
|
||||
|
||||
def setup_cfg(args):
|
||||
|
@ -149,7 +152,7 @@ if __name__ == '__main__':
|
|||
model.eval()
|
||||
logger.info(model)
|
||||
|
||||
inputs = torch.randn(args.batch_size, 3, cfg.INPUT.SIZE_TEST[0], cfg.INPUT.SIZE_TEST[1])
|
||||
inputs = torch.randn(args.batch_size, 3, cfg.INPUT.SIZE_TEST[0], cfg.INPUT.SIZE_TEST[1]).to(model.device)
|
||||
onnx_model = export_onnx_model(model, inputs)
|
||||
|
||||
model_simp, check = simplify(onnx_model)
|
||||
|
|
|
@ -12,12 +12,11 @@ import tensorrt as trt
|
|||
|
||||
from trt_calibrator import FeatEntropyCalibrator
|
||||
|
||||
sys.path.append('../../')
|
||||
sys.path.append('.')
|
||||
|
||||
from fastreid.utils.logger import setup_logger
|
||||
from fastreid.utils.file_io import PathManager
|
||||
from fastreid.utils.logger import setup_logger, PathManager
|
||||
|
||||
logger = setup_logger(name='trt_export')
|
||||
logger = setup_logger(name="trt_export")
|
||||
|
||||
|
||||
def get_parser():
|
||||
|
|
|
@ -197,4 +197,4 @@ if __name__ == "__main__":
|
|||
# the model expects RGB inputs
|
||||
cvt_img = img[:, :, ::-1]
|
||||
feat = trt.inference_on_images([cvt_img])
|
||||
np.save(os.path.join(args.output, os.path.basename(img_path) + '.npy'), feat[0])
|
||||
np.save(os.path.join(args.output, os.path.basename(img_path).split('.')[0] + '.npy'), feat)
|
||||
|
|
Loading…
Reference in New Issue