Skip to content

Instantly share code, notes, and snippets.

@vincentAgnus
Created March 22, 2023 16:57
Show Gist options
  • Save vincentAgnus/713ca4865eedb74ccdc31d01f1727bf8 to your computer and use it in GitHub Desktop.
Save vincentAgnus/713ca4865eedb74ccdc31d01f1727bf8 to your computer and use it in GitHub Desktop.

Revisions

  1. vincentAgnus created this gist Mar 22, 2023.
    72 changes: 72 additions & 0 deletions version_info.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    from importlib.metadata import PackageNotFoundError
    from importlib.metadata import version as get_module_version

    import subprocess
    import os

    python_libs ="""
    torch
    tensorflow
    tensorboard
    numpy
    pandas
    scikit-image
    scikit-learn
    seaborn
    simpleitk
    tensorboard
    torchvision
    yaml
    imgaug
    yacs
    yaml
    pydicom
    tqdm
    sacred
    cv2
    """

    python_libs = python_libs.split()
    #print(python_libs)

    versions = dict()

    for module in python_libs:
    try:
    versions[module] = get_module_version(module)
    except PackageNotFoundError:
    versions[module] = 'NOT FOUND'



    #cuda version
    try:
    import torch
    assert(torch.cuda.is_available())
    versions["cuda"] = torch.version.cuda
    except:
    #code for second chance with tf ?
    try:
    versions["cuda"] = "NOTFOUND"
    #out = subprocess.check_output(["nvcc","--version"],shell=True, env=None)
    #proc = subprocess.Popen("nvcc --version",stdout=subprocess.PIPE,shell=True)
    #(out, err) = proc.communicate()
    #print(out)
    except Exception as e:
    #
    print(e)
    versions["cuda"] = "NOTFOUND"


    try:
    import torch
    assert(torch.backends.cudnn.is_available())
    versions["cudnn"] = torch.backends.cudnn.version()
    except:
    versions["cudnn"] = "NOTFOUND"




    for module, version in versions.items():
    print(f"{module:<16}{version}")