Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tensorboard examples with MonkeyModel path #6569

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions examples/python/visualization/tensorboard_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------
import copy
import os
from os.path import exists, join, dirname, basename, splitext
import sys
import numpy as np
import open3d as o3d
# pylint: disable-next=unused-import
from open3d.visualization.tensorboard_plugin import summary # noqa
from open3d.visualization.tensorboard_plugin.util import to_dict_batch
from torch.utils.tensorboard import SummaryWriter

BASE_LOGDIR = "demo_logs/pytorch/"
MODEL_DIR = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(
os.path.realpath(__file__)))), "test_data", "monkey")
MODEL_PATH = o3d.data.MonkeyModel().path


def small_scale(run_name="small_scale"):
"""Basic demo with cube and cylinder with normals and colors.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = SummaryWriter(logdir)

cube = o3d.geometry.TriangleMesh.create_box(1, 2, 4, create_uv_map=True)
Expand All @@ -45,7 +44,7 @@ def property_reference(run_name="property_reference"):
"""Produces identical visualization to small_scale, but does not store
repeated properties of ``vertex_positions`` and ``vertex_normals``.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = SummaryWriter(logdir)

cube = o3d.geometry.TriangleMesh.create_box(1, 2, 4, create_uv_map=True)
Expand Down Expand Up @@ -79,7 +78,7 @@ def large_scale(n_steps=16,
"""Generate a large scale summary. Geometry resolution increases linearly
with step. Each element in a batch is painted a different color.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = SummaryWriter(logdir)
colors = []
for k in range(batch_size):
Expand Down Expand Up @@ -116,14 +115,13 @@ def large_scale(n_steps=16,
max_outputs=batch_size)


def with_material(model_dir=MODEL_DIR):
def with_material(model_path=MODEL_PATH):
"""Read an obj model from a directory and write as a TensorBoard summary.
"""
model_name = os.path.basename(model_dir)
logdir = os.path.join(BASE_LOGDIR, model_name)
model_path = os.path.join(model_dir, model_name + ".obj")
model = o3d.t.geometry.TriangleMesh.from_legacy(
o3d.io.read_triangle_mesh(model_path))
model_dir = dirname(model_path)
model_name = splitext(basename(model_path))[0]
logdir = join(BASE_LOGDIR, model_name)
model = o3d.t.io.read_triangle_mesh(model_path)
summary_3d = {
"vertex_positions": model.vertex.positions,
"vertex_normals": model.vertex.normals,
Expand All @@ -134,8 +132,8 @@ def with_material(model_dir=MODEL_DIR):
names_to_o3dprop = {"ao": "ambient_occlusion"}

for texture in ("albedo", "normal", "ao", "metallic", "roughness"):
texture_file = os.path.join(model_dir, texture + ".png")
if os.path.exists(texture_file):
texture_file = join(model_dir, texture + ".png")
if exists(texture_file):
texture = names_to_o3dprop.get(texture, texture)
summary_3d.update({
("material_texture_map_" + texture):
Expand All @@ -149,11 +147,11 @@ def with_material(model_dir=MODEL_DIR):


def demo_scene():
"""Write the demo_scene.py example showing rich PBR materials as a summary
"""Write the demo_scene.py example showing rich PBR materials as a summary.
"""
import demo_scene
geoms = demo_scene.create_scene()
writer = SummaryWriter(os.path.join(BASE_LOGDIR, 'demo_scene'))
writer = SummaryWriter(join(BASE_LOGDIR, 'demo_scene'))
for geom_data in geoms:
geom = geom_data["geometry"]
summary_3d = {}
Expand Down
29 changes: 13 additions & 16 deletions examples/python/visualization/tensorboard_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------
import copy
import os
from os.path import exists, join, dirname, basename, splitext
import sys
import numpy as np
import open3d as o3d
Expand All @@ -14,15 +14,13 @@
import tensorflow as tf

BASE_LOGDIR = "demo_logs/tf/"
MODEL_DIR = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(
os.path.realpath(__file__)))), "test_data", "monkey")
MODEL_PATH = o3d.data.MonkeyModel().path


def small_scale(run_name="small_scale"):
"""Basic demo with cube and cylinder with normals and colors.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = tf.summary.create_file_writer(logdir)

cube = o3d.geometry.TriangleMesh.create_box(1, 2, 4, create_uv_map=True)
Expand Down Expand Up @@ -52,7 +50,7 @@ def property_reference(run_name="property_reference"):
"""Produces identical visualization to small_scale, but does not store
repeated properties of ``vertex_positions`` and ``vertex_normals``.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = tf.summary.create_file_writer(logdir)

cube = o3d.geometry.TriangleMesh.create_box(1, 2, 4, create_uv_map=True)
Expand Down Expand Up @@ -90,7 +88,7 @@ def large_scale(n_steps=16,
"""Generate a large scale summary. Geometry resolution increases linearly
with step. Each element in a batch is painted a different color.
"""
logdir = os.path.join(BASE_LOGDIR, run_name)
logdir = join(BASE_LOGDIR, run_name)
writer = tf.summary.create_file_writer(logdir)
colors = []
for k in range(batch_size):
Expand Down Expand Up @@ -130,14 +128,13 @@ def large_scale(n_steps=16,
max_outputs=batch_size)


def with_material(model_dir=MODEL_DIR):
def with_material(model_path=MODEL_PATH):
"""Read an obj model from a directory and write as a TensorBoard summary.
"""
model_name = os.path.basename(model_dir)
logdir = os.path.join(BASE_LOGDIR, model_name)
model_path = os.path.join(model_dir, model_name + ".obj")
model = o3d.t.geometry.TriangleMesh.from_legacy(
o3d.io.read_triangle_mesh(model_path))
model_dir = dirname(model_path)
model_name = splitext(basename(model_path))[0]
logdir = join(BASE_LOGDIR, model_name)
model = o3d.t.io.read_triangle_mesh(model_path)
summary_3d = {
"vertex_positions": model.vertex.positions,
"vertex_normals": model.vertex.normals,
Expand All @@ -148,8 +145,8 @@ def with_material(model_dir=MODEL_DIR):
names_to_o3dprop = {"ao": "ambient_occlusion"}

for texture in ("albedo", "normal", "ao", "metallic", "roughness"):
texture_file = os.path.join(model_dir, texture + ".png")
if os.path.exists(texture_file):
texture_file = join(model_dir, texture + ".png")
if exists(texture_file):
texture = names_to_o3dprop.get(texture, texture)
summary_3d.update({
("material_texture_map_" + texture):
Expand All @@ -168,7 +165,7 @@ def demo_scene():
"""
import demo_scene
geoms = demo_scene.create_scene()
logdir = os.path.join(BASE_LOGDIR, 'demo_scene')
logdir = join(BASE_LOGDIR, 'demo_scene')
writer = tf.summary.create_file_writer(logdir)
for geom_data in geoms:
geom = geom_data["geometry"]
Expand Down
Loading