Skip to content

Commit

Permalink
changes to find and fix occasional missing file bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Roberts committed Dec 29, 2020
1 parent b2a92be commit 9c9be19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
13 changes: 11 additions & 2 deletions code/python/tools/dataset_generate_hdf5_from_vrimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
parser.add_argument("--dataset_dir", required=True)
parser.add_argument("--scene_names")
parser.add_argument("--camera_names")
parser.add_argument("--frames")
parser.add_argument("--render_pass")
parser.add_argument("--n_jobs", type=int)
parser.add_argument("--denoise", action="store_true")
Expand Down Expand Up @@ -85,7 +86,11 @@ def process_scene(s, args):

if args.render_pass is None or args.render_pass == "geometry":

in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_geometry", "*.vrimg")) + '"'
if args.frames is not None:
in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_geometry", "frame." + args.frames + ".vrimg")) + '"'
else:
in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_geometry", "frame.*.vrimg")) + '"'

in_camera_trajectory_dir = os.path.abspath(os.path.join(detail_dir, camera_name))
in_metadata_nodes_file = os.path.abspath(os.path.join(detail_dir, "metadata_nodes.csv"))
in_metadata_scene_file = os.path.abspath(os.path.join(detail_dir, "metadata_scene.csv"))
Expand Down Expand Up @@ -121,7 +126,11 @@ def process_scene(s, args):

if args.render_pass is None or args.render_pass == "final":

in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_final", "*.vrimg")) + '"'
if args.frames is not None:
in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_final", "frame." + args.frames + ".vrimg")) + '"'
else:
in_vrimg_files = '"' + os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_final", "frame.*.vrimg")) + '"'

out_hdf5_dir = os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_final_hdf5"))
out_preview_dir = os.path.abspath(os.path.join(images_dir, in_scene_fileroot + "_" + camera_name + "_final_preview"))
tmp_dir_ = os.path.abspath(tmp_dir)
Expand Down
22 changes: 17 additions & 5 deletions code/python/tools/generate_hdf5_from_vrimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,26 @@
with h5py.File(out_normal_bump_cam_hdf5_file, "w") as f: f.create_dataset("dataset", data=normal_bump_cam.astype(float16), compression="gzip", compression_opts=9)
with h5py.File(out_tex_coord_hdf5_file, "w") as f: f.create_dataset("dataset", data=tex_coord.astype(float16), compression="gzip", compression_opts=9)

eps = 0.000001 # amount of numerical slack when checking if normal images are in the range [0,1]
assert all(np.min(normal_world_.reshape(-1,3), axis=0)) > 0.0 - eps
assert all(np.min(normal_cam_.reshape(-1,3), axis=0)) > 0.0 - eps
assert all(np.min(normal_bump_world_.reshape(-1,3), axis=0)) > 0.0 - eps
assert all(np.min(normal_bump_cam_.reshape(-1,3), axis=0)) > 0.0 - eps
assert all(np.max(normal_world_.reshape(-1,3), axis=0)) < 1.0 + eps
assert all(np.max(normal_cam_.reshape(-1,3), axis=0)) < 1.0 + eps
assert all(np.max(normal_bump_world_.reshape(-1,3), axis=0)) < 1.0 + eps
assert all(np.max(normal_bump_cam_.reshape(-1,3), axis=0)) < 1.0 + eps

# ideally we would normalize depth consistently for each scene, but we don't know a good depth range, so don't try to normalize
# normals are already unit-length, but due to occasional numerical artifacts we need to clip anyway
imsave(out_color_jpg_file, clip(rgb_color,0,1))
imsave(out_gamma_jpg_file, clip(rgb_color_gamma,0,1))
imsave(out_render_entity_id_png_file, render_entity_id_, vmin=np.min(color_vals_unique), vmax=np.max(color_vals_unique))
imsave(out_depth_meters_png_file, depth_meters) # ideally we would normalize depth consistently for each scene, but we don't know a good depth range, so don't try to normalize
imsave(out_normal_world_png_file, normal_world_) # normals are already unit-length so don't need to normalize
imsave(out_normal_cam_png_file, normal_cam_) # normals are already unit-length so don't need to normalize
imsave(out_normal_bump_world_png_file, normal_bump_world_) # normals are already unit-length so don't need to normalize
imsave(out_normal_bump_cam_png_file, normal_bump_cam_) # normals are already unit-length so don't need to normalize
imsave(out_depth_meters_png_file, depth_meters)
imsave(out_normal_world_png_file, clip(normal_world_,0,1))
imsave(out_normal_cam_png_file, clip(normal_cam_,0,1))
imsave(out_normal_bump_world_png_file, clip(normal_bump_world_,0,1))
imsave(out_normal_bump_cam_png_file, clip(normal_bump_cam_,0,1))
imsave(out_tex_coord_png_file, clip(tex_coord,0,1))

if args.render_pass == "final":
Expand Down

0 comments on commit 9c9be19

Please sign in to comment.