Unverified 提交 ee169834 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

PyTorch Hub custom model to CUDA device fix (#2636)

Fix for #2630 raised by @Pro100rus32
上级 2e95cf3d
...@@ -128,7 +128,10 @@ def custom(path_or_model='path/to/model.pt', autoshape=True): ...@@ -128,7 +128,10 @@ def custom(path_or_model='path/to/model.pt', autoshape=True):
hub_model = Model(model.yaml).to(next(model.parameters()).device) # create hub_model = Model(model.yaml).to(next(model.parameters()).device) # create
hub_model.load_state_dict(model.float().state_dict()) # load state_dict hub_model.load_state_dict(model.float().state_dict()) # load state_dict
hub_model.names = model.names # class names hub_model.names = model.names # class names
return hub_model.autoshape() if autoshape else hub_model if autoshape:
hub_model = hub_model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available
return hub_model.to(device)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论