Skip to content

Commit

Permalink
added more inference logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyslavhereha committed Feb 5, 2024
1 parent f0a6234 commit aa90cc9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions custom/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@


class FPSLogger:
def __init__(self):
def __init__(self, num_of_images):
self.tottime = 0.0
self.count = 0
self.last_record = 0.0
self.last_print = time.time()
self.interval = 10
self.num_of_images = num_of_images

def start_record(self):
self.last_record = time.time()
Expand All @@ -37,7 +38,8 @@ def end_record(self):

def print_fps(self):
if time.time() - self.last_print > self.interval:
print(f"Inference running at {self.count / self.tottime:.3f} FPS")
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - mmdet - INFO - Predict({self.count}/{self.num_of_images}) "
f"- Inference running at {self.count / self.tottime:.3f} FPS")
self.last_print = time.time()


Expand All @@ -56,17 +58,13 @@ def __init__(
self.inf_dir = inf_dir
self.inf_out_dir = inf_out_dir
self.output_file = output_file
self.fps_logger = FPSLogger()
self.fps_logger = FPSLogger(len(os.listdir(self.inf_dir)))
self.run(threshold)

def run(self, threshold=0.5):
results = []
num_images = len(os.listdir(self.inf_dir))
counter = 0
for imn in os.listdir(self.inf_dir):
img = f"{self.inf_dir}/{imn}"
if counter % 100 == 0:
print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - mmdet - INFO - Predict({counter}/{num_images})")
self.fps_logger.start_record()
result = inference_detector(self.model, img)
results.append({img: extract_bounding_boxes(result, threshold)})
Expand All @@ -78,7 +76,6 @@ def run(self, threshold=0.5):
out_file=f"{self.inf_out_dir}/{imn}",
score_thr=threshold,
)
counter += 1
if self.output_file:
with open(self.output_file, "w") as f:
json.dump(results, f)
Expand Down

0 comments on commit aa90cc9

Please sign in to comment.