MCPcopy Create free account
hub / github.com/XLearning-SCU/2022-CVPR-DART / Logger

Class Logger

utils.py:128–163  ·  view source on GitHub ↗

Write console output to external text file. Code imported from https://github.com/Cysu/open-reid/blob/master/reid/utils/logging.py.

Source from the content-addressed store, hash-verified

126 raise
127
128class Logger(object):
129 """
130 Write console output to external text file.
131 Code imported from https://github.com/Cysu/open-reid/blob/master/reid/utils/logging.py.
132 """
133 def __init__(self, fpath=None):
134 self.console = sys.stdout
135 self.file = None
136 if fpath is not None:
137 mkdir_if_missing(osp.dirname(fpath))
138 self.file = open(fpath, 'w')
139
140 def __del__(self):
141 self.close()
142
143 def __enter__(self):
144 pass
145
146 def __exit__(self, *args):
147 self.close()
148
149 def write(self, msg):
150 self.console.write(msg)
151 if self.file is not None:
152 self.file.write(msg)
153
154 def flush(self):
155 self.console.flush()
156 if self.file is not None:
157 self.file.flush()
158 os.fsync(self.file.fileno())
159
160 def close(self):
161 self.console.close()
162 if self.file is not None:
163 self.file.close()
164
165def set_seed(seed, cuda=True):
166 random.seed(seed)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected