File size: 3,967 Bytes
5ccd75a | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | # Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from collections import OrderedDict
import numpy as np
import torch
import monai
try:
import ignite
ignite_version = ignite.__version__
del ignite
except (ImportError, AttributeError):
ignite_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import nibabel
nibabel_version = nibabel.__version__
del nibabel
except (ImportError, AttributeError):
nibabel_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import skimage
skimage_version = skimage.__version__
del skimage
except (ImportError, AttributeError):
skimage_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import PIL
PIL_version = PIL.__version__
del PIL
except (ImportError, AttributeError):
PIL_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import tensorboard
tensorboard_version = tensorboard.__version__
del tensorboard
except (ImportError, AttributeError):
tensorboard_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import gdown
gdown_version = gdown.__version__
del gdown
except (ImportError, AttributeError):
gdown_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import torchvision
torchvision_version = torchvision.__version__
del torchvision
except (ImportError, AttributeError):
torchvision_version = "NOT INSTALLED or UNKNOWN VERSION."
try:
import itk # type: ignore
itk_version = itk.Version.GetITKVersion()
del itk
except (ImportError, AttributeError):
itk_version = "NOT INSTALLED or UNKNOWN VERSION."
def get_config_values():
"""
Read the package versions into a dictionary.
"""
output = OrderedDict()
output["MONAI"] = monai.__version__
output["Python"] = sys.version.replace("\n", " ")
output["Numpy"] = np.version.full_version
output["Pytorch"] = torch.__version__
return output
def get_optional_config_values():
"""
Read the optional package versions into a dictionary.
"""
output = OrderedDict()
output["Pytorch Ignite"] = ignite_version
output["Nibabel"] = nibabel_version
output["scikit-image"] = skimage_version
output["Pillow"] = PIL_version
output["Tensorboard"] = tensorboard_version
output["gdown"] = gdown_version
output["TorchVision"] = torchvision_version
output["ITK"] = itk_version
return output
def print_config(file=sys.stdout):
"""
Print the package versions to `file`.
Args:
file: `print()` text stream file. Defaults to `sys.stdout`.
"""
for k, v in get_config_values().items():
print(f"{k} version: {v}", file=file, flush=True)
print("\nOptional dependencies:", file=file, flush=True)
for k, v in get_optional_config_values().items():
print(f"{k} version: {v}", file=file, flush=True)
print("\nFor details about installing the optional dependencies, please visit:", file=file, flush=True)
print(
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
file=file,
flush=True,
)
def set_visible_devices(*dev_inds):
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(map(str, dev_inds))
def get_torch_version_tuple():
"""
Returns:
tuple of ints represents the pytorch major/minor version.
"""
return tuple((int(x) for x in torch.__version__.split(".")[:2]))
|