提交 d46b37bb 编写于 作者: F FDInSky 提交者: SunGaofeng

add check gpu for deeplabe3+, icnet, rcnn (#2738)

* add check gpu for deeplabe3+, icnet, rcnn

* modify based on review

* modify based on review
上级 7fa0e3de
......@@ -55,6 +55,7 @@ def load_model():
CityscapeDataset = reader.CityscapeDataset
args = parser.parse_args()
utility.check_gpu(args.use_gpu)
models.clean()
models.is_train = False
......
......@@ -116,6 +116,7 @@ def loss(logit, label):
args = parser.parse_args()
utility.print_arguments(args)
utility.check_gpu(args.use_gpu)
models.clean()
models.bn_momentum = 0.9997
......
......@@ -17,6 +17,7 @@ from __future__ import division
from __future__ import print_function
import distutils.util
import six
import paddle.fluid as fluid
def print_arguments(args):
......@@ -58,3 +59,22 @@ def add_arguments(argname, type, default, help, argparser, **kwargs):
type=type,
help=help + ' Default: %(default)s.',
**kwargs)
def check_gpu(use_gpu):
"""
Log error and exit when set use_gpu=true in paddlepaddle
cpu version.
"""
err = "Config use_gpu cannot be set as true while you are " \
"using paddlepaddle cpu version ! \nPlease try: \n" \
"\t1. Install paddlepaddle-gpu to run model on GPU \n" \
"\t2. Set use_gpu as false in config file to run " \
"model on CPU"
try:
if use_gpu and not fluid.is_compiled_with_cuda():
logger.error(err)
sys.exit(1)
except Exception as e:
pass
"""Evaluator for ICNet model."""
import paddle.fluid as fluid
import numpy as np
from utils import add_arguments, print_arguments, get_feeder_data
from utils import add_arguments, print_arguments, get_feeder_data, check_gpu
from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter
from paddle.fluid.initializer import init_on_cpu
from icnet import icnet
......@@ -89,6 +89,7 @@ def eval(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
eval(args)
......
......@@ -10,7 +10,7 @@ import cv2
import paddle.fluid as fluid
import paddle
from icnet import icnet
from utils import add_arguments, print_arguments, get_feeder_data
from utils import add_arguments, print_arguments, get_feeder_data, check_gpu
from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter
from paddle.fluid.initializer import init_on_cpu
import numpy as np
......@@ -128,6 +128,7 @@ def infer(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
infer(args)
......
......@@ -11,7 +11,7 @@ import os
import time
import paddle.fluid as fluid
import numpy as np
from utils import add_arguments, print_arguments, get_feeder_data
from utils import add_arguments, print_arguments, get_feeder_data, check_gpu
from paddle.fluid.layers.learning_rate_scheduler import _decay_step_counter
from paddle.fluid.initializer import init_on_cpu
......@@ -148,6 +148,7 @@ def train(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
train(args)
......
......@@ -21,6 +21,7 @@ import numpy as np
import six
import paddle.fluid as fluid
def print_arguments(args):
"""Print argparse's arguments.
......@@ -112,3 +113,22 @@ def get_feeder_data(data, place, for_test=False):
feed_dict["mask"] = mask_t
return feed_dict
def check_gpu(use_gpu):
"""
Log error and exit when set use_gpu=true in paddlepaddle
cpu version.
"""
err = "Config use_gpu cannot be set as true while you are " \
"using paddlepaddle cpu version ! \nPlease try: \n" \
"\t1. Install paddlepaddle-gpu to run model on GPU \n" \
"\t2. Set use_gpu as false in config file to run " \
"model on CPU"
try:
if use_gpu and not fluid.is_compiled_with_cuda():
logger.error(err)
sys.exit(1)
except Exception as e:
pass
......@@ -22,7 +22,7 @@ from eval_helper import *
import paddle
import paddle.fluid as fluid
import reader
from utility import print_arguments, parse_args
from utility import print_arguments, parse_args, check_gpu
import models.model_builder as model_builder
import models.resnet as resnet
import json
......@@ -139,4 +139,5 @@ def eval():
if __name__ == '__main__':
args = parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
eval()
......@@ -5,7 +5,7 @@ from eval_helper import *
import paddle
import paddle.fluid as fluid
import reader
from utility import print_arguments, parse_args
from utility import print_arguments, parse_args, check_gpu
import models.model_builder as model_builder
import models.resnet as resnet
from config import cfg
......@@ -92,4 +92,5 @@ def infer():
if __name__ == '__main__':
args = parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
infer()
......@@ -35,7 +35,7 @@ import sys
import numpy as np
import time
import shutil
from utility import parse_args, print_arguments, SmoothedValue, TrainingStats, now_time
from utility import parse_args, print_arguments, SmoothedValue, TrainingStats, now_time, check_gpu
import collections
import paddle
......@@ -260,4 +260,5 @@ def train():
if __name__ == '__main__':
args = parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
train()
......@@ -29,6 +29,7 @@ from paddle.fluid import core
import argparse
import functools
from config import *
import paddle.fluid as fluid
def print_arguments(args):
......@@ -172,3 +173,22 @@ def parse_args():
else:
merge_cfg_from_args(args, 'val')
return args
def check_gpu(use_gpu):
"""
Log error and exit when set use_gpu=true in paddlepaddle
cpu version.
"""
err = "Config use_gpu cannot be set as true while you are " \
"using paddlepaddle cpu version ! \nPlease try: \n" \
"\t1. Install paddlepaddle-gpu to run model on GPU \n" \
"\t2. Set use_gpu as false in config file to run " \
"model on CPU"
try:
if use_gpu and not fluid.is_compiled_with_cuda():
logger.error(err)
sys.exit(1)
except Exception as e:
pass
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册