Scheaven
2021-09-18 291deeb1fcf45dbf39a24aa72a213ff3fd6b3405
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
U
©r_éã@s¨ddlZddlZddlZddlZddlZddlZddlZddlmZddl    Z    dgZ
e dd„e    j   d¡dd…DƒƒZddd„Zdd
d „Zd d „Zd    add„Zdd„ZdS)éN)ÚdatetimeÚ seed_all_rngccs|]}t|ƒVqdS©N)Úint)Ú.0Úx©rú./utils/env.pyÚ    <genexpr>sr
Ú.écCs||dkrNt ¡tt ¡ d¡ƒt t d¡d¡}t     t
¡}|  d  |¡¡t j |¡t t |¡ ¡¡t |¡dS)z‹
    Set the random seed for the RNG in torch, numpy and python.
    Args:
        seed (int): if None, will use a strong random seed.
    Nz%S%fr Úbigz Using a generated random seed {})ÚosÚgetpidrrÚnowÚstrftimeÚ
from_bytesÚurandomÚloggingÚ    getLoggerÚ__name__ÚinfoÚformatÚnpÚrandomÚseedÚtorchÚ set_rng_stateÚ manual_seedÚ    get_state)rÚloggerrrr    rsÿþÿ
 FcCs8tj ||¡}tj |¡}|j |¡|r4|tj|<|Sr)Ú    importlibÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚ exec_moduleÚsysÚmodules)Ú module_nameÚ    file_pathZmake_importableÚspecÚmodulerrr    Ú _import_file)s   
r-cCs°ttj dd¡ƒ}|r"dtjd<nPdtjd<z0ddl}t|j d¡dƒd    krZ|j     
d¡Wnt k
rpYnXdd d „}|t ƒd kst dƒ‚ddl}||ƒdks¬t dƒ‚dS)z,
    Configurations for some libraries.
    ZDETECTRON2_DISABLE_CV2FNÚcv2ÚdisabledZOPENCV_OPENCL_RUNTIMErr ér cSsttt|j d¡d|…ƒƒS)Nr )ÚtupleÚmaprÚ __version__Úsplit)r,Údigitrrr    Ú get_versionGsz)_configure_libraries.<locals>.get_version)éézRequires torch>=1.4)ér7zRequires pyyaml>=5.1)r )rrÚenvironÚgetr'r(r.r3r4ÚoclÚ setUseOpenCLÚ ImportErrorrÚAssertionErrorÚyaml)Z disable_cv2r.r6r@rrr    Ú_configure_libraries2s 
 
rAcCs0trdSdatƒtj d¡}|r,t|ƒndS)a$Perform environment setup work. The default setup is a no-op, but this
    function allows the user to specify a Python source file or a module in
    the $FASTREID_ENV_MODULE environment variable, that performs
    custom setup work that may be necessary to their computing environment.
    NTZFASTREID_ENV_MODULE)Ú_ENV_SETUP_DONErArr:r;Úsetup_custom_environment)Zcustom_module_pathrrr    Úsetup_environmentTs 
rDcCsN| d¡rtd|ƒ}n
t |¡}t|dƒr4t|jƒsBtd |¡ƒ‚| ¡dS)zv
    Load custom environment setup by importing a Python source file or a
    module, and run the setup function.
    z.pyz fastreid.utils.env.custom_modulerDzjCustom environment module defined in {} does not have the required callable attribute 'setup_environment'.N)    Úendswithr-r!Ú import_moduleÚhasattrÚcallablerDr?r)Z custom_moduler,rrr    rCjs
 
ÿýrC)N)F)r!Úimportlib.utilrÚnumpyrrrr'rrÚ__all__r1r3r4Z TORCH_VERSIONrr-rArBrDrCrrrr    Ú<module>s  "