Skip to content

Commit

Permalink
Merge pull request #165 from princeton-vl/develop
Browse files Browse the repository at this point in the history
Bugfix v1.4.1
  • Loading branch information
araistrick authored and pvl-bot committed Jul 2, 2024
2 parents fb7991e + 55b61f3 commit 967970e
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 146 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ v1.4.0 - Infinigen Indoors
- Add library of procedural generators for indoor objects & materials
- Add indoor scene generation system, including constraint language and solver
- Add HelloRoom.md & ExportingToSimulators.md

v1.4.1
- @David-Yan1 fix placeholder & ocmesher submodule version
- @lahavlipson fix bug in surface normals of wall meshes
- @araistrick bugfix example commands & other typos
6 changes: 3 additions & 3 deletions docs/ConfiguringInfinigen.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ We recommend this command as a starting point for generating high quality videos
````
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 60000 --config video high_quality_terrain
--cleanup big_files --warmup_sec 60000 --config trailer_video high_quality_terrain
````

#### Creating large-scale stereo datasets
Expand Down Expand Up @@ -218,7 +218,7 @@ python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_
```
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 30000 --config video high_quality_terrain \
--cleanup big_files --warmup_sec 30000 --config trailer_video high_quality_terrain \
--overrides camera.camera_pose_proposal.altitude=["uniform", 20, 30]
```

Expand All @@ -228,7 +228,7 @@ python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_
```
python -m infinigen.datagen.manage_jobs --output_folder outputs/my_videos --num_scenes 500 \
--pipeline_config slurm monocular_video cuda_terrain opengl_gt \
--cleanup big_files --warmup_sec 30000 --config video high_quality_terrain \
--cleanup big_files --warmup_sec 30000 --config trailer_video high_quality_terrain \
--pipeline_overrides iterate_scene_tasks.frame_range=[1,25]
```

Expand Down
4 changes: 2 additions & 2 deletions docs/HelloRoom.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ We also provide an OpenGL-based ground truth extractor which offers additional g

To generate a single scene in one command, you can run the following:
```bash
screen python -m infinigen.datagen.manage_jobs --output_folder outputs/my_dataset --num_scenes 1000 --pipeline_configs local_256.gin monocular.gin blender_gt.gin indoor_background_configs.gin --configs singleroom.gin --pipeline_overrides get_cmd.driver_script='infinigen_examples.generate_indoors' manage_datagen_jobs.num_concurrent=16 --overrides compose_indoors.restrict_single_supported_roomtype=True
screen python -m infinigen.datagen.manage_jobs --output_folder outputs/my_dataset --num_scenes 1000 --pipeline_configs local_256GB.gin monocular.gin blender_gt.gin indoor_background_configs.gin --configs singleroom.gin --pipeline_overrides get_cmd.driver_script='infinigen_examples.generate_indoors' manage_datagen_jobs.num_concurrent=16 --overrides compose_indoors.restrict_single_supported_roomtype=True
```

To create a large dataset of many random rooms, we recommend:
```bash
screen python -m infinigen.datagen.manage_jobs --output_folder outputs/my_dataset --num_scenes 1000 --pipeline_configs local_256.gin monocular.gin blender_gt.gin indoor_background_configs.gin --configs singleroom.gin --pipeline_overrides get_cmd.driver_script='infinigen_examples.generate_indoors' manage_datagen_jobs.num_concurrent=16 --overrides compose_indoors.restrict_single_supported_roomtype=True
screen python -m infinigen.datagen.manage_jobs --output_folder outputs/my_dataset --num_scenes 1000 --pipeline_configs local_256GB.gin monocular.gin blender_gt.gin indoor_background_configs.gin --configs singleroom.gin --pipeline_overrides get_cmd.driver_script='infinigen_examples.generate_indoors' manage_datagen_jobs.num_concurrent=16 --overrides compose_indoors.restrict_single_supported_roomtype=True
```

You can inspect `outputs/my_dataset/SEED/` to see the running logs of the subprocesses and output results.
Expand Down
2 changes: 1 addition & 1 deletion docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ INFINIGEN_MINIMAL_INSTALL=True bash scripts/install/interactive_blender.sh
bash scripts/install/interactive_blender.sh

