forked from TobyPDE/FRRN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dependencies.py
140 lines (109 loc) · 4.09 KB
/
check_dependencies.py
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
"""Runs a sequence of tests to determine if all dependencies are installed."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import logging
import importlib
import sys
CS_TRAIN_IMGS = 2975
CS_VAL_IMGS = 500
def check_theano():
"""Checks if theano is installed correctly."""
try:
import theano
import theano.tensor as T
# Check float type.
if theano.config.floatX != "float32":
logging.error("Theano float type must be float32. Add "
"floatX=float32 to your .theanorc.")
else:
logging.info("Theano float is float32.")
# Check if cudnn softmax is available.
try:
from dltools import architectures
architectures.FRRNBuilderBase.log_softmax_4d(T.ftensor4())
logging.info("cuDNN spatial softmax found.")
except:
logging.error("Cannot create cuDNN spatial log softmax. Install "
"cuDNN and make sure that theano uses the GPU.")
except:
logging.error("Cannot import theano.")
def check_package(package_name):
"""Checks if numpy is installed.
Args:
package_name: The name of the package to import.
"""
try:
importlib.import_module(package_name)
logging.info("Successfully imported {}.".format(package_name))
except:
logging.error("Cannot import {}. Please install.".format(package_name))
def check_chianti():
"""Checks if the Chianti C++ library is available."""
try:
import pychianti
logging.info("Use Chianti C++ library.")
except:
logging.info("Chianti C++ library is not available. Will default to "
"slower Python implementation.")
def _load_cs_split(cs_folder, split):
"""Loads a split from the CityScapes dataset.
Args:
cs_folder: The CityScapes folder.
split: The split to load.
"""
try:
from dltools import utility
dataset = utility.get_image_label_pairs(cs_folder, split)
return dataset
except:
return []
def check_cityscapes(cs_folder):
"""Checks if the Cityscapes dataset is available."""
train_images = _load_cs_split(cs_folder, "train")
val_images = _load_cs_split(cs_folder, "val")
if len(train_images) != CS_TRAIN_IMGS:
logging.error("Invalid number of CityScapes training "
"images {}.".format(len(train_images)))
else:
logging.info("Found CityScapes training set.")
if len(val_images) != CS_VAL_IMGS:
logging.error("Invalid number of CityScapes validation "
"images {}.".format(len(val_images)))
else:
logging.info("Found CityScapes validation set.")
def check_python():
"""Issues a warning if you're not running P2.7 or P3.4."""
version = sys.version[:3]
if version != "2.7" and version != "3.4":
logging.warning("You are running Python {}. We only officially support "
"Python 2.7 and 3.4. This software may "
"or may not run.".format(version))
else:
logging.info("Found supported Python version {}.".format(version))
def main(cs_folder):
"""Runs all checks."""
check_python()
check_package("numpy")
check_package("cv2")
check_package("sklearn")
check_package("sklearn.metrics")
check_package("scipy")
check_package("theano")
check_package("lasagne")
check_theano()
check_chianti()
check_cityscapes(cs_folder)
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s",
level=logging.DEBUG)
parser = argparse.ArgumentParser(
description="Checks if all needed dependencies are installed "
"correctly.")
parser.add_argument("--cs_folder",
type=str,
required=True,
help="The folder that contains the Cityscapes Dataset.")
args = parser.parse_args()
main(args.cs_folder)