Skip to content

Commit

Permalink
makefile for deployment to ECR
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Jun 18, 2024
1 parent 04f8079 commit d4384e9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 211 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Workflows

The actions only push the opencap (-dev) image to ECR, not the openpose (-dev) and mmpose (-dev) images.
The mmpose (-dev) image is too big and the action fail. To push them to ECR, do it manually through the makefile by running make build and then make run.
70 changes: 0 additions & 70 deletions .github/workflows/ecr-mmpose-dev.yml

This file was deleted.

70 changes: 0 additions & 70 deletions .github/workflows/ecr-openpose-dev.yml

This file was deleted.

33 changes: 27 additions & 6 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
BASE_NAME := 660440363484.dkr.ecr.us-west-2.amazonaws.com
REPO_NAME := opencap
PROD_BRANCH := main

# Determine the branch name
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

# Determine image tag based on branch
ifeq ($(CURRENT_BRANCH),$(PROD_BRANCH))
OPENCAP_IMAGE_TAG := opencap
OPENPOSE_IMAGE_TAG := openpose
MMPOSE_IMAGE_TAG := mmpose
else
OPENCAP_IMAGE_TAG := opencap-dev
OPENPOSE_IMAGE_TAG := openpose-dev
MMPOSE_IMAGE_TAG := mmpose-dev
endif


.PHONY: build
build:
wget -c -O ../mmpose/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth https://mc-opencap-public.s3.us-west-2.amazonaws.com/mmpose_pth/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
wget -c -O ../mmpose/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth https://mc-opencap-public.s3.us-west-2.amazonaws.com/mmpose_pth/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth
docker build -t 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/opencap .. -f Dockerfile
docker build -t 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/openpose .. -f openpose/Dockerfile
docker build -t 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/mmpose .. -f mmpose/Dockerfile

docker build -t $(BASE_NAME)/$(REPO_NAME)/$(OPENCAP_IMAGE_TAG) .. -f Dockerfile
docker build -t $(BASE_NAME)/$(REPO_NAME)/$(OPENPOSE_IMAGE_TAG) .. -f openpose/Dockerfile
docker build -t $(BASE_NAME)/$(REPO_NAME)/$(MMPOSE_IMAGE_TAG) .. -f mmpose/Dockerfile

.PHONY: push
push:
aws ecr get-login-password --region us-west-2 --profile opencap | docker login --username AWS --password-stdin 660440363484.dkr.ecr.us-west-2.amazonaws.com
docker push 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/opencap
docker push 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/openpose
docker push 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap/mmpose

docker push $(BASE_NAME)/$(REPO_NAME)/$(OPENCAP_IMAGE_TAG)
docker push $(BASE_NAME)/$(REPO_NAME)/$(OPENPOSE_IMAGE_TAG)
docker push $(BASE_NAME)/$(REPO_NAME)/$(MMPOSE_IMAGE_TAG)

.PHONY: run
run:
Expand Down
40 changes: 11 additions & 29 deletions mmpose/loop_mmpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,33 @@

logging.basicConfig(level=logging.INFO)

logging.info("Waiting TEST for data...")
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.")
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"

generateVideo=False

logging.info("Before open")
with open('/mmpose/defaultOpenCapSettings.json') as f:
defaultOpenCapSettings = json.load(f)
bbox_thr = defaultOpenCapSettings['hrnet']
model_config_person='/mmpose/faster_rcnn_r50_fpn_coco.py'
model_ckpt_person='/mmpose/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
model_config_pose='/mmpose/hrnet_w48_coco_wholebody_384x288_dark_plus.py'
model_ckpt_pose='/mmpose/hrnet_w48_coco_wholebody_384x288_dark-f5726563_20200918.pth'

logging.info("isfile")

if os.path.isfile(video_path):
os.remove(video_path)

# checkCudaPyTorch()
logging.info("Before cuda check")
if torch.cuda.is_available():
logging.info("cuda check: if")
num_gpus = torch.cuda.device_count()
logging.info(f"Found {num_gpus} GPU(s).")
else:
logging.info("cuda check: else")
logging.info("No GPU detected. Exiting.")
raise Exception("No GPU detected. Exiting.")
logging.info("After cuda check")
checkCudaPyTorch()
while True:
if not os.path.isfile(video_path):
time.sleep(0.1)
Expand All @@ -60,13 +48,7 @@
os.makedirs(output_dir)

try:
# 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.")
checkCudaPyTorch()
# Run human detection.
pathModelCkptPerson = model_ckpt_person
bboxPath = os.path.join(output_dir, 'box.pkl')
Expand Down
49 changes: 13 additions & 36 deletions openpose/loop_openpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
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: %s", e)
# raise Exception("No CUDA-capable device is detected.")
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):
Expand Down Expand Up @@ -74,21 +74,7 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):

#%%

logging.info("Waiting TEST for data...")
# check_cuda_device()
logging.info("Before cuda check")
try:
logging.info("cuda check: 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:
logging.info("cuda check: except")
# If the command fails, it means no CUDA device is detected
logging.info("No CUDA-capable device is detected. Error: %s", e)
raise Exception("No CUDA-capable device is detected.")
logging.info("After cuda check")
logging.info("Waiting for data...")

video_path = "/openpose/data/video_openpose.mov"
output_dir = "/openpose/data/output_openpose"
Expand All @@ -106,7 +92,7 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):
time.sleep(0.1)
continue

logging.info("Processing openpose ...")
logging.info("Processing...")

if os.path.isdir(output_dir):
shutil.rmtree(output_dir)
Expand All @@ -115,16 +101,7 @@ def getResolutionCommand(resolutionPoseDetection, horizontal):
horizontal = getVideoOrientation(video_path)
cmd_hr = getResolutionCommand(resolutionPoseDetection, horizontal)

# 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.")
check_cuda_device()
command = "/openpose/build/examples/openpose/openpose.bin\
--video {video_path}\
--display 0\
Expand Down

0 comments on commit d4384e9

Please sign in to comment.