Skip to content

Commit b64aa29

Browse files
CLU Authorscopybara-github
authored andcommitted
Rollback add point clouds summary writer to tensorboard interface and metric writer.
PiperOrigin-RevId: 654045032
1 parent d090965 commit b64aa29

File tree

10 files changed

+19
-247
lines changed

10 files changed

+19
-247
lines changed

clu/metric_writers/async_writer.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323

2424
from collections.abc import Mapping, Sequence
2525
import contextlib
26-
from typing import Any, Optional, Union
26+
from typing import Any, Optional
2727

2828
from clu import asynclib
2929

3030
from clu.metric_writers import interface
3131
from clu.metric_writers import multi_writer
3232
import wrapt
3333

34-
3534
Array = interface.Array
3635
Scalar = interface.Scalar
3736

@@ -97,44 +96,21 @@ def write_videos(self, step: int, videos: Mapping[str, Array]):
9796

9897
@_wrap_exceptions
9998
def write_audios(
100-
self, step: int, audios: Mapping[str, Array], *, sample_rate: int
101-
):
99+
self, step: int, audios: Mapping[str, Array], *, sample_rate: int):
102100
self._pool(self._writer.write_audios)(
103-
step=step, audios=audios, sample_rate=sample_rate
104-
)
101+
step=step, audios=audios, sample_rate=sample_rate)
105102

106103
@_wrap_exceptions
107104
def write_texts(self, step: int, texts: Mapping[str, str]):
108105
self._pool(self._writer.write_texts)(step=step, texts=texts)
109106

110107
@_wrap_exceptions
111-
def write_histograms(
112-
self,
113-
step: int,
114-
arrays: Mapping[str, Array],
115-
num_buckets: Optional[Mapping[str, int]] = None,
116-
):
108+
def write_histograms(self,
109+
step: int,
110+
arrays: Mapping[str, Array],
111+
num_buckets: Optional[Mapping[str, int]] = None):
117112
self._pool(self._writer.write_histograms)(
118-
step=step, arrays=arrays, num_buckets=num_buckets
119-
)
120-
121-
@_wrap_exceptions
122-
def write_pointcloud(
123-
self,
124-
step: int,
125-
point_clouds: Mapping[str, Array],
126-
*,
127-
point_colors: Optional[Array] = None,
128-
configs: Optional[
129-
Mapping[str, Union[str, int, float, bool, None]]
130-
] = None,
131-
):
132-
self._pool(self._writer.write_pointcloud)(
133-
step=step,
134-
point_clouds=point_clouds,
135-
point_colors=point_colors,
136-
configs=configs,
137-
)
113+
step=step, arrays=arrays, num_buckets=num_buckets)
138114

139115
@_wrap_exceptions
140116
def write_hparams(self, hparams: Mapping[str, Any]):

clu/metric_writers/async_writer_test.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,6 @@ def test_write_videos(self):
7272
self.sync_writer.write_videos.assert_called_with(4,
7373
{"input_videos": mock.ANY})
7474

75-
def test_write_pointcloud(self):
76-
point_clouds = np.random.normal(0, 1, (1, 1024, 3)).astype(np.float32)
77-
point_colors = np.random.uniform(0, 1, (1, 1024, 3)).astype(np.float32)
78-
config = {
79-
"material": "PointCloudMaterial",
80-
"size": 0.09,
81-
}
82-
self.writer.write_pointcloud(
83-
step=0,
84-
point_clouds={"pcd": point_clouds},
85-
point_colors={"pcd": point_colors},
86-
configs={"config": config},
87-
)
88-
self.writer.flush()
89-
self.sync_writer.write_pointcloud.assert_called_with(
90-
step=0,
91-
point_clouds={"pcd": mock.ANY},
92-
point_colors={"pcd": mock.ANY},
93-
configs={"config": mock.ANY},
94-
)
95-
9675
def test_write_texts(self):
9776
self.writer.write_texts(4, {"samples": "bla"})
9877
self.writer.flush()