# Enable OpenGL GT
INFINIGEN_INSTALL_CUSTOMGT=True scripts/install/interactive_blender.sh
INFINIGEN_INSTALL_CUSTOMGT=True bash scripts/install/interactive_blender.sh
```

:exclamation: If you encounter any issues with the above, please add ` > logs.txt 2>&1` to the end of your command and run again, then provide the resulting logs.txt file as an attachment when making a Github Issue.
Expand Down
2 changes: 1 addition & 1 deletion infinigen/OcMesher
2 changes: 1 addition & 1 deletion infinigen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import logging

__version__ = "1.4.0"
__version__ = "1.4.1"
2 changes: 1 addition & 1 deletion infinigen/assets/shelves/kitchen_cabinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,4 @@ def sample_params(self):

def create_placeholder(self, **kwargs) -> bpy.types.Object:
x,y,z = self.dimensions
return new_bbox(-x/2 * 1.2, x/2 * 1.2, 0, y * 1.1, 0, (z + 0.06) * 1.03)
return new_bbox(-x/2 * 1.2, x/2 * 1.2, 0, y * 1.1, 0, (z + 0.06))
2 changes: 1 addition & 1 deletion infinigen/assets/shelves/kitchen_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def sample_parameters(self, dimensions):

def create_placeholder(self, **kwargs) -> bpy.types.Object:
x, y, z = self.dimensions
box = new_bbox(-x/2 * 1.08, x/2 * 1.08, 0, y, 0, self.cabinet_bottom_height + 0.13)
box = new_bbox(-x/2 * 1.08, x/2 * 1.08, 0, y, 0, self.cabinet_bottom_height + 0.095)
surface.add_geomod(box, nodegroup_tag_cube, apply=True)

if not self.island:
Expand Down
21 changes: 3 additions & 18 deletions infinigen/core/execute_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
pipeline,
exporting
)
from infinigen.tools.export import export_scene
from infinigen.tools.export import export_scene, triangulate_meshes
from infinigen.core.util.math import FixedSeed, int_hash
from infinigen.core.util.logging import Timer, save_polycounts, create_text_file
from infinigen.core.util.pipeline import RandomStageExecutor
Expand Down Expand Up @@ -228,29 +228,14 @@ def render(scene_seed, output_folder, camera_id, render_image_func=render_image,
with Timer('Render Frames'):
render_image_func(frames_folder=Path(output_folder), camera_id=camera_id)

def triangulate_meshes():
for obj in bpy.context.scene.objects:
if obj.type == 'MESH':
view_state = obj.hide_viewport
obj.hide_viewport = False
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
logging.info(f"Triangulating {obj}")
bpy.ops.mesh.quads_convert_to_tris()
bpy.ops.object.mode_set(mode='OBJECT')
obj.select_set(False)
obj.hide_viewport = view_state

@gin.configurable
def save_meshes(scene_seed, output_folder, frame_range, resample_idx=False):

if resample_idx is not None and resample_idx > 0:
resample_scene(int_hash((scene_seed, resample_idx)))

triangulate_meshes()

for obj in bpy.data.objects:
obj.hide_viewport = obj.hide_render

Expand Down
2 changes: 1 addition & 1 deletion infinigen/core/placement/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def save_camera_parameters(camera_ids, output_folder, frame, use_dof=False):
bpy.context.scene.render.resolution_y,
bpy.context.scene.render.resolution_x
))
T = np.asarray(camera_obj.matrix_world, dtype=np.float64) @ np.diag((1.,-1.,-1.,1.))
T = np.asarray(camera_obj.matrix_world, dtype=np.float64) @ np.diag((1.,-1.,-1.,1.)) # Y down Z forward (aka opencv)
np.savez(output_file, K=np.asarray(K, dtype=np.float64), T=T, HW=height_width)

if __name__ == "__main__":
Expand Down
26 changes: 11 additions & 15 deletions infinigen/datagen/customgt/camera_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,31 @@ const Matrix4f FLIP_Y_Z = Eigen::Vector4f({1,-1,-1,1}).asDiagonal();

template <int h, int w, typename T_orig=double, typename T_final=float>
Eigen::Matrix<T_final, h, w> load_matrix(const npz &camview, const std::string &key){
const auto blender_camera_pose_data = camview.read_data<T_orig>(key);
const auto tmp = Eigen::Matrix<T_orig, h, w>(blender_camera_pose_data.data());
const auto opengl_camera_pose_data = camview.read_data<T_orig>(key);
const auto tmp = Eigen::Matrix<T_orig, h, w>(opengl_camera_pose_data.data());
return tmp.transpose().template cast<T_final>();
}

CameraView::CameraView(const std::string fstr, const fs::path input_dir, const int width, const int height) : frame_string(fstr), image_height(height), image_width(width), buffer_height(height*2), buffer_width(width*2)
{
// Current Frame
const fs::path current_frame_cam_path = input_dir / ("camview_"+frame_string+".npz");
const npz current_camview(current_frame_cam_path);
const Matrix4f blender_camera_pose = load_matrix<4, 4>(current_camview, "T") * FLIP_Y_Z; // TODO REMOVE
current_frame_view_matrix = glm::make_mat4(Matrix4f(blender_camera_pose.inverse()).data());
const npz current_camview(current_frame_cam_path); // Y down Z forward (aka opencv)
const Matrix4f opengl_camera_pose = load_matrix<4, 4>(current_camview, "T") * FLIP_Y_Z;
current_frame_view_matrix = glm::make_mat4(Matrix4f(opengl_camera_pose.inverse()).data()); // Y up Z back (aka blender/opengl)

// Next Frame
const fs::path next_frame_cam_path = increment_int_substr({"frame_([0-9]{4})", "camview_[0-9]+_[0-9]+_([0-9]{4})"}, current_frame_cam_path);
const npz next_camview(next_frame_cam_path);
const Matrix4f next_blender_camera_pose = load_matrix<4, 4>(next_camview, "T") * FLIP_Y_Z; // TODO REMOVE
next_frame_view_matrix = glm::make_mat4(Matrix4f(next_blender_camera_pose.inverse()).data());
const Matrix4f next_opengl_camera_pose = load_matrix<4, 4>(next_camview, "T") * FLIP_Y_Z;
next_frame_view_matrix = glm::make_mat4(Matrix4f(next_opengl_camera_pose.inverse()).data());

// Set Camera Position
position = glm::make_vec3(blender_camera_pose.block<3, 1>(0, 3).data());

// Set WC -> Img Transformation
// Set CC -> Img Transformation
const Matrix3f K_mat3x3 = load_matrix<3, 3>(current_camview, "K");
Matrix4f K_mat = Matrix4f::Identity();
buffer_over_image = 2;
K_mat.block<2,3>(0, 0) = buffer_over_image * K_mat3x3.block<2,3>(0, 0);
wc2img = glm::make_mat4(Matrix4f(K_mat * FLIP_Y_Z * blender_camera_pose.inverse()).data());
cc2img = glm::make_mat4(K_mat.data()); // maps opencv wc to img

fx = K_mat(0,0);
fy = K_mat(1,1);
Expand Down Expand Up @@ -107,10 +104,9 @@ CameraView::CameraView(const std::string fstr, const fs::path input_dir, const i
void CameraView::activateShader(Shader &shader) const {
shader.use();
shader.setMat4("projection", projection);
shader.setMat4("view", current_frame_view_matrix);
shader.setMat4("view", current_frame_view_matrix);// Y up Z back (aka blender/opengl)
shader.setMat4("viewNext", next_frame_view_matrix);
shader.setMat4("wc2img", wc2img);
shader.setVec3("cameraPos", position);
shader.setMat4("cc2img", cc2img);
}

Tensor<double, 3> CameraView::project(const Tensor<double, 3> &cam_coords) const {
Expand Down
2 changes: 1 addition & 1 deletion infinigen/datagen/customgt/camera_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CameraView
// float calc_resolution_scale(const npz &camview) const;
unsigned int create_framebuffer();

glm::mat4 wc2img, projection, current_frame_view_matrix, next_frame_view_matrix;
glm::mat4 cc2img, projection, current_frame_view_matrix, next_frame_view_matrix;
glm::vec3 position;
double fx, fy, cx, cy;
float buffer_over_image; // should be >= 1
Expand Down
15 changes: 6 additions & 9 deletions infinigen/datagen/customgt/glsl/spine.geom
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
layout (lines_adjacency) in;
layout (line_strip, max_vertices = 2) out;

uniform mat4 wc2img;

out vec3 normal;
out vec3 interp_pos_wc;
uniform mat4 cc2img;

in VS_OUT {
vec3 pos_wc;
Expand All @@ -19,7 +16,7 @@ in VS_OUT {
} gs_in[];

vec2 proj(vec3 v){
vec4 h = wc2img * vec4(v, 1.0);
vec4 h = cc2img * vec4(v, 1.0);
return vec2(h[0] / abs(h[2]), h[1] / abs(h[2]));
}

Expand All @@ -38,10 +35,10 @@ bool is_frontfacing(vec3 v1, vec3 v2, vec3 v3){
}

void main() {
vec3 v1 = gs_in[0].pos_wc; // A
vec3 v2 = gs_in[1].pos_wc; // B
vec3 v3 = gs_in[2].pos_wc;
vec3 v4 = gs_in[3].pos_wc;
vec3 v1 = gs_in[0].pos_cc; // A
vec3 v2 = gs_in[1].pos_cc; // B
vec3 v3 = gs_in[2].pos_cc;
vec3 v4 = gs_in[3].pos_cc;

bool draw_boundary = (is_frontfacing(v1, v2, v3) != is_frontfacing(v2, v1, v4));

Expand Down
58 changes: 30 additions & 28 deletions infinigen/datagen/customgt/glsl/wings.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

#version 440 core

uniform vec3 cameraPos;

uniform int object_index;

in vec3 interp_pos_wc;
in vec3 interp_pos_cc;
in vec3 interp_pos_cc_next;
in vec3 normal;
in vec3 cc_normal;
in float tri_area;
in float px_area;
Expand All @@ -27,36 +23,42 @@ layout (location = 5) out ivec4 tag_segmentation;
layout (location = 6) out ivec4 instance_segmentation;
layout (location = 7) out vec4 geo_normal;

mat4 cv_to_sn_convention = mat4(
vec4(1., 0., 0., 0.),
vec4(0., -1., 0., 0.),
vec4(0., 0., -1., 0.),
vec4(0., 0., 0., 1.));

/*
// No longer used
layout (location = 3) out vec4 faceSize;
layout (location = 4) out vec4 pixelSize;
*/

void main() {
vec3 updated_normal = normal;
if (dot((cameraPos - interp_pos_wc), updated_normal) < 0){
updated_normal = updated_normal * -1;
}

rasterized_cc = vec4(interp_pos_cc, 1.0);
if (has_flow > 0.99)
next_rasterized_cc = vec4(interp_pos_cc_next, 1.0);
else
next_rasterized_cc = vec4(0.0, 0.0, -1.0, 1.0);
tag_segmentation = ivec4(tag, 0);
instance_segmentation = ivec4(instance_id[0], instance_id[1], instance_id[2], 1);
object_segmentation = ivec4(object_index, 0, 0, 1);

geo_normal = vec4(normalize(-cc_normal), 1.0);
rasterized_occ_bounds = ivec4(0, 0, 0, 1);

rasterized_face_id = vec4(face_id, 1.0);

/*
// No longer used
faceSize = vec4(tri_area, 0.0, 0.0, 1.0);
pixelSize = vec4(px_area, 0.0, 0.0, 1.0);
*/

rasterized_cc = vec4(interp_pos_cc, 1.0);
if (has_flow > 0.99)
next_rasterized_cc = vec4(interp_pos_cc_next, 1.0);
else
next_rasterized_cc = vec4(0.0, 0.0, -1.0, 1.0);
tag_segmentation = ivec4(tag, 0);
instance_segmentation = ivec4(instance_id[0], instance_id[1], instance_id[2], 1);
object_segmentation = ivec4(object_index, 0, 0, 1);

if (dot(interp_pos_cc, cc_normal) < 0){
geo_normal = cv_to_sn_convention * vec4(cc_normal, 1.0);
} else {
geo_normal = cv_to_sn_convention * vec4(-cc_normal, 1.0);
}
rasterized_occ_bounds = ivec4(0, 0, 0, 1);

rasterized_face_id = vec4(face_id, 1.0);

/*
// No longer used
faceSize = vec4(tri_area, 0.0, 0.0, 1.0);
pixelSize = vec4(px_area, 0.0, 0.0, 1.0);
*/

}
Loading

0 comments on commit 967970e

Please sign in to comment.