Open4

PaddleSeg CityScapesSOTA のエクスポート(jit.save)

PINTOPINTO
  • PaddleSeg Release/v2.3
docker pull pinto0309/paddleseg:latest

docker run --rm -it --gpus all \
-v ${PWD}:/share \
pinto0309/paddleseg:latest /bin/bash

cd /paddleseg/contrib/CityscapesSOTA
  • predict.py
def main(args):
    env_info = get_sys_env()
    place = 'gpu' if env_info['Paddle compiled with cuda'] and env_info[
        'GPUs used'] else 'cpu'

    paddle.set_device(place)
    if not args.cfg:
        raise RuntimeError('No configuration file specified.')

    cfg = Config(args.cfg)
    #val_dataset = cfg.val_dataset
    #if not val_dataset:
    #    raise RuntimeError(
    #        'The verification dataset is not specified in the configuration file.'
    #    )

    msg = '\n---------------Config Information---------------\n'
    msg += str(cfg)
    msg += '------------------------------------------------'
    logger.info(msg)

    model = cfg.model
    para_state_dict = paddle.load(args.model_path)
    model.set_dict(para_state_dict)
    H=args.crop_size[1]
    W=args.crop_size[0]
    shape = [1,3,H,W]
    model.eval()
    model = paddle.jit.to_static(model, input_spec=[paddle.static.InputSpec(shape=shape, dtype='float32')])
    paddle.jit.save(model, f'paddleseg_cityscapessota_{H}x{W}')
    import sys
    sys.exit(0)
python3 predict.py \
--config configs//mscale_ocr_cityscapes_autolabel_mapillary.yml \
--model_path pretrain/pretrained.pdparams \
--crop_size 320 180

python3 predict.py \
--config configs//mscale_ocr_cityscapes_autolabel_mapillary.yml \
--model_path pretrain/pretrained.pdparams \
--crop_size 320 240

python3 predict.py \
--config configs//mscale_ocr_cityscapes_autolabel_mapillary.yml \
--model_path pretrain/pretrained.pdparams \
--crop_size 640 360

python3 predict.py \
--config configs//mscale_ocr_cityscapes_autolabel_mapillary.yml \
--model_path pretrain/pretrained.pdparams \
--crop_size 640 480

python3 predict.py \
--config configs//mscale_ocr_cityscapes_autolabel_mapillary.yml \
--model_path pretrain/pretrained.pdparams \
--crop_size 1280 720

pip3 install paddle2onnx

H=180
W=320
paddle2onnx \
--model_dir . \
--model_filename paddleseg_cityscapessota_${H}x${W}.pdmodel \
--params_filename paddleseg_cityscapessota_${H}x${W}.pdiparams \
--opset_version 11 \
--save_file paddleseg_cityscapessota_${H}x${W}.onnx

H=240
W=320
paddle2onnx \
--model_dir . \
--model_filename paddleseg_cityscapessota_${H}x${W}.pdmodel \
--params_filename paddleseg_cityscapessota_${H}x${W}.pdiparams \
--opset_version 11 \
--save_file paddleseg_cityscapessota_${H}x${W}.onnx

H=360
W=640
paddle2onnx \
--model_dir . \
--model_filename paddleseg_cityscapessota_${H}x${W}.pdmodel \
--params_filename paddleseg_cityscapessota_${H}x${W}.pdiparams \
--opset_version 11 \
--save_file paddleseg_cityscapessota_${H}x${W}.onnx

H=480
W=640
paddle2onnx \
--model_dir . \
--model_filename paddleseg_cityscapessota_${H}x${W}.pdmodel \
--params_filename paddleseg_cityscapessota_${H}x${W}.pdiparams \
--opset_version 11 \
--save_file paddleseg_cityscapessota_${H}x${W}.onnx

H=720
W=1280
paddle2onnx \
--model_dir . \
--model_filename paddleseg_cityscapessota_${H}x${W}.pdmodel \
--params_filename paddleseg_cityscapessota_${H}x${W}.pdiparams \
--opset_version 11 \
--save_file paddleseg_cityscapessota_${H}x${W}.onnx

cp *.onnx /share
exit
PINTOPINTO
sudo chown $USER *.onnx
python3 -m onnxsim paddleseg_cityscapessota_180x320.onnx paddleseg_cityscapessota_180x320.onnx
python3 -m onnxsim paddleseg_cityscapessota_240x320.onnx paddleseg_cityscapessota_240x320.onnx
python3 -m onnxsim paddleseg_cityscapessota_360x640.onnx paddleseg_cityscapessota_360x640.onnx
python3 -m onnxsim paddleseg_cityscapessota_480x640.onnx paddleseg_cityscapessota_480x640.onnx
python3 -m onnxsim paddleseg_cityscapessota_720x1280.onnx paddleseg_cityscapessota_720x1280.onnx
PINTOPINTO
  • Dockerfile
# for available args, see:
# https://hub.docker.com/r/paddlepaddle/paddle/tags
ARG PADDLEPADDLE="2.2.1-gpu"
ARG CUDA="11.2"
ARG CUDNN="8"
FROM paddlepaddle/paddle:${PADDLEPADDLE}-cuda${CUDA}-cudnn${CUDNN}

# install paddleseg:
# https://github.com/PaddlePaddle/PaddleSeg#installation
ARG PADDLESEG="2.3.0"
RUN pip3 install paddleseg==${PADDLESEG} -vv

# clone paddleseg source
ARG PADDLESEG_BRANCH="release/2.3"
RUN git clone -b ${PADDLESEG_BRANCH} https://github.com/PaddlePaddle/PaddleSeg /paddleseg

# alias to use python3.8 as default python
RUN echo 'alias python="python3"' >> /root/.bashrc && \
    echo 'alias pip="pip3"' >> /root/.bashrc

WORKDIR /paddleseg