car-detection-bayes/utils/torch_utils.py

26 lines
828 B
Python
Raw Normal View History

import torch
def init_seeds(seed=0):
torch.manual_seed(seed)
2019-02-25 12:47:51 +00:00
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
def select_device(force_cpu=False):
if force_cpu:
2019-02-25 12:47:51 +00:00
cuda = False
device = torch.device('cpu')
else:
2019-02-25 12:47:51 +00:00
cuda = torch.cuda.is_available()
device = torch.device('cuda:0' if cuda else 'cpu')
2019-02-16 13:33:52 +00:00
2019-03-04 14:46:25 +00:00
if torch.cuda.device_count() > 1:
print('Found %g GPUs' % torch.cuda.device_count())
2019-03-04 16:34:53 +00:00
print('WARNING Multi-GPU Issue: https://github.com/ultralytics/yolov3/issues/21')
2019-03-04 16:36:41 +00:00
torch.cuda.set_device(0) # OPTIONAL: Set your GPU if multiple available
2019-03-04 14:41:22 +00:00
# # print('Using ', torch.cuda.device_count(), ' GPUs')
2019-02-16 13:33:52 +00:00
2019-02-26 01:53:11 +00:00
print('Using %s %s\n' % (device.type, torch.cuda.get_device_properties(0) if cuda else ''))
return device