Skip to content

Commit

Permalink
gpu check
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Oct 11, 2023
1 parent 1a8bf28 commit 4fcc1e3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
5 changes: 1 addition & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
from utilsAPI import getAPIURL, getWorkerType
from utilsAuth import getToken
from utils import getDataDirectory, checkTime, checkResourceUsage, checkCuda
from utils import getDataDirectory, checkTime, checkResourceUsage

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -57,9 +57,6 @@
# Check resource usage
resourceUsage = checkResourceUsage(stop_machine_and_email=True)
logging.info(json.dumps(resourceUsage))
# TODO: not yet functional.
# Check GPU device is available
# checkCuda()
logging.info(r.text)

trial = r.json()
Expand Down
10 changes: 10 additions & 0 deletions mmpose/loop_mmpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
import logging
import shutil
import json
import torch

from utilsMMpose import detection_inference, pose_inference

logging.basicConfig(level=logging.INFO)

logging.info("Waiting for data...")

def checkCudaPyTorch():
if torch.cuda.is_available():
num_gpus = torch.cuda.device_count()
logging.info(f"Found {num_gpus} GPU(s).")
else:
logging.info("No GPU detected. Exiting.")
raise Exception("No GPU detected. Exiting.")

video_path = "/mmpose/data/video_mmpose.mov"
output_dir = "/mmpose/data/output_mmpose"

Expand Down Expand Up @@ -38,6 +47,7 @@
os.makedirs(output_dir)

try:
checkCudaPyTorch()
# Run human detection.
pathModelCkptPerson = model_ckpt_person
bboxPath = os.path.join(output_dir, 'box.pkl')
Expand Down
19 changes: 17 additions & 2 deletions openpose/loop_openpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
import shutil
import ffmpeg
import json
import subprocess

#%%
logging.basicConfig(level=logging.INFO)

#%%
def check_cuda_device():
try:
# Run the nvidia-smi command and capture the output
_ = subprocess.check_output(["nvidia-smi"])
# If the command ran successfully, assume a CUDA device is present
logging.info("A CUDA-capable device is detected.")
except subprocess.CalledProcessError as e:
# If the command fails, it means no CUDA device is detected
logging.info("No CUDA-capable device is detected. Error:", e)
raise Exception("No CUDA-capable device is detected.")

#%%
def getVideoOrientation(videoPath):

meta = ffmpeg.probe(videoPath)
Expand Down Expand Up @@ -58,7 +73,6 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):
return cmd_hr

#%%
logging.basicConfig(level=logging.INFO)

logging.info("Waiting for data...")

Expand Down Expand Up @@ -87,6 +101,7 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):
horizontal = getVideoOrientation(video_path)
cmd_hr = getResolutionCommand(resolutionPoseDetection, horizontal)

check_cuda_device()
command = "/openpose/build/examples/openpose/openpose.bin\
--video {video_path}\
--display 0\
Expand Down
10 changes: 4 additions & 6 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,16 +1480,14 @@ def checkResourceUsage(stop_machine_and_email=True):

return resourceUsage

def checkCuda():
def checkCudaTF():
import tensorflow as tf

if tf.config.experimental.list_physical_devices('GPU'):
# Get the list of available GPUs
gpus = tf.config.experimental.list_physical_devices('GPU')
if tf.config.list_physical_devices('GPU'):
gpus = tf.config.list_physical_devices('GPU')
print(f"Found {len(gpus)} GPU(s).")
# You can also print GPU device names and memory limits if needed
for gpu in gpus:
print(f"GPU: {gpu.name}, Memory: {gpu.memory_limit}")
print(f"GPU: {gpu.name}")
else:
message = "Cuda check failed on an OpenCap machine backend machine: " \
+ socket.gethostname() + ". It has been stopped."
Expand Down
1 change: 1 addition & 0 deletions utilsServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def runTestSession(pose='all',isDocker=True):
# trials['failure'] = '698162c8-3980-46e5-a3c5-8d4f081db4c4' # failed trial for testing
else: # dev trials
trials['openpose'] = '89d77579-8371-4760-a019-95f2c793622c' # session acd0e19c-6c86-4ba4-95fd-94b97229a926
trials['hrnet'] = 'e0e02393-42ee-46d4-9ae1-a6fbb0b89c42' # session 3510c726-a1b8-4de4-a4a2-52b021b4aab2

if pose == 'all':
trialList = list(trials.values())
Expand Down

0 comments on commit 4fcc1e3

Please sign in to comment.