未验证 提交 6f981127 编写于 作者: R ruri 提交者: GitHub

check gpu (#2743)

上级 5d5a28d2
......@@ -29,7 +29,7 @@ import paddle.fluid as fluid
import reader_cv2 as reader
import models
from utils.learning_rate import cosine_decay
from utils.utility import add_arguments, print_arguments
from utils.utility import add_arguments, print_arguments, check_gpu
parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser)
......@@ -134,6 +134,7 @@ def eval(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
eval(args)
......
......@@ -29,7 +29,7 @@ import paddle.fluid as fluid
import reader_cv2 as reader
import models
import utils
from utils.utility import add_arguments,print_arguments
from utils.utility import add_arguments,print_arguments, check_gpu
parser = argparse.ArgumentParser(description=__doc__)
# yapf: disable
......@@ -108,6 +108,7 @@ def infer(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
infer(args)
......
......@@ -47,7 +47,7 @@ import reader_cv2 as reader
import utils
import models
from utils.fp16_utils import create_master_params_grads, master_param_to_train_param
from utils.utility import add_arguments, print_arguments
from utils.utility import add_arguments, print_arguments, check_gpu
from utils.learning_rate import cosine_decay_with_warmup
from dist_train import dist_utils
......@@ -612,6 +612,7 @@ def train(args):
def main():
args = parser.parse_args()
print_arguments(args)
check_gpu(args.use_gpu)
train(args)
......
......@@ -60,3 +60,21 @@ 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册