local_test_cityscapes.py 3.0 KB
Newer Older
W
wuyefeilin 已提交
1 2
# coding: utf8
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve.
W
wuzewu 已提交
3
#
W
wuyefeilin 已提交
4
# Licensed under the Apache License, Version 2.0 (the "License");
W
wuzewu 已提交
5 6 7
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
W
wuyefeilin 已提交
8
#    http://www.apache.org/licenses/LICENSE-2.0
W
wuzewu 已提交
9 10 11 12 13 14 15 16 17
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from test_utils import download_file_and_uncompress, train, eval, vis, export_model
import os
C
chenguowei01 已提交
18
import argparse
W
wuzewu 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

LOCAL_PATH = os.path.dirname(os.path.abspath(__file__))
DATASET_PATH = os.path.join(LOCAL_PATH, "..", "dataset")
MODEL_PATH = os.path.join(LOCAL_PATH, "models")


def download_cityscapes_dataset(savepath, extrapath):
    url = "https://paddleseg.bj.bcebos.com/dataset/cityscapes.tar"
    download_file_and_uncompress(
        url=url, savepath=savepath, extrapath=extrapath)


def download_deeplabv3p_xception65_cityscapes_model(savepath, extrapath):
    url = "https://paddleseg.bj.bcebos.com/models/deeplabv3p_xception65_cityscapes.tgz"
    download_file_and_uncompress(
        url=url, savepath=savepath, extrapath=extrapath)


if __name__ == "__main__":
    download_cityscapes_dataset(".", DATASET_PATH)
    download_deeplabv3p_xception65_cityscapes_model(".", MODEL_PATH)

    model_name = "deeplabv3p_xception65_cityscapes"
    test_model = os.path.join(LOCAL_PATH, "models", model_name)
    cfg = os.path.join(LOCAL_PATH, "configs", "{}.yaml".format(model_name))
    freeze_save_dir = os.path.join(LOCAL_PATH, "inference_model", model_name)
    vis_dir = os.path.join(LOCAL_PATH, "visual", model_name)
    saved_model = os.path.join(LOCAL_PATH, "saved_model", model_name)

C
chenguowei01 已提交
48
    parser = argparse.ArgumentParser(description="PaddleSeg loacl test")
W
wuzewu 已提交
49 50
    parser.add_argument(
        "--devices",
C
chenguowei01 已提交
51 52 53
        dest="devices",
        help="GPU id of running. if more than one, use spacing to separate.",
        nargs="+",
L
LutaoChu 已提交
54
        default=[0],
C
chenguowei01 已提交
55 56 57 58
        type=int)
    args = parser.parse_args()

    devices = [str(x) for x in args.devices]
W
wuzewu 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

    export_model(
        flags=["--cfg", cfg],
        options=[
            "TEST.TEST_MODEL", test_model, "FREEZE.SAVE_DIR", freeze_save_dir
        ],
        devices=devices)

    # Final eval results should be #image=500 acc=0.9615 IoU=0.7804
    eval(
        flags=["--cfg", cfg, "--use_gpu"],
        options=["TEST.TEST_MODEL", test_model],
        devices=devices)

    vis(flags=["--cfg", cfg, "--use_gpu", "--local_test", "--vis_dir", vis_dir],
        options=["TEST.TEST_MODEL", test_model],
        devices=devices)

    train(
        flags=["--cfg", cfg, "--use_gpu", "--log_steps", "10"],
        options=[
W
wuzewu 已提交
80
            "SOLVER.NUM_EPOCHS", "1", "TRAIN.PRETRAINED_MODEL_DIR", test_model,
W
wuzewu 已提交
81 82 83
            "TRAIN.MODEL_SAVE_DIR", saved_model
        ],
        devices=devices)