File size: 1,998 Bytes
ea66a99 | 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 | #
# Copyright (C) 2023, Inria
# GRAPHDECO research group, https://team.inria.fr/graphdeco
# All rights reserved.
#
# This software is free for non-commercial, research and evaluation use
# under the terms of the LICENSE.md file.
#
# For inquiries contact george.drettakis@inria.fr
#
from errno import EEXIST
from os import makedirs, path
import os
def mkdir_p(folder_path):
# Creates a directory. equivalent to using mkdir -p on the command line
try:
makedirs(folder_path)
except OSError as exc: # Python >2.5
if exc.errno == EEXIST and path.isdir(folder_path):
pass
else:
raise
def searchForMaxIteration(folder):
saved_iters = [int(fname.split("_")[-1]) for fname in os.listdir(folder)]
return max(saved_iters)
def find_best_iteration_from_log(log_file_path):
"""
log_file_path : e.g. scene.model_path + '/log_metrics.txt'
Returns best_iter, best_psnr (int, float)
"""
best_iter = None
best_psnr = -1
try:
with open(log_file_path, 'r') as f:
lines = f.readlines()
except FileNotFoundError:
print(f"Log file not found: {log_file_path}")
return None, None
# lines[0] might be header: "iteration, mPSNR, nPoints\n"
# lines[1:] -> data
# Optionally, check if the first line is a header
# If you always have a header, skip lines[0]
start_idx = 0
if 'iteration' in lines[0]:
start_idx = 1
for line in lines[start_idx:]:
line = line.strip()
if not line:
continue
# e.g. "300, 27.4936, 59725"
parts = [p.strip() for p in line.split(',')]
# if len(parts) < 2:
# continue
iteration_str, mpsnr_str = parts[0], parts[1]
# optional: nPoints_str = parts[2] if you need it
it = int(iteration_str)
ps = float(mpsnr_str)
if ps > best_psnr:
best_psnr = ps
best_iter = it
return best_iter, best_psnr |