Spaces:
Sleeping
Sleeping
File size: 1,696 Bytes
95b1715 |
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 |
import sys
import torch
import random
sys.path = ['.'] + sys.path
from argparse import ArgumentParser
from pathlib import Path
from metrics.metrics import metrics_registry
from utils.common_utils import setup_seed
setup_seed(777)
def run(test_opts):
metrics = []
for metric_name in test_opts.metrics:
metrics.append(
metrics_registry[metric_name]()
)
out_path = None
for metric in metrics:
print("Calculating", metric.get_name())
if test_opts.metrics_dir != "":
out_path = Path(test_opts.metrics_dir) / metric.get_name()
out_path = f"{out_path}.json"
_, value, _ = metric(
test_opts.orig_path,
test_opts.reconstr_path,
out_path=str(out_path) if out_path else None,
)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--metrics", nargs="+", help="List of calculated metrics")
parser.add_argument(
"--orig_path", type=str, help="Path to directory of original images to evaluate"
)
parser.add_argument(
"--reconstr_path",
type=str,
help="Path to directory of reconstructions of images to evaluate",
)
parser.add_argument(
"--batch_size", default=4, type=int, help="Batch size for testing and inference"
)
parser.add_argument(
"--workers",
default=4,
type=int,
help="Number of test/inference dataloader workers",
)
parser.add_argument(
"--metrics_dir",
default="",
type=str,
help="Directory to save .json metrics info",
)
test_opts = parser.parse_args()
run(test_opts)
|