File size: 1,797 Bytes
a542139 | 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 | #!/usr/bin/env python
"""eval_final.py (imported, NOT modified) with every appearance comparison done at 512x512.
The only change: eval_final.appearance_metrics(pred_rgba, ref_rgba) -- called once per IV / NV view with the masked
crops -- now receives both images composited over white (exactly as appearance_metrics does internally) and resized
to 512x512 (cv2 INTER_AREA when downsampling, INTER_LINEAR when upsampling), passed on as opaque RGBA.
Rendering, masks, coverage, view selection and geometry are unchanged.
Usage: python eval512.py fb150 <eval_final.py args>
python eval512.py rest658 <eval_rest658_wrapper.py args>
"""
import os, sys, runpy
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE); sys.path.insert(0, os.path.join(HERE, "appeval"))
import numpy as np, cv2
import eval_final as EF
from appearance import composite_white
S = int(os.environ.get("EVAL_IMG_SIZE", "512"))
_orig = EF.appearance_metrics
def _to_s(x):
rgb = composite_white(np.asarray(x, np.float32))
h, w = rgb.shape[:2]
interp = cv2.INTER_AREA if (h >= S and w >= S) else cv2.INTER_LINEAR
rgb = cv2.resize(rgb, (S, S), interpolation=interp).astype(np.float32)
return np.concatenate([np.clip(rgb, 0, 1), np.ones((S, S, 1), np.float32)], -1)
def appearance_metrics_512(pred_rgba, ref_rgba):
return _orig(_to_s(pred_rgba), _to_s(ref_rgba))
EF.appearance_metrics = appearance_metrics_512
mode = sys.argv.pop(1)
if mode == "fb150":
sys.argv[0] = os.path.join(HERE, "eval_final.py"); EF.main()
elif mode == "rest658":
sys.argv[0] = os.path.join(HERE, "eval_rest658_wrapper.py")
runpy.run_path(os.path.join(HERE, "eval_rest658_wrapper.py"), run_name="__main__") # imports the patched EF
else:
sys.exit("mode must be fb150 or rest658")
|