Skip to content
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

Add the device argument for GPU support on the ClassifierContainer() #411

Closed
ludovicmoncla opened this issue May 1, 2024 · 1 comment · Fixed by #424
Closed

Add the device argument for GPU support on the ClassifierContainer() #411

ludovicmoncla opened this issue May 1, 2024 · 1 comment · Fixed by #424
Labels
documentation Improvements or additions to documentation

Comments

@ludovicmoncla
Copy link

I would suggest adding the device argument in the ClassifierContainer() constructor in the documentation (and also in the Workshop_AprilMay2024.ipynb notebook):
https://mapreader.readthedocs.io/en/latest/User-guide/Classify/Infer.html#initialize-classifiercontainer
for support for GPU: Nvidia chips (cuda) or Apple Mx chips (mps).

import torch

my_model = torch.load("./models/model_checkpoint_6.pkl")
labels_map = {0: "no_railspace", 1: "railspace"}
device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'

my_classifier = ClassifierContainer(my_model, labels_map, device=device)

For instance, running the inference example from the Workshop_AprilMay2024.ipynb notebook on a M1 Max Macbook laptop, the difference is 20 sec using GPU support against 9 min on CPU.

@ludovicmoncla ludovicmoncla added the documentation Improvements or additions to documentation label May 1, 2024
@rwood-97
Copy link
Collaborator

rwood-97 commented May 8, 2024

Thanks, I will add this as part of the work in ticket #417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: Done (review)
Development

Successfully merging a pull request may close this issue.

2 participants