提交 238ed4fb 编写于 作者: L LielinJiang 提交者: qingqing01

Add model check function (#2729)

上级 5987726d
...@@ -13,7 +13,7 @@ import paddle ...@@ -13,7 +13,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from pyramidbox import PyramidBox from pyramidbox import PyramidBox
import reader import reader
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -247,6 +247,7 @@ def get_cards(args): ...@@ -247,6 +247,7 @@ def get_cards(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
data_dir = os.path.join(args.data_dir, 'WIDER_train/images/') data_dir = os.path.join(args.data_dir, 'WIDER_train/images/')
train_file_list = os.path.join(args.data_dir, train_file_list = os.path.join(args.data_dir,
......
...@@ -17,7 +17,8 @@ from __future__ import division ...@@ -17,7 +17,8 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import distutils.util import distutils.util
import six import six
import sys
import paddle.fluid as fluid
def print_arguments(args): def print_arguments(args):
"""Print argparse's arguments. """Print argparse's arguments.
...@@ -58,3 +59,14 @@ def add_arguments(argname, type, default, help, argparser, **kwargs): ...@@ -58,3 +59,14 @@ def add_arguments(argname, type, default, help, argparser, **kwargs):
type=type, type=type,
help=help + ' Default: %(default)s.', help=help + ' Default: %(default)s.',
**kwargs) **kwargs)
def check_cuda(use_cuda, err = \
"\nYou can not set use_cuda = True in the model because you are using paddlepaddle-cpu.\n \
Please: 1. Install paddlepaddle-gpu to run your models on GPU or 2. Set use_cuda = False to run models on CPU.\n"
):
try:
if use_cuda == True and fluid.is_compiled_with_cuda() == False:
print(err)
sys.exit(1)
except Exception as e:
pass
\ No newline at end of file
...@@ -133,4 +133,5 @@ def test(args): ...@@ -133,4 +133,5 @@ def test(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
check_cuda(args.use_gpu)
test(args) test(args)
...@@ -175,5 +175,6 @@ def train(args): ...@@ -175,5 +175,6 @@ def train(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
check_cuda(args.use_gpu)
train(args) train(args)
...@@ -23,7 +23,8 @@ import distutils.util ...@@ -23,7 +23,8 @@ import distutils.util
import numpy as np import numpy as np
import cv2 import cv2
from pathlib import Path from pathlib import Path
import sys
import paddle.fluid as fluid
def print_arguments(args): def print_arguments(args):
"""Print argparse's arguments. """Print argparse's arguments.
...@@ -395,3 +396,14 @@ class AverageMeter(object): ...@@ -395,3 +396,14 @@ class AverageMeter(object):
self.sum += val * n self.sum += val * n
self.count += n self.count += n
self.avg = self.sum / self.count if self.count != 0 else 0 self.avg = self.sum / self.count if self.count != 0 else 0
def check_cuda(use_cuda, err = \
"\nYou can not set use_cuda = True in the model because you are using paddlepaddle-cpu.\n \
Please: 1. Install paddlepaddle-gpu to run your models on GPU or 2. Set use_cuda = False to run models on CPU.\n"
):
try:
if use_cuda == True and fluid.is_compiled_with_cuda() == False:
print(err)
sys.exit(1)
except Exception as e:
pass
...@@ -230,4 +230,5 @@ def valid(args): ...@@ -230,4 +230,5 @@ def valid(args):
if __name__ == '__main__': if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
check_cuda(args.use_gpu)
valid(args) valid(args)
...@@ -13,7 +13,7 @@ import paddle ...@@ -13,7 +13,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import models import models
import reader import reader
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
from utility import fmt_time, recall_topk from utility import fmt_time, recall_topk
# yapf: disable # yapf: disable
...@@ -93,6 +93,7 @@ def eval(args): ...@@ -93,6 +93,7 @@ def eval(args):
def main(): def main():
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
eval(args) eval(args)
......
...@@ -13,7 +13,7 @@ import paddle ...@@ -13,7 +13,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import models import models
import reader import reader
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -77,6 +77,7 @@ def infer(args): ...@@ -77,6 +77,7 @@ def infer(args):
def main(): def main():
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
infer(args) infer(args)
......
...@@ -19,7 +19,7 @@ import reader ...@@ -19,7 +19,7 @@ import reader
from losses import SoftmaxLoss from losses import SoftmaxLoss
from losses import ArcMarginLoss from losses import ArcMarginLoss
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments
from utility import fmt_time, recall_topk, get_gpu_num from utility import fmt_time, recall_topk, get_gpu_num, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -283,6 +283,7 @@ def initlogging(): ...@@ -283,6 +283,7 @@ def initlogging():
def main(): def main():
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
train_async(args) train_async(args)
......
...@@ -21,7 +21,7 @@ from losses import QuadrupletLoss ...@@ -21,7 +21,7 @@ from losses import QuadrupletLoss
from losses import EmlLoss from losses import EmlLoss
from losses import NpairsLoss from losses import NpairsLoss
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments
from utility import fmt_time, recall_topk, get_gpu_num from utility import fmt_time, recall_topk, get_gpu_num, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -275,6 +275,7 @@ def initlogging(): ...@@ -275,6 +275,7 @@ def initlogging():
def main(): def main():
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
train_async(args) train_async(args)
......
...@@ -23,7 +23,8 @@ import time ...@@ -23,7 +23,8 @@ import time
import subprocess import subprocess
import distutils.util import distutils.util
import numpy as np import numpy as np
import sys
import paddle.fluid as fluid
from paddle.fluid import core from paddle.fluid import core
...@@ -101,3 +102,14 @@ def get_gpu_num(): ...@@ -101,3 +102,14 @@ def get_gpu_num():
[str.encode('nvidia-smi'), str.encode('-L')]).decode('utf-8').count('\n') [str.encode('nvidia-smi'), str.encode('-L')]).decode('utf-8').count('\n')
return devicenum return devicenum
def check_cuda(use_cuda, err = \
"\nYou can not set use_cuda = True in the model because you are using paddlepaddle-cpu.\n \
Please: 1. Install paddlepaddle-gpu to run your models on GPU or 2. Set use_cuda = False to run models on CPU.\n"
):
try:
if use_cuda == True and fluid.is_compiled_with_cuda() == False:
print(err)
sys.exit(1)
except Exception as e:
pass
...@@ -9,7 +9,7 @@ import paddle ...@@ -9,7 +9,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import reader import reader
from mobilenet_ssd import build_mobilenet_ssd from mobilenet_ssd import build_mobilenet_ssd
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -105,6 +105,8 @@ if __name__ == '__main__': ...@@ -105,6 +105,8 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
data_dir = 'data/pascalvoc' data_dir = 'data/pascalvoc'
test_list = 'test.txt' test_list = 'test.txt'
label_file = 'label_list' label_file = 'label_list'
......
...@@ -11,7 +11,7 @@ import paddle ...@@ -11,7 +11,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import reader import reader
from mobilenet_ssd import build_mobilenet_ssd from mobilenet_ssd import build_mobilenet_ssd
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -117,6 +117,8 @@ if __name__ == '__main__': ...@@ -117,6 +117,8 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
data_dir = 'data/pascalvoc' data_dir = 'data/pascalvoc'
label_file = 'label_list' label_file = 'label_list'
......
...@@ -11,7 +11,7 @@ import paddle ...@@ -11,7 +11,7 @@ import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
import reader import reader
from mobilenet_ssd import build_mobilenet_ssd from mobilenet_ssd import build_mobilenet_ssd
from utility import add_arguments, print_arguments from utility import add_arguments, print_arguments, check_cuda
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
add_arg = functools.partial(add_arguments, argparser=parser) add_arg = functools.partial(add_arguments, argparser=parser)
...@@ -288,6 +288,8 @@ def main(): ...@@ -288,6 +288,8 @@ def main():
args = parser.parse_args() args = parser.parse_args()
print_arguments(args) print_arguments(args)
check_cuda(args.use_gpu)
data_dir = args.data_dir data_dir = args.data_dir
dataset = args.dataset dataset = args.dataset
assert dataset in ['pascalvoc', 'coco2014', 'coco2017'] assert dataset in ['pascalvoc', 'coco2014', 'coco2017']
......
...@@ -18,9 +18,9 @@ from __future__ import division ...@@ -18,9 +18,9 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import distutils.util import distutils.util
import numpy as np import sys
import six import six
from paddle.fluid import core import paddle.fluid as fluid
def print_arguments(args): def print_arguments(args):
...@@ -62,3 +62,14 @@ def add_arguments(argname, type, default, help, argparser, **kwargs): ...@@ -62,3 +62,14 @@ def add_arguments(argname, type, default, help, argparser, **kwargs):
type=type, type=type,
help=help + ' Default: %(default)s.', help=help + ' Default: %(default)s.',
**kwargs) **kwargs)
def check_cuda(use_cuda, err = \
"\nYou can not set use_cuda = True in the model because you are using paddlepaddle-cpu.\n \
Please: 1. Install paddlepaddle-gpu to run your models on GPU or 2. Set use_cuda = False to run models on CPU.\n"
):
try:
if use_cuda == True and fluid.is_compiled_with_cuda() == False:
print(err)
sys.exit(1)
except Exception as e:
pass
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册