Skip to content

Commit

Permalink
mv get_gpu_id func to utility
Browse files Browse the repository at this point in the history
  • Loading branch information
LDOUBLEV committed Aug 17, 2021
1 parent 96a3f90 commit d83b1de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 1 addition & 14 deletions tools/infer/predict_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, args):
if args.benchmark:
import auto_log
pid = os.getpid()
gpu_id = self.get_infer_gpuid()
gpu_id = utility.get_infer_gpuid()
self.autolog = auto_log.AutoLogger(
model_name="det",
model_precision=args.precision,
Expand All @@ -118,19 +118,6 @@ def __init__(self, args):
warmup=2,
logger=logger)

def get_infer_gpuid(self):
cmd = "nvidia-smi"
res = os.popen(cmd).readlines()
if len(res) == 0:
return None
cmd = "env | grep CUDA_VISIBLE_DEVICES"
env_cuda = os.popen(cmd).readlines()
if len(env_cuda) == 0:
return 0
else:
gpu_id = env_cuda[0].strip().split("=")[1]
return int(gpu_id[0])

def order_points_clockwise(self, pts):
"""
reference from: https://github.com/jrosebr1/imutils/blob/master/imutils/perspective.py
Expand Down
14 changes: 14 additions & 0 deletions tools/infer/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ def create_predictor(args, mode, logger):
return predictor, input_tensor, output_tensors, config


def get_infer_gpuid():
cmd = "nvidia-smi"
res = os.popen(cmd).readlines()
if len(res) == 0:
return None
cmd = "env | grep CUDA_VISIBLE_DEVICES"
env_cuda = os.popen(cmd).readlines()
if len(env_cuda) == 0:
return 0
else:
gpu_id = env_cuda[0].strip().split("=")[1]
return int(gpu_id[0])


def draw_e2e_res(dt_boxes, strs, img_path):
src_im = cv2.imread(img_path)
for box, str in zip(dt_boxes, strs):
Expand Down

0 comments on commit d83b1de

Please sign in to comment.