clu/metric_writers/interface.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,6 @@ def write_histograms(self,
153153
of the MetricWriter.
154154
"""
155155

156-
@abc.abstractmethod
157-
def write_pointcloud(
158-
self,
159-
step: int,
160-
point_clouds: Mapping[str, Array],
161-
*,
162-
point_colors: Optional[Mapping[str, Array]] = None,
163-
configs: Optional[
164-
Mapping[str, Union[str, int, float, bool, None]]
165-
] = None,
166-
):
167-
"""Writes point cloud summaries.
168-
169-
Args:
170-
step: Step at which the point cloud was generated.
171-
point_clouds: Mapping from point clouds key to point cloud of shape [N, 3]
172-
array of point coordinates.
173-
point_colors: Mapping from point colors key to [N, 3] array of point
174-
colors.
175-
configs: A dictionary of configuration options for the point cloud.
176-
"""
177-
178156
@abc.abstractmethod
179157
def write_hparams(self, hparams: Mapping[str, Any]):
180158
"""Write hyper parameters.

clu/metric_writers/logging_writer.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""MetricWriter that writes all values to INFO log."""
1616

1717
from collections.abc import Mapping
18-
from typing import Any, Optional, Union
18+
from typing import Any, Optional
1919

2020
from absl import logging
2121
from clu.metric_writers import interface
@@ -77,29 +77,6 @@ def write_histograms(self,
7777
self._collection_str, key,
7878
_get_histogram_as_string(histo, bins))
7979

80-
def write_pointcloud(
81-
self,
82-
step: int,
83-
point_clouds: Mapping[str, Array],
84-
*,
85-
point_colors: Optional[Mapping[str, Any]] = None,
86-
configs: Optional[
87-
Mapping[str, Union[str, int, float, bool, None]]
88-
] = None,
89-
):
90-
logging.info(
91-
"[%d]%s Got point clouds: %s, point_colors: %s, configs: %s.",
92-
step,
93-
self._collection_str,
94-
{k: v.shape for k, v in point_clouds.items()},
95-
(
96-
{k: v.shape for k, v in point_colors.items()}
97-
if point_colors is not None
98-
else None
99-
),
100-
configs,
101-
)
102-
10380
def write_hparams(self, hparams: Mapping[str, Any]):
10481
logging.info("[Hyperparameters]%s %s", self._collection_str, hparams)
10582

clu/metric_writers/logging_writer_test.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,42 +80,14 @@ def test_write_histogram(self):
8080
"INFO:absl:[4] Histogram for 'c' = {[-0.4, 0.6]: 5}",
8181
])
8282

83-
def test_write_pointcloud(self):
84-
point_clouds = np.random.normal(0, 1, (1, 1024, 3)).astype(np.float32)
85-
point_colors = np.random.uniform(0, 1, (1, 1024, 3)).astype(np.float32)
86-
config = {
87-
"material": "PointCloudMaterial",
88-
"size": 0.09,
89-
}
90-
with self.assertLogs(level="INFO") as logs:
91-
self.writer.write_pointcloud(
92-
step=4,
93-
point_clouds={"pcd": point_clouds},
94-
point_colors={"pcd": point_colors},
95-
configs={"configs": config},
96-
)
97-
self.assertEqual(
98-
logs.output,
99-
[
100-
"INFO:absl:[4] Got point clouds: {'pcd': (1, 1024, 3)},"
101-
" point_colors: {'pcd': (1, 1024, 3)}, configs: {'configs':"
102-
" {'material': 'PointCloudMaterial', 'size': 0.09}}."
103-
],
104-
)
105-
10683
def test_write_hparams(self):
10784
with self.assertLogs(level="INFO") as logs:
10885
self.writer.write_hparams({"learning_rate": 0.1, "batch_size": 128})
109-
self.assertEqual(
110-
logs.output,
111-
[
112-
"INFO:absl:[Hyperparameters] {'learning_rate': 0.1, 'batch_size':"
113-
" 128}"
114-
],
115-
)
86+
self.assertEqual(logs.output, [
87+
"INFO:absl:[Hyperparameters] {'learning_rate': 0.1, 'batch_size': 128}"
88+
])
11689

11790
def test_collection(self):
118-
writer = logging_writer.LoggingWriter(collection="train")
11991
writer = logging_writer.LoggingWriter(collection="train")
12092
with self.assertLogs(level="INFO") as logs:
12193
writer.write_scalars(0, {"a": 3, "b": 0.15})

clu/metric_writers/multi_writer.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""MetricWriter that writes to multiple MetricWriters."""
1616

1717
from collections.abc import Mapping, Sequence
18-
from typing import Any, Optional, Union
18+
from typing import Any, Optional
1919

2020
from clu.metric_writers import interface
2121

@@ -57,27 +57,13 @@ def write_texts(self, step: int, texts: Mapping[str, str]):
5757
for w in self._writers:
5858
w.write_texts(step, texts)
5959

60-
def write_histograms(
61-
self,
62-
step: int,
63-
arrays: Mapping[str, Array],
64-
num_buckets: Optional[Mapping[str, int]] = None):
60+
def write_histograms(self,
61+
step: int,
62+
arrays: Mapping[str, Array],
63+
num_buckets: Optional[Mapping[str, int]] = None):
6564
for w in self._writers:
6665
w.write_histograms(step, arrays, num_buckets)
6766

68-
def write_pointcloud(
69-
self,
70-
step: int,
71-
point_clouds: Mapping[str, Array],
72-
*,
73-
point_colors: Optional[Mapping[str, Array]] = None,
74-
configs: Optional[Mapping[str, Union[str, int, float, bool, None]]] = None
75-
):
76-
for w in self._writers:
77-
w.write_pointcloud(
78-
step, point_clouds, point_colors=point_colors, configs=configs
79-
)
80-
8167
def write_hparams(self, hparams: Mapping[str, Any]):
8268
for w in self._writers:
8369
w.write_hparams(hparams)

clu/metric_writers/multi_writer_test.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from clu.metric_writers import interface
2020
from clu.metric_writers import multi_writer
21-
import numpy as np
2221
import tensorflow as tf
2322

2423

@@ -49,29 +48,6 @@ def test_write_scalars(self):
4948
])
5049
w.flush.assert_called()
5150

