common.py源码分析

from lib.include import *
from lib.utility.draw import *
from lib.utility.file import *
from lib.net.rate import *
COMMON_STRING ='@%s:  \n' % os.path.basename(__file__)

打印文件名

if 1:
    SEED = int(time.time()) #35202   #35202  #123  #
    random.seed(SEED)
    np.random.seed(SEED)
    torch.manual_seed(SEED)
    torch.cuda.manual_seed_all(SEED)
    COMMON_STRING += '\tset random seed\n'
    COMMON_STRING += '\t\tSEED = %d\n'%SEED

    torch.backends.cudnn.benchmark     = False  ##uses the inbuilt cudnn auto-tuner to find the fastest convolution algorithms. -
    torch.backends.cudnn.enabled       = True
    torch.backends.cudnn.deterministic = True

    COMMON_STRING += '\tset cuda environment\n'
    COMMON_STRING += '\t\ttorch.__version__              = %s\n'%torch.__version__
    COMMON_STRING += '\t\ttorch.version.cuda             = %s\n'%torch.version.cuda
    COMMON_STRING += '\t\ttorch.backends.cudnn.version() = %s\n'%torch.backends.cudnn.version()
    try:
        COMMON_STRING += '\t\tos[\'CUDA_VISIBLE_DEVICES\']     = %s\n'%os.environ['CUDA_VISIBLE_DEVICES']
        NUM_CUDA_DEVICES = len(os.environ['CUDA_VISIBLE_DEVICES'].split(','))
    except Exception:
        COMMON_STRING += '\t\tos[\'CUDA_VISIBLE_DEVICES\']     = None\n'
        NUM_CUDA_DEVICES = 1

    COMMON_STRING += '\t\ttorch.cuda.device_count()      = %d\n'%torch.cuda.device_count()
    #print ('\t\ttorch.cuda.current_device()    =', torch.cuda.current_device())


COMMON_STRING += '\n'
if __name__ == '__main__':
    print (COMMON_STRING)

输出如下结果

matplotlib.get_backend :  TkAgg#这句是在import其他包输出的
@common.py:  
    set random seed
        SEED = 1571291014
    set cuda environment
        torch.__version__              = 1.2.0#torch1.2版本
        torch.version.cuda             = 10.0.130#cuda10.0
        torch.backends.cudnn.version() = 7602#cudnn版本7.6
        os['CUDA_VISIBLE_DEVICES']     = None
        torch.cuda.device_count()      = 1

你可能感兴趣的:(common.py源码分析)