文档检测
This commit is contained in:
2
object_detection/core/utils/__init__.py
Normal file
2
object_detection/core/utils/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .tqdm import stdout_to_tqdm
|
||||
from .timer import Timer
|
||||
27
object_detection/core/utils/timer.py
Normal file
27
object_detection/core/utils/timer.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import time
|
||||
|
||||
|
||||
class Timer(object):
|
||||
"""A simple timer."""
|
||||
|
||||
def __init__(self):
|
||||
self.total_time = 0.
|
||||
self.calls = 0
|
||||
self.start_time = 0.
|
||||
self.diff = 0.
|
||||
self.average_time = 0.
|
||||
|
||||
def tic(self):
|
||||
# using time.time instead of time.clock because time time.clock
|
||||
# does not normalize for multithreading
|
||||
self.start_time = time.time()
|
||||
|
||||
def toc(self, average=True):
|
||||
self.diff = time.time() - self.start_time
|
||||
self.total_time += self.diff
|
||||
self.calls += 1
|
||||
self.average_time = self.total_time / self.calls
|
||||
if average:
|
||||
return self.average_time
|
||||
else:
|
||||
return self.diff
|
||||
27
object_detection/core/utils/tqdm.py
Normal file
27
object_detection/core/utils/tqdm.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import contextlib
|
||||
import sys
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class TqdmFile(object):
|
||||
dummy_file = None
|
||||
|
||||
def __init__(self, dummy_file):
|
||||
self.dummy_file = dummy_file
|
||||
|
||||
def write(self, x):
|
||||
if len(x.rstrip()) > 0:
|
||||
tqdm.write(x, file=self.dummy_file)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def stdout_to_tqdm():
|
||||
save_stdout = sys.stdout
|
||||
try:
|
||||
sys.stdout = TqdmFile(sys.stdout)
|
||||
yield save_stdout
|
||||
except Exception as exc:
|
||||
raise exc
|
||||
finally:
|
||||
sys.stdout = save_stdout
|
||||
Reference in New Issue
Block a user