Skip to content

added support for running demos on CPU when no CUDA devices are found #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

images/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# PyTorch weights
*.tar
*.pth
*.gz
Untitled.ipynb
Testing notebook.ipynb
5 changes: 3 additions & 2 deletions image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

def main():
model = posenet.load_model(args.model)
model = model.cuda()
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device=device)
output_stride = model.output_stride

if args.output_dir:
Expand All @@ -34,7 +35,7 @@ def main():
f, scale_factor=args.scale_factor, output_stride=output_stride)

with torch.no_grad():
input_image = torch.Tensor(input_image).cuda()
input_image = torch.Tensor(input_image).to(device=device)

heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = model(input_image)

Expand Down
7 changes: 4 additions & 3 deletions webcam_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

def main():
model = posenet.load_model(args.model)
model = model.cuda()
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device=device)
output_stride = model.output_stride

cap = cv2.VideoCapture(args.cam_id)
Expand All @@ -30,7 +31,7 @@ def main():
cap, scale_factor=args.scale_factor, output_stride=output_stride)

with torch.no_grad():
input_image = torch.Tensor(input_image).cuda()
input_image = torch.Tensor(input_image).to(device=device)

heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = model(input_image)

Expand Down Expand Up @@ -59,4 +60,4 @@ def main():


if __name__ == "__main__":
main()
main()