52-
def test_write_pointcloud(self):
53-
point_clouds = np.random.normal(0, 1, (1, 1024, 3)).astype(np.float32)
54-
point_colors = np.random.uniform(0, 1, (1, 1024, 3)).astype(np.float32)
55-
config = {
56-
"material": "PointCloudMaterial",
57-
"size": 0.09,
58-
}
59-
self.writer.write_pointcloud(
60-
step=0,
61-
point_clouds={"pcd": point_clouds},
62-
point_colors={"pcd": point_colors},
63-
configs={"config": config},
64-
)
65-
self.writer.flush()
66-
for w in self.writers:
67-
w.write_pointcloud.assert_called_with(
68-
step=0,
69-
point_clouds={"pcd": point_clouds},
70-
point_colors={"pcd": point_colors},
71-
configs={"config": config},
72-
)
73-
w.flush.assert_called()
74-
7551

7652
if __name__ == "__main__":
7753
tf.test.main()

clu/metric_writers/tf/summary_writer.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"""
2020

2121
from collections.abc import Mapping
22-
from typing import Any, Optional, Union
22+
from typing import Any, Optional
2323

2424
from absl import logging
2525

@@ -31,7 +31,6 @@
3131
with epy.lazy_imports():
3232
# pylint: disable=g-import-not-at-top
3333
from tensorboard.plugins.hparams import api as hparams_api
34-
from tensorboard.plugins.mesh import summary as mesh_summary # pylint: disable=line-too-long
3534
# pylint: enable=g-import-not-at-top
3635

3736

@@ -98,28 +97,6 @@ def write_histograms(
9897
buckets = None if num_buckets is None else num_buckets.get(key)
9998
tf.summary.histogram(key, value, step=step, buckets=buckets)
10099

101-
def write_pointcloud(
102-
self,
103-
step: int,
104-
point_clouds: Mapping[str, Array],
105-
*,
106-
point_colors: Optional[Mapping[str, Array]] = None,
107-
configs: Optional[
108-
Mapping[str, Union[str, int, float, bool, None]]
109-
] = None,
110-
):
111-
with self._summary_writer.as_default():
112-
for key, vertices in point_clouds.items():
113-
colors = None if point_colors is None else point_colors.get(key)
114-
config = None if configs is None else configs.get(key)
115-
mesh_summary.mesh(
116-
key,
117-
vertices=vertices,
118-
colors=colors,
119-
step=step,
120-
config_dict=config,
121-
)
122-
123100
def write_hparams(self, hparams: Mapping[str, Any]):
124101
with self._summary_writer.as_default():
125102
hparams_api.hparams(dict(utils.flatten_dict(hparams)))

clu/metric_writers/tf/summary_writer_test.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,6 @@ def _load_hparams(logdir: str):
8383
return hparams
8484

8585

86-
def _load_pointcloud_data(logdir: str):
87-
"""Loads pointcloud summaries from events in a logdir."""
88-
paths = tf.io.gfile.glob(os.path.join(logdir, "events.out.tfevents.*"))
89-
data = collections.defaultdict(dict)
90-
for path in paths:
91-
for event in tf.compat.v1.train.summary_iterator(path):
92-
for value in event.summary.value:
93-
if value.metadata.plugin_data.plugin_name == "mesh":
94-
if "config" not in value.tag:
95-
data[event.step][value.tag] = tf.make_ndarray(value.tensor)
96-
else:
97-
data[event.step][value.tag] = value.metadata.plugin_data.content
98-
return data
99-
100-
10186
class SummaryWriterTest(tf.test.TestCase):
10287

10388
def setUp(self):
@@ -157,24 +142,6 @@ def test_write_histograms(self):
157142
]
158143
self.assertAllClose(data["b"], ([0, 2], expected_histograms_b))
159144

160-
def test_write_pointcloud(self):
161-
point_clouds = np.random.normal(0, 1, (1, 1024, 3)).astype(np.float32)
162-
point_colors = np.random.uniform(0, 1, (1, 1024, 3)).astype(np.float32)
163-
config = {
164-
"material": "PointCloudMaterial",
165-
"size": 0.09,
166-
}
167-
self.writer.write_pointcloud(
168-
step=0,
169-
point_clouds={"pcd": point_clouds},
170-
point_colors={"pcd": point_colors},
171-
configs={"config": config},
172-
)
173-
self.writer.flush()
174-
data = _load_pointcloud_data(self.logdir)
175-
self.assertAllClose(data[0]["pcd_VERTEX"], point_clouds)
176-
self.assertAllClose(data[0]["pcd_COLOR"], point_colors)
177-
178145
def test_hparams(self):
179146
self.writer.write_hparams(dict(batch_size=512, num_epochs=90))
180147
hparams = _load_hparams(self.logdir)

0 commit comments

Comments
 (0)