diff --git a/PaddleCV/deeplabv3+/eval.py b/PaddleCV/deeplabv3+/eval.py index 94d82e70d2e23ab6cd4db6a96821e9d89253d13f..99e49e113bf4126440ee02aa687d18be8d3cfd30 100644 --- a/PaddleCV/deeplabv3+/eval.py +++ b/PaddleCV/deeplabv3+/eval.py @@ -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 diff --git a/PaddleCV/deeplabv3+/train.py b/PaddleCV/deeplabv3+/train.py index 2e3ba9cbf75f22a1ed769f993aab69127ea55a60..c8a1b26be0015e6765349d5d1b0b195c8eb159c7 100755 --- a/PaddleCV/deeplabv3+/train.py +++ b/PaddleCV/deeplabv3+/train.py @@ -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 diff --git a/PaddleCV/deeplabv3+/utility.py b/PaddleCV/deeplabv3+/utility.py index aebb9acbf4f450b50f020d96ccd3b13be5d7afaf..8d9bcfb3b4cde1f0c54aca4c8d0c61ca2e955d7b 100644 --- a/PaddleCV/deeplabv3+/utility.py +++ b/PaddleCV/deeplabv3+/utility.py @@ -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 diff --git a/PaddleCV/icnet/eval.py b/PaddleCV/icnet/eval.py index dc2f574359a568de794b07cf05d854f6d388482a..bae058953ecc1f0f9371bc0673749f7c6a3c6f6a 100644 --- a/PaddleCV/icnet/eval.py +++ b/PaddleCV/icnet/eval.py @@ -1,7 +1,7 @@ """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) diff --git a/PaddleCV/icnet/infer.py b/PaddleCV/icnet/infer.py index 1686adcc45b40b6306fbe8b5d0fc80aa757c74ab..b11452034813a1889e250d84afe2071f372edd2f 100644 --- a/PaddleCV/icnet/infer.py +++ b/PaddleCV/icnet/infer.py @@ -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) diff --git a/PaddleCV/icnet/train.py b/PaddleCV/icnet/train.py index 07efe4c6c065644f50cfa7ce39ccea9a3673cbd4..cdb8e96c1757debf7b78113cf6941f0aebfb65ef 100644 --- a/PaddleCV/icnet/train.py +++ b/PaddleCV/icnet/train.py @@ -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) diff --git a/PaddleCV/icnet/utils.py b/PaddleCV/icnet/utils.py index 18172b33adbe8a8ba2fcf3df1d699167d107e0b7..34e28602dbc1d8149f7ff70638b85f72cf4b8cbc 100644 --- a/PaddleCV/icnet/utils.py +++ b/PaddleCV/icnet/utils.py @@ -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 diff --git a/PaddleCV/rcnn/eval_coco_map.py b/PaddleCV/rcnn/eval_coco_map.py index 6b01da55ade6e9b5dabf370c30208c465028df9f..e4d8bb4ace8601d8d363a27d630cb7f49813a40b 100644 --- a/PaddleCV/rcnn/eval_coco_map.py +++ b/PaddleCV/rcnn/eval_coco_map.py @@ -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() diff --git a/PaddleCV/rcnn/infer.py b/PaddleCV/rcnn/infer.py index 0c66ec08cf63cbf25df0959a5c082838965d7597..b37d6c2ccdb1e3fb69a627517e51cd6b6e51f0d4 100644 --- a/PaddleCV/rcnn/infer.py +++ b/PaddleCV/rcnn/infer.py @@ -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() diff --git a/PaddleCV/rcnn/train.py b/PaddleCV/rcnn/train.py index 49fcb71d235b8b3c64eb4ac70b575d105c5cb6e1..74e86840875c3452798bab85b34b3d841c2f865e 100644 --- a/PaddleCV/rcnn/train.py +++ b/PaddleCV/rcnn/train.py @@ -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() diff --git a/PaddleCV/rcnn/utility.py b/PaddleCV/rcnn/utility.py index fcad5566fd082904c37953b09918f2bf5e0aa273..9df7f78b844e2a83ed3c91b93566d8fa78c5ce4e 100644 --- a/PaddleCV/rcnn/utility.py +++ b/PaddleCV/rcnn/utility.py @@ -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