添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
霸气的花卷  ·  python list 错位相减 ...·  2 月前    · 
憨厚的大脸猫  ·  python ...·  2 月前    · 
小猫猫  ·  python tornado ...·  1 月前    · 
有腹肌的充值卡  ·  pycharm console 清屏 ...·  1 月前    · 
飘逸的李子  ·  C# 运算符 | 菜鸟教程·  1 年前    · 
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.