Checking consistency of serialization

This test checks the consistency of the internal states between before/after serialization. We render two images. One with normal configuration and the other with deserialized states.

[1]:
import lmenv
env = lmenv.load('.lmenv')
[2]:
import os
import imageio
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import lmscene
import lightmetrica as lm
[3]:
os.getpid()
[3]:
374
[4]:
%load_ext lightmetrica_jupyter
[5]:
lm.init()
lm.log.init('jupyter')
lm.progress.init('jupyter')
lm.info()
[I|0.000] Lightmetrica -- Version 3.0.0 (rev. 70601db) Linux x64
[6]:
if not lm.Release:
    lm.debug.attach_to_debugger()
[7]:
scene_names = lmscene.scenes_small()
[8]:
def rmse(img1, img2):
    return np.sqrt(np.mean((img1 - img2) ** 2))
[9]:
rmse_series = pd.Series(index=scene_names)
for scene_name in scene_names:
    print("Testing [scene='{}']".format(scene_name))

    # Load scene and render
    print('w/o serialization')
    lm.reset()
    lm.load_film('film_output', 'bitmap', w=1920, h=1080)
    lm.load_accel('accel', 'sahbvh')
    scene = lm.load_scene('scene', 'default', accel='$.assets.accel')
    lmscene.load(scene, env.scene_path, scene_name)
    scene.build()
    lm.load_renderer('renderer', 'raycast',
        scene='$.assets.scene',
        output='$.assets.film_output')

    renderer = lm.get_renderer('$.assets.renderer')
    renderer.render()
    film = lm.get_film('$.assets.film_output')
    img_orig = np.copy(film.buffer())

    # Visualize
    f = plt.figure(figsize=(15,15))
    ax = f.add_subplot(111)
    ax.imshow(np.clip(np.power(img_orig,1/2.2),0,1), origin='lower')
    plt.show()

    # Serialize, reset, deserialize, and render
    print('w/ serialization')
    lm.save_state_to_file('lm.serialized')
    lm.reset()
    lm.load_state_from_file('lm.serialized')

    renderer = lm.get_renderer('$.assets.renderer')
    renderer.render()
    film = lm.get_film('$.assets.film_output')
    img_serial = np.copy(film.buffer())

    # Visualize
    f = plt.figure(figsize=(15,15))
    ax = f.add_subplot(111)
    ax.imshow(np.clip(np.power(img_serial,1/2.2),0,1), origin='lower')
    plt.show()

    # Compare two images
    e = rmse(img_orig, img_serial)
    rmse_series[scene_name] = e
Testing [scene='fireplace_room']
w/o serialization
[I|0.031] Loading asset [name='film_output']
[I|0.109] Loading asset [name='accel']
[I|0.109] Loading asset [name='scene']
[I|0.109] Loading asset [name='camera_main']
[I|0.109] Loading asset [name='model_obj']
[I|0.109] .. Loading OBJ file [path='fireplace_room.obj']
[I|0.109] .. Loading MTL file [path='fireplace_room.mtl']
/miniconda/envs/lm3_dev/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
  """Entry point for launching an IPython kernel.
[I|0.436] .. Loading texture [path='wood.ppm']
[I|0.526] .. Loading texture [path='leaf.ppm']
[I|0.528] .. Loading texture [path='picture8.ppm']
[I|0.560] .. Loading texture [path='wood5.ppm']
[I|0.616] Building acceleration structure [name='accel']
[I|0.616] .. Flattening scene
[I|0.643] .. Building
[I|1.285] Loading asset [name='renderer']
../_images/executed_functest_func_serial_consistency_9_4.png
w/ serialization
../_images/executed_functest_func_serial_consistency_9_7.png
Testing [scene='cornell_box_sphere']
w/o serialization
[I|10.028] Loading asset [name='film_output']
[I|10.090] Loading asset [name='accel']
[I|10.090] Loading asset [name='scene']
[I|10.091] Loading asset [name='camera_main']
[I|10.091] Loading asset [name='model_obj']
[I|10.091] .. Loading OBJ file [path='CornellBox-Sphere.obj']
[I|10.107] .. Loading MTL file [path='CornellBox-Sphere.mtl']
[I|10.109] Building acceleration structure [name='accel']
[I|10.109] .. Flattening scene
[I|10.109] .. Building
[I|10.113] Loading asset [name='renderer']
../_images/executed_functest_func_serial_consistency_9_10.png
w/ serialization
../_images/executed_functest_func_serial_consistency_9_13.png
Testing [scene='cube']
w/o serialization
[I|14.668] Loading asset [name='film_output']
[I|14.730] Loading asset [name='accel']
[I|14.730] Loading asset [name='scene']
[I|14.730] Loading asset [name='camera_main']
[I|14.731] Loading asset [name='model_obj']
[I|14.731] .. Loading OBJ file [path='cube.obj']
[I|14.731] .. Loading MTL file [path='default.mtl']
[I|14.731] .. Loading texture [path='default.png']
[I|14.742] Building acceleration structure [name='accel']
[I|14.742] .. Flattening scene
[I|14.742] .. Building
[I|14.743] Loading asset [name='renderer']
../_images/executed_functest_func_serial_consistency_9_16.png
w/ serialization
../_images/executed_functest_func_serial_consistency_9_19.png
[10]:
rmse_series
[10]:
fireplace_room        0.0
cornell_box_sphere    0.0
cube                  0.0
dtype: float64