Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
sorry - I'm a complete beginner!
I am trying to build a 'mini-system' using the Torchreid libraries from
https://kaiyangzhou.github.io/deep-person-reid/index.html#
In their version they use CUDA but my Mac is not compatible with CUDA and it doesn't have a
CUDA enabled GPU so I installed the CPU-only version of PyTorch instead - therefore I changed
model = model.cuda()
to
model = model.to(device)
and added in
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
as you can see below. I thought this would work but I keep getting the
NameError: name 'device' is not defined
and I don't know what to do.
Please help!
(I also tried putting
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
at the top instead of the bottom to see if it made any difference but I just got another error -
NameError: name 'torch' is not defined
)
model = torchreid.models.build_model(
name='resnet50',
num_classes=datamanager.num_train_pids,
loss='softmax',
pretrained=True
model = model.to(device)
optimizer = torchreid.optim.build_optimizer(
model,
optim='adam',
lr=0.0003
scheduler = torchreid.optim.build_lr_scheduler(
optimizer,
lr_scheduler='single_step',
stepsize=20
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = torchreid.models.build_model(
name='resnet50',
num_classes=datamanager.num_train_pids,
loss='softmax',
pretrained=True
# Just right before the actual usage
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.