File size: 1,219 Bytes
377dccd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # Copyright 2020-present, Pietro Buzzega, Matteo Boschini, Angelo Porrello, Davide Abati, Simone Calderara.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import os
import torch.backends.cudnn
import random
import torch
import numpy as np
def get_device() -> torch.device:
"""
Returns the GPU device if available else CPU.
"""
return torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
def base_path() -> str:
"""
Returns the base bath where to log accuracies and tensorboard data.
"""
return './data/'
def base_path_dataset() -> str:
"""
Returns the base bath where to log accuracies and tensorboard data.
"""
return '/common_datasets2/CV/'
def set_random_seed(seed: int) -> None:
"""
Sets the seeds at a certain value.
:param seed: the value to be set
"""
random.seed(seed)
#os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
#torch.backends.cudnn.deterministic = True
#torch.backends.cudnn.benchmark = False |