tensorbored 2.21.0rc1769983804__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tensorbored/__init__.py +112 -0
- tensorbored/_vendor/__init__.py +0 -0
- tensorbored/_vendor/bleach/__init__.py +125 -0
- tensorbored/_vendor/bleach/_vendor/__init__.py +0 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/__init__.py +35 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_ihatexml.py +289 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_inputstream.py +918 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_tokenizer.py +1735 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_trie/__init__.py +5 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_trie/_base.py +40 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_trie/py.py +67 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/_utils.py +159 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/constants.py +2946 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/__init__.py +0 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/alphabeticalattributes.py +29 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/base.py +12 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/inject_meta_charset.py +73 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/lint.py +93 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/optionaltags.py +207 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/sanitizer.py +916 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/filters/whitespace.py +38 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/html5parser.py +2795 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/serializer.py +409 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/__init__.py +30 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/genshi.py +54 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/sax.py +50 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/__init__.py +88 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/base.py +417 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/dom.py +239 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree.py +343 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree_lxml.py +392 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/__init__.py +154 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/base.py +252 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/dom.py +43 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree.py +131 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree_lxml.py +215 -0
- tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/genshi.py +69 -0
- tensorbored/_vendor/bleach/_vendor/parse.py +1078 -0
- tensorbored/_vendor/bleach/callbacks.py +32 -0
- tensorbored/_vendor/bleach/html5lib_shim.py +757 -0
- tensorbored/_vendor/bleach/linkifier.py +633 -0
- tensorbored/_vendor/bleach/parse_shim.py +1 -0
- tensorbored/_vendor/bleach/sanitizer.py +638 -0
- tensorbored/_vendor/bleach/six_shim.py +19 -0
- tensorbored/_vendor/webencodings/__init__.py +342 -0
- tensorbored/_vendor/webencodings/labels.py +231 -0
- tensorbored/_vendor/webencodings/mklabels.py +59 -0
- tensorbored/_vendor/webencodings/x_user_defined.py +325 -0
- tensorbored/assets.py +36 -0
- tensorbored/auth.py +102 -0
- tensorbored/backend/__init__.py +0 -0
- tensorbored/backend/application.py +604 -0
- tensorbored/backend/auth_context_middleware.py +38 -0
- tensorbored/backend/client_feature_flags.py +113 -0
- tensorbored/backend/empty_path_redirect.py +46 -0
- tensorbored/backend/event_processing/__init__.py +0 -0
- tensorbored/backend/event_processing/data_ingester.py +276 -0
- tensorbored/backend/event_processing/data_provider.py +535 -0
- tensorbored/backend/event_processing/directory_loader.py +142 -0
- tensorbored/backend/event_processing/directory_watcher.py +272 -0
- tensorbored/backend/event_processing/event_accumulator.py +950 -0
- tensorbored/backend/event_processing/event_file_inspector.py +463 -0
- tensorbored/backend/event_processing/event_file_loader.py +292 -0
- tensorbored/backend/event_processing/event_multiplexer.py +521 -0
- tensorbored/backend/event_processing/event_util.py +68 -0
- tensorbored/backend/event_processing/io_wrapper.py +223 -0
- tensorbored/backend/event_processing/plugin_asset_util.py +104 -0
- tensorbored/backend/event_processing/plugin_event_accumulator.py +721 -0
- tensorbored/backend/event_processing/plugin_event_multiplexer.py +522 -0
- tensorbored/backend/event_processing/reservoir.py +266 -0
- tensorbored/backend/event_processing/tag_types.py +29 -0
- tensorbored/backend/experiment_id.py +71 -0
- tensorbored/backend/experimental_plugin.py +51 -0
- tensorbored/backend/http_util.py +263 -0
- tensorbored/backend/json_util.py +70 -0
- tensorbored/backend/path_prefix.py +67 -0
- tensorbored/backend/process_graph.py +74 -0
- tensorbored/backend/security_validator.py +202 -0
- tensorbored/compat/__init__.py +69 -0
- tensorbored/compat/proto/__init__.py +0 -0
- tensorbored/compat/proto/allocation_description_pb2.py +35 -0
- tensorbored/compat/proto/api_def_pb2.py +82 -0
- tensorbored/compat/proto/attr_value_pb2.py +80 -0
- tensorbored/compat/proto/cluster_pb2.py +58 -0
- tensorbored/compat/proto/config_pb2.py +271 -0
- tensorbored/compat/proto/coordination_config_pb2.py +45 -0
- tensorbored/compat/proto/cost_graph_pb2.py +87 -0
- tensorbored/compat/proto/cpp_shape_inference_pb2.py +70 -0
- tensorbored/compat/proto/debug_pb2.py +65 -0
- tensorbored/compat/proto/event_pb2.py +149 -0
- tensorbored/compat/proto/full_type_pb2.py +74 -0
- tensorbored/compat/proto/function_pb2.py +157 -0
- tensorbored/compat/proto/graph_debug_info_pb2.py +111 -0
- tensorbored/compat/proto/graph_pb2.py +41 -0
- tensorbored/compat/proto/histogram_pb2.py +39 -0
- tensorbored/compat/proto/meta_graph_pb2.py +254 -0
- tensorbored/compat/proto/node_def_pb2.py +61 -0
- tensorbored/compat/proto/op_def_pb2.py +81 -0
- tensorbored/compat/proto/resource_handle_pb2.py +48 -0
- tensorbored/compat/proto/rewriter_config_pb2.py +93 -0
- tensorbored/compat/proto/rpc_options_pb2.py +35 -0
- tensorbored/compat/proto/saved_object_graph_pb2.py +193 -0
- tensorbored/compat/proto/saver_pb2.py +38 -0
- tensorbored/compat/proto/step_stats_pb2.py +116 -0
- tensorbored/compat/proto/struct_pb2.py +144 -0
- tensorbored/compat/proto/summary_pb2.py +111 -0
- tensorbored/compat/proto/tensor_description_pb2.py +38 -0
- tensorbored/compat/proto/tensor_pb2.py +68 -0
- tensorbored/compat/proto/tensor_shape_pb2.py +46 -0
- tensorbored/compat/proto/tfprof_log_pb2.py +307 -0
- tensorbored/compat/proto/trackable_object_graph_pb2.py +90 -0
- tensorbored/compat/proto/types_pb2.py +105 -0
- tensorbored/compat/proto/variable_pb2.py +62 -0
- tensorbored/compat/proto/verifier_config_pb2.py +38 -0
- tensorbored/compat/proto/versions_pb2.py +35 -0
- tensorbored/compat/tensorflow_stub/__init__.py +38 -0
- tensorbored/compat/tensorflow_stub/app.py +124 -0
- tensorbored/compat/tensorflow_stub/compat/__init__.py +131 -0
- tensorbored/compat/tensorflow_stub/compat/v1/__init__.py +20 -0
- tensorbored/compat/tensorflow_stub/dtypes.py +692 -0
- tensorbored/compat/tensorflow_stub/error_codes.py +169 -0
- tensorbored/compat/tensorflow_stub/errors.py +507 -0
- tensorbored/compat/tensorflow_stub/flags.py +124 -0
- tensorbored/compat/tensorflow_stub/io/__init__.py +17 -0
- tensorbored/compat/tensorflow_stub/io/gfile.py +1011 -0
- tensorbored/compat/tensorflow_stub/pywrap_tensorflow.py +285 -0
- tensorbored/compat/tensorflow_stub/tensor_shape.py +1035 -0
- tensorbored/context.py +129 -0
- tensorbored/data/__init__.py +0 -0
- tensorbored/data/grpc_provider.py +365 -0
- tensorbored/data/ingester.py +46 -0
- tensorbored/data/proto/__init__.py +0 -0
- tensorbored/data/proto/data_provider_pb2.py +517 -0
- tensorbored/data/proto/data_provider_pb2_grpc.py +374 -0
- tensorbored/data/provider.py +1365 -0
- tensorbored/data/server_ingester.py +301 -0
- tensorbored/data_compat.py +159 -0
- tensorbored/dataclass_compat.py +224 -0
- tensorbored/default.py +124 -0
- tensorbored/errors.py +130 -0
- tensorbored/lazy.py +99 -0
- tensorbored/main.py +48 -0
- tensorbored/main_lib.py +62 -0
- tensorbored/manager.py +487 -0
- tensorbored/notebook.py +441 -0
- tensorbored/plugin_util.py +266 -0
- tensorbored/plugins/__init__.py +0 -0
- tensorbored/plugins/audio/__init__.py +0 -0
- tensorbored/plugins/audio/audio_plugin.py +229 -0
- tensorbored/plugins/audio/metadata.py +69 -0
- tensorbored/plugins/audio/plugin_data_pb2.py +37 -0
- tensorbored/plugins/audio/summary.py +230 -0
- tensorbored/plugins/audio/summary_v2.py +124 -0
- tensorbored/plugins/base_plugin.py +367 -0
- tensorbored/plugins/core/__init__.py +0 -0
- tensorbored/plugins/core/core_plugin.py +981 -0
- tensorbored/plugins/custom_scalar/__init__.py +0 -0
- tensorbored/plugins/custom_scalar/custom_scalars_plugin.py +320 -0
- tensorbored/plugins/custom_scalar/layout_pb2.py +85 -0
- tensorbored/plugins/custom_scalar/metadata.py +35 -0
- tensorbored/plugins/custom_scalar/summary.py +79 -0
- tensorbored/plugins/debugger_v2/__init__.py +0 -0
- tensorbored/plugins/debugger_v2/debug_data_multiplexer.py +631 -0
- tensorbored/plugins/debugger_v2/debug_data_provider.py +634 -0
- tensorbored/plugins/debugger_v2/debugger_v2_plugin.py +504 -0
- tensorbored/plugins/distribution/__init__.py +0 -0
- tensorbored/plugins/distribution/compressor.py +158 -0
- tensorbored/plugins/distribution/distributions_plugin.py +116 -0
- tensorbored/plugins/distribution/metadata.py +19 -0
- tensorbored/plugins/graph/__init__.py +0 -0
- tensorbored/plugins/graph/graph_util.py +129 -0
- tensorbored/plugins/graph/graphs_plugin.py +336 -0
- tensorbored/plugins/graph/keras_util.py +328 -0
- tensorbored/plugins/graph/metadata.py +42 -0
- tensorbored/plugins/histogram/__init__.py +0 -0
- tensorbored/plugins/histogram/histograms_plugin.py +144 -0
- tensorbored/plugins/histogram/metadata.py +63 -0
- tensorbored/plugins/histogram/plugin_data_pb2.py +34 -0
- tensorbored/plugins/histogram/summary.py +234 -0
- tensorbored/plugins/histogram/summary_v2.py +292 -0
- tensorbored/plugins/hparams/__init__.py +14 -0
- tensorbored/plugins/hparams/_keras.py +93 -0
- tensorbored/plugins/hparams/api.py +130 -0
- tensorbored/plugins/hparams/api_pb2.py +208 -0
- tensorbored/plugins/hparams/backend_context.py +606 -0
- tensorbored/plugins/hparams/download_data.py +158 -0
- tensorbored/plugins/hparams/error.py +26 -0
- tensorbored/plugins/hparams/get_experiment.py +71 -0
- tensorbored/plugins/hparams/hparams_plugin.py +206 -0
- tensorbored/plugins/hparams/hparams_util_pb2.py +69 -0
- tensorbored/plugins/hparams/json_format_compat.py +38 -0
- tensorbored/plugins/hparams/list_metric_evals.py +57 -0
- tensorbored/plugins/hparams/list_session_groups.py +1040 -0
- tensorbored/plugins/hparams/metadata.py +125 -0
- tensorbored/plugins/hparams/metrics.py +41 -0
- tensorbored/plugins/hparams/plugin_data_pb2.py +69 -0
- tensorbored/plugins/hparams/summary.py +205 -0
- tensorbored/plugins/hparams/summary_v2.py +597 -0
- tensorbored/plugins/image/__init__.py +0 -0
- tensorbored/plugins/image/images_plugin.py +232 -0
- tensorbored/plugins/image/metadata.py +65 -0
- tensorbored/plugins/image/plugin_data_pb2.py +34 -0
- tensorbored/plugins/image/summary.py +159 -0
- tensorbored/plugins/image/summary_v2.py +130 -0
- tensorbored/plugins/mesh/__init__.py +14 -0
- tensorbored/plugins/mesh/mesh_plugin.py +292 -0
- tensorbored/plugins/mesh/metadata.py +152 -0
- tensorbored/plugins/mesh/plugin_data_pb2.py +37 -0
- tensorbored/plugins/mesh/summary.py +251 -0
- tensorbored/plugins/mesh/summary_v2.py +214 -0
- tensorbored/plugins/metrics/__init__.py +0 -0
- tensorbored/plugins/metrics/metadata.py +17 -0
- tensorbored/plugins/metrics/metrics_plugin.py +623 -0
- tensorbored/plugins/pr_curve/__init__.py +0 -0
- tensorbored/plugins/pr_curve/metadata.py +75 -0
- tensorbored/plugins/pr_curve/plugin_data_pb2.py +34 -0
- tensorbored/plugins/pr_curve/pr_curves_plugin.py +241 -0
- tensorbored/plugins/pr_curve/summary.py +574 -0
- tensorbored/plugins/profile_redirect/__init__.py +0 -0
- tensorbored/plugins/profile_redirect/profile_redirect_plugin.py +49 -0
- tensorbored/plugins/projector/__init__.py +67 -0
- tensorbored/plugins/projector/metadata.py +26 -0
- tensorbored/plugins/projector/projector_config_pb2.py +54 -0
- tensorbored/plugins/projector/projector_plugin.py +795 -0
- tensorbored/plugins/projector/tf_projector_plugin/index.js +32 -0
- tensorbored/plugins/projector/tf_projector_plugin/projector_binary.html +524 -0
- tensorbored/plugins/projector/tf_projector_plugin/projector_binary.js +15536 -0
- tensorbored/plugins/scalar/__init__.py +0 -0
- tensorbored/plugins/scalar/metadata.py +60 -0
- tensorbored/plugins/scalar/plugin_data_pb2.py +34 -0
- tensorbored/plugins/scalar/scalars_plugin.py +181 -0
- tensorbored/plugins/scalar/summary.py +109 -0
- tensorbored/plugins/scalar/summary_v2.py +124 -0
- tensorbored/plugins/text/__init__.py +0 -0
- tensorbored/plugins/text/metadata.py +62 -0
- tensorbored/plugins/text/plugin_data_pb2.py +34 -0
- tensorbored/plugins/text/summary.py +114 -0
- tensorbored/plugins/text/summary_v2.py +124 -0
- tensorbored/plugins/text/text_plugin.py +288 -0
- tensorbored/plugins/wit_redirect/__init__.py +0 -0
- tensorbored/plugins/wit_redirect/wit_redirect_plugin.py +49 -0
- tensorbored/program.py +910 -0
- tensorbored/summary/__init__.py +35 -0
- tensorbored/summary/_output.py +124 -0
- tensorbored/summary/_tf/__init__.py +14 -0
- tensorbored/summary/_tf/summary/__init__.py +178 -0
- tensorbored/summary/_writer.py +105 -0
- tensorbored/summary/v1.py +51 -0
- tensorbored/summary/v2.py +25 -0
- tensorbored/summary/writer/__init__.py +13 -0
- tensorbored/summary/writer/event_file_writer.py +291 -0
- tensorbored/summary/writer/record_writer.py +50 -0
- tensorbored/util/__init__.py +0 -0
- tensorbored/util/encoder.py +116 -0
- tensorbored/util/grpc_util.py +311 -0
- tensorbored/util/img_mime_type_detector.py +40 -0
- tensorbored/util/io_util.py +20 -0
- tensorbored/util/lazy_tensor_creator.py +110 -0
- tensorbored/util/op_evaluator.py +104 -0
- tensorbored/util/platform_util.py +20 -0
- tensorbored/util/tb_logging.py +24 -0
- tensorbored/util/tensor_util.py +617 -0
- tensorbored/util/timing.py +122 -0
- tensorbored/version.py +21 -0
- tensorbored/webfiles.zip +0 -0
- tensorbored-2.21.0rc1769983804.dist-info/METADATA +49 -0
- tensorbored-2.21.0rc1769983804.dist-info/RECORD +271 -0
- tensorbored-2.21.0rc1769983804.dist-info/WHEEL +5 -0
- tensorbored-2.21.0rc1769983804.dist-info/entry_points.txt +6 -0
- tensorbored-2.21.0rc1769983804.dist-info/licenses/LICENSE +739 -0
- tensorbored-2.21.0rc1769983804.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""The TensorBoard Audio plugin."""
|
|
16
|
+
|
|
17
|
+
import urllib.parse
|
|
18
|
+
|
|
19
|
+
from werkzeug import wrappers
|
|
20
|
+
|
|
21
|
+
from tensorbored import errors
|
|
22
|
+
from tensorbored import plugin_util
|
|
23
|
+
from tensorbored.backend import http_util
|
|
24
|
+
from tensorbored.data import provider
|
|
25
|
+
from tensorbored.plugins import base_plugin
|
|
26
|
+
from tensorbored.plugins.audio import metadata
|
|
27
|
+
|
|
28
|
+
_DEFAULT_MIME_TYPE = "application/octet-stream"
|
|
29
|
+
_DEFAULT_DOWNSAMPLING = 10 # audio clips per time series
|
|
30
|
+
_MIME_TYPES = {
|
|
31
|
+
metadata.Encoding.Value("WAV"): "audio/wav",
|
|
32
|
+
}
|
|
33
|
+
_ALLOWED_MIME_TYPES = frozenset(
|
|
34
|
+
list(_MIME_TYPES.values()) + [_DEFAULT_MIME_TYPE]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class AudioPlugin(base_plugin.TBPlugin):
|
|
39
|
+
"""Audio Plugin for TensorBoard."""
|
|
40
|
+
|
|
41
|
+
plugin_name = metadata.PLUGIN_NAME
|
|
42
|
+
|
|
43
|
+
def __init__(self, context):
|
|
44
|
+
"""Instantiates AudioPlugin via TensorBoard core.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
context: A base_plugin.TBContext instance.
|
|
48
|
+
"""
|
|
49
|
+
self._data_provider = context.data_provider
|
|
50
|
+
self._downsample_to = (context.sampling_hints or {}).get(
|
|
51
|
+
self.plugin_name, _DEFAULT_DOWNSAMPLING
|
|
52
|
+
)
|
|
53
|
+
self._version_checker = plugin_util._MetadataVersionChecker(
|
|
54
|
+
data_kind="audio",
|
|
55
|
+
latest_known_version=0,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
def get_plugin_apps(self):
|
|
59
|
+
return {
|
|
60
|
+
"/audio": self._serve_audio_metadata,
|
|
61
|
+
"/individualAudio": self._serve_individual_audio,
|
|
62
|
+
"/tags": self._serve_tags,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
def is_active(self):
|
|
66
|
+
return False # `list_plugins` as called by TB core suffices
|
|
67
|
+
|
|
68
|
+
def frontend_metadata(self):
|
|
69
|
+
return base_plugin.FrontendMetadata(element_name="tf-audio-dashboard")
|
|
70
|
+
|
|
71
|
+
def _index_impl(self, ctx, experiment):
|
|
72
|
+
"""Return information about the tags in each run.
|
|
73
|
+
|
|
74
|
+
Result is a dictionary of the form
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
"runName1": {
|
|
78
|
+
"tagName1": {
|
|
79
|
+
"displayName": "The first tag",
|
|
80
|
+
"description": "<p>Long ago there was just one tag...</p>",
|
|
81
|
+
"samples": 3
|
|
82
|
+
},
|
|
83
|
+
"tagName2": ...,
|
|
84
|
+
...
|
|
85
|
+
},
|
|
86
|
+
"runName2": ...,
|
|
87
|
+
...
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
For each tag, `samples` is the greatest number of audio clips that
|
|
91
|
+
appear at any particular step. (It's not related to "samples of a
|
|
92
|
+
waveform.") For example, if for tag `minibatch_input` there are
|
|
93
|
+
five audio clips at step 0 and ten audio clips at step 1, then the
|
|
94
|
+
dictionary for `"minibatch_input"` will contain `"samples": 10`.
|
|
95
|
+
"""
|
|
96
|
+
mapping = self._data_provider.list_blob_sequences(
|
|
97
|
+
ctx,
|
|
98
|
+
experiment_id=experiment,
|
|
99
|
+
plugin_name=metadata.PLUGIN_NAME,
|
|
100
|
+
)
|
|
101
|
+
result = {run: {} for run in mapping}
|
|
102
|
+
for run, tag_to_time_series in mapping.items():
|
|
103
|
+
for tag, time_series in tag_to_time_series.items():
|
|
104
|
+
md = metadata.parse_plugin_metadata(time_series.plugin_content)
|
|
105
|
+
if not self._version_checker.ok(md.version, run, tag):
|
|
106
|
+
continue
|
|
107
|
+
description = plugin_util.markdown_to_safe_html(
|
|
108
|
+
time_series.description
|
|
109
|
+
)
|
|
110
|
+
result[run][tag] = {
|
|
111
|
+
"displayName": time_series.display_name,
|
|
112
|
+
"description": description,
|
|
113
|
+
"samples": time_series.max_length,
|
|
114
|
+
}
|
|
115
|
+
return result
|
|
116
|
+
|
|
117
|
+
@wrappers.Request.application
|
|
118
|
+
def _serve_audio_metadata(self, request):
|
|
119
|
+
"""Given a tag and list of runs, serve a list of metadata for audio.
|
|
120
|
+
|
|
121
|
+
Note that the actual audio data are not sent; instead, we respond
|
|
122
|
+
with URLs to the audio. The frontend should treat these URLs as
|
|
123
|
+
opaque and should not try to parse information about them or
|
|
124
|
+
generate them itself, as the format may change.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
request: A werkzeug.wrappers.Request object.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
A werkzeug.Response application.
|
|
131
|
+
"""
|
|
132
|
+
ctx = plugin_util.context(request.environ)
|
|
133
|
+
experiment = plugin_util.experiment_id(request.environ)
|
|
134
|
+
tag = request.args.get("tag")
|
|
135
|
+
run = request.args.get("run")
|
|
136
|
+
sample = int(request.args.get("sample", 0))
|
|
137
|
+
|
|
138
|
+
response = self._audio_response_for_run(
|
|
139
|
+
ctx, experiment, run, tag, sample
|
|
140
|
+
)
|
|
141
|
+
return http_util.Respond(request, response, "application/json")
|
|
142
|
+
|
|
143
|
+
def _audio_response_for_run(self, ctx, experiment, run, tag, sample):
|
|
144
|
+
"""Builds a JSON-serializable object with information about audio.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
run: The name of the run.
|
|
148
|
+
tag: The name of the tag the audio entries all belong to.
|
|
149
|
+
sample: The zero-indexed sample of the audio sample for which to
|
|
150
|
+
retrieve information. For instance, setting `sample` to `2` will
|
|
151
|
+
fetch information about only the third audio clip of each batch,
|
|
152
|
+
and steps with fewer than three audio clips will be omitted from
|
|
153
|
+
the results.
|
|
154
|
+
|
|
155
|
+
Returns:
|
|
156
|
+
A list of dictionaries containing the wall time, step, label,
|
|
157
|
+
content type, and query string for each audio entry.
|
|
158
|
+
"""
|
|
159
|
+
all_audio = self._data_provider.read_blob_sequences(
|
|
160
|
+
ctx,
|
|
161
|
+
experiment_id=experiment,
|
|
162
|
+
plugin_name=metadata.PLUGIN_NAME,
|
|
163
|
+
downsample=self._downsample_to,
|
|
164
|
+
run_tag_filter=provider.RunTagFilter(runs=[run], tags=[tag]),
|
|
165
|
+
)
|
|
166
|
+
audio = all_audio.get(run, {}).get(tag, None)
|
|
167
|
+
if audio is None:
|
|
168
|
+
raise errors.NotFoundError(
|
|
169
|
+
"No audio data for run=%r, tag=%r" % (run, tag)
|
|
170
|
+
)
|
|
171
|
+
content_type = self._get_mime_type(ctx, experiment, run, tag)
|
|
172
|
+
response = []
|
|
173
|
+
for datum in audio:
|
|
174
|
+
if len(datum.values) < sample:
|
|
175
|
+
continue
|
|
176
|
+
query = urllib.parse.urlencode(
|
|
177
|
+
{
|
|
178
|
+
"blob_key": datum.values[sample].blob_key,
|
|
179
|
+
"content_type": content_type,
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
response.append(
|
|
183
|
+
{
|
|
184
|
+
"wall_time": datum.wall_time,
|
|
185
|
+
"label": "",
|
|
186
|
+
"step": datum.step,
|
|
187
|
+
"contentType": content_type,
|
|
188
|
+
"query": query,
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
return response
|
|
192
|
+
|
|
193
|
+
def _get_mime_type(self, ctx, experiment, run, tag):
|
|
194
|
+
# TODO(@wchargin): Move this call from `/audio` (called many
|
|
195
|
+
# times) to `/tags` (called few times) to reduce data provider
|
|
196
|
+
# calls.
|
|
197
|
+
mapping = self._data_provider.list_blob_sequences(
|
|
198
|
+
ctx,
|
|
199
|
+
experiment_id=experiment,
|
|
200
|
+
plugin_name=metadata.PLUGIN_NAME,
|
|
201
|
+
)
|
|
202
|
+
time_series = mapping.get(run, {}).get(tag, None)
|
|
203
|
+
if time_series is None:
|
|
204
|
+
raise errors.NotFoundError(
|
|
205
|
+
"No audio data for run=%r, tag=%r" % (run, tag)
|
|
206
|
+
)
|
|
207
|
+
parsed = metadata.parse_plugin_metadata(time_series.plugin_content)
|
|
208
|
+
return _MIME_TYPES.get(parsed.encoding, _DEFAULT_MIME_TYPE)
|
|
209
|
+
|
|
210
|
+
@wrappers.Request.application
|
|
211
|
+
def _serve_individual_audio(self, request):
|
|
212
|
+
"""Serve encoded audio data."""
|
|
213
|
+
ctx = plugin_util.context(request.environ)
|
|
214
|
+
experiment = plugin_util.experiment_id(request.environ)
|
|
215
|
+
mime_type = request.args["content_type"]
|
|
216
|
+
if mime_type not in _ALLOWED_MIME_TYPES:
|
|
217
|
+
raise errors.InvalidArgumentError(
|
|
218
|
+
"Illegal mime type %r" % mime_type
|
|
219
|
+
)
|
|
220
|
+
blob_key = request.args["blob_key"]
|
|
221
|
+
data = self._data_provider.read_blob(ctx, blob_key=blob_key)
|
|
222
|
+
return http_util.Respond(request, data, mime_type)
|
|
223
|
+
|
|
224
|
+
@wrappers.Request.application
|
|
225
|
+
def _serve_tags(self, request):
|
|
226
|
+
ctx = plugin_util.context(request.environ)
|
|
227
|
+
experiment = plugin_util.experiment_id(request.environ)
|
|
228
|
+
index = self._index_impl(ctx, experiment)
|
|
229
|
+
return http_util.Respond(request, index, "application/json")
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Internal information about the audio plugin."""
|
|
16
|
+
|
|
17
|
+
from tensorbored.compat.proto import summary_pb2
|
|
18
|
+
from tensorbored.plugins.audio import plugin_data_pb2
|
|
19
|
+
|
|
20
|
+
PLUGIN_NAME = "audio"
|
|
21
|
+
|
|
22
|
+
# The most recent value for the `version` field of the `AudioPluginData`
|
|
23
|
+
# proto.
|
|
24
|
+
PROTO_VERSION = 0
|
|
25
|
+
|
|
26
|
+
# Expose the `Encoding` enum constants.
|
|
27
|
+
Encoding = plugin_data_pb2.AudioPluginData.Encoding
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def create_summary_metadata(
|
|
31
|
+
display_name, description, encoding, *, converted_to_tensor=None
|
|
32
|
+
):
|
|
33
|
+
"""Create a `SummaryMetadata` proto for audio plugin data.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
A `SummaryMetadata` protobuf object.
|
|
37
|
+
"""
|
|
38
|
+
content = plugin_data_pb2.AudioPluginData(
|
|
39
|
+
version=PROTO_VERSION,
|
|
40
|
+
encoding=encoding,
|
|
41
|
+
converted_to_tensor=converted_to_tensor,
|
|
42
|
+
)
|
|
43
|
+
metadata = summary_pb2.SummaryMetadata(
|
|
44
|
+
display_name=display_name,
|
|
45
|
+
summary_description=description,
|
|
46
|
+
plugin_data=summary_pb2.SummaryMetadata.PluginData(
|
|
47
|
+
plugin_name=PLUGIN_NAME, content=content.SerializeToString()
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
return metadata
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def parse_plugin_metadata(content):
|
|
54
|
+
"""Parse summary metadata to a Python object.
|
|
55
|
+
|
|
56
|
+
Arguments:
|
|
57
|
+
content: The `content` field of a `SummaryMetadata` proto
|
|
58
|
+
corresponding to the audio plugin.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
An `AudioPluginData` protobuf object.
|
|
62
|
+
"""
|
|
63
|
+
if not isinstance(content, bytes):
|
|
64
|
+
raise TypeError("Content type must be bytes")
|
|
65
|
+
result = plugin_data_pb2.AudioPluginData.FromString(content)
|
|
66
|
+
if result.version == 0:
|
|
67
|
+
return result
|
|
68
|
+
# No other versions known at this time, so no migrations to do.
|
|
69
|
+
return result
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# source: tensorbored/plugins/audio/plugin_data.proto
|
|
4
|
+
"""Generated protocol buffer code."""
|
|
5
|
+
from google.protobuf import descriptor as _descriptor
|
|
6
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
7
|
+
from google.protobuf import message as _message
|
|
8
|
+
from google.protobuf import reflection as _reflection
|
|
9
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
10
|
+
# @@protoc_insertion_point(imports)
|
|
11
|
+
|
|
12
|
+
_sym_db = _symbol_database.Default()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n+tensorbored/plugins/audio/plugin_data.proto\x12\x0btensorbored\"\x9a\x01\n\x0f\x41udioPluginData\x12\x0f\n\x07version\x18\x01 \x01(\x05\x12\x37\n\x08\x65ncoding\x18\x02 \x01(\x0e\x32%.tensorbored.AudioPluginData.Encoding\x12\x1b\n\x13\x63onverted_to_tensor\x18\x03 \x01(\x08\" \n\x08\x45ncoding\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x07\n\x03WAV\x10\x0b\x62\x06proto3')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_AUDIOPLUGINDATA = DESCRIPTOR.message_types_by_name['AudioPluginData']
|
|
22
|
+
_AUDIOPLUGINDATA_ENCODING = _AUDIOPLUGINDATA.enum_types_by_name['Encoding']
|
|
23
|
+
AudioPluginData = _reflection.GeneratedProtocolMessageType('AudioPluginData', (_message.Message,), {
|
|
24
|
+
'DESCRIPTOR' : _AUDIOPLUGINDATA,
|
|
25
|
+
'__module__' : 'tensorbored.plugins.audio.plugin_data_pb2'
|
|
26
|
+
# @@protoc_insertion_point(class_scope:tensorbored.AudioPluginData)
|
|
27
|
+
})
|
|
28
|
+
_sym_db.RegisterMessage(AudioPluginData)
|
|
29
|
+
|
|
30
|
+
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
31
|
+
|
|
32
|
+
DESCRIPTOR._options = None
|
|
33
|
+
_AUDIOPLUGINDATA._serialized_start=61
|
|
34
|
+
_AUDIOPLUGINDATA._serialized_end=215
|
|
35
|
+
_AUDIOPLUGINDATA_ENCODING._serialized_start=183
|
|
36
|
+
_AUDIOPLUGINDATA_ENCODING._serialized_end=215
|
|
37
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Audio summaries and TensorFlow operations to create them.
|
|
16
|
+
|
|
17
|
+
An audio summary stores a rank-2 string tensor of shape `[k, 2]`, where
|
|
18
|
+
`k` is the number of audio clips recorded in the summary. Each row of
|
|
19
|
+
the tensor is a pair `[encoded_audio, label]`, where `encoded_audio` is
|
|
20
|
+
a binary string whose encoding is specified in the summary metadata, and
|
|
21
|
+
`label` is a UTF-8 encoded Markdown string describing the audio clip.
|
|
22
|
+
|
|
23
|
+
NOTE: This module is in beta, and its API is subject to change, but the
|
|
24
|
+
data that it stores to disk will be supported forever.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import functools
|
|
28
|
+
import warnings
|
|
29
|
+
|
|
30
|
+
import numpy as np
|
|
31
|
+
|
|
32
|
+
from tensorbored.util import encoder as encoder_util
|
|
33
|
+
from tensorbored.plugins.audio import metadata
|
|
34
|
+
from tensorbored.plugins.audio import summary_v2
|
|
35
|
+
|
|
36
|
+
# Export V2 versions.
|
|
37
|
+
audio = summary_v2.audio
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_LABELS_WARNING = (
|
|
41
|
+
"Labels on audio summaries are deprecated and will be removed. "
|
|
42
|
+
"See <https://github.com/tensorflow/tensorboard/issues/3513>."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def op(
|
|
47
|
+
name,
|
|
48
|
+
audio,
|
|
49
|
+
sample_rate,
|
|
50
|
+
labels=None,
|
|
51
|
+
max_outputs=3,
|
|
52
|
+
encoding=None,
|
|
53
|
+
display_name=None,
|
|
54
|
+
description=None,
|
|
55
|
+
collections=None,
|
|
56
|
+
):
|
|
57
|
+
"""Create a legacy audio summary op for use in a TensorFlow graph.
|
|
58
|
+
|
|
59
|
+
Arguments:
|
|
60
|
+
name: A unique name for the generated summary node.
|
|
61
|
+
audio: A `Tensor` representing audio data with shape `[k, t, c]`,
|
|
62
|
+
where `k` is the number of audio clips, `t` is the number of
|
|
63
|
+
frames, and `c` is the number of channels. Elements should be
|
|
64
|
+
floating-point values in `[-1.0, 1.0]`. Any of the dimensions may
|
|
65
|
+
be statically unknown (i.e., `None`).
|
|
66
|
+
sample_rate: An `int` or rank-0 `int32` `Tensor` that represents the
|
|
67
|
+
sample rate, in Hz. Must be positive.
|
|
68
|
+
labels: Deprecated. Do not set.
|
|
69
|
+
max_outputs: Optional `int` or rank-0 integer `Tensor`. At most this
|
|
70
|
+
many audio clips will be emitted at each step. When more than
|
|
71
|
+
`max_outputs` many clips are provided, the first `max_outputs`
|
|
72
|
+
many clips will be used and the rest silently discarded.
|
|
73
|
+
encoding: A constant `str` (not string tensor) indicating the
|
|
74
|
+
desired encoding. You can choose any format you like, as long as
|
|
75
|
+
it's "wav". Please see the "API compatibility note" below.
|
|
76
|
+
display_name: Optional name for this summary in TensorBoard, as a
|
|
77
|
+
constant `str`. Defaults to `name`.
|
|
78
|
+
description: Optional long-form description for this summary, as a
|
|
79
|
+
constant `str`. Markdown is supported. Defaults to empty.
|
|
80
|
+
collections: Optional list of graph collections keys. The new
|
|
81
|
+
summary op is added to these collections. Defaults to
|
|
82
|
+
`[Graph Keys.SUMMARIES]`.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
A TensorFlow summary op.
|
|
86
|
+
|
|
87
|
+
API compatibility note: The default value of the `encoding`
|
|
88
|
+
argument is _not_ guaranteed to remain unchanged across TensorBoard
|
|
89
|
+
versions. In the future, we will by default encode as FLAC instead of
|
|
90
|
+
as WAV. If the specific format is important to you, please provide a
|
|
91
|
+
file format explicitly.
|
|
92
|
+
"""
|
|
93
|
+
if labels is not None:
|
|
94
|
+
warnings.warn(_LABELS_WARNING)
|
|
95
|
+
|
|
96
|
+
# TODO(nickfelt): remove on-demand imports once dep situation is fixed.
|
|
97
|
+
import tensorflow.compat.v1 as tf
|
|
98
|
+
|
|
99
|
+
if display_name is None:
|
|
100
|
+
display_name = name
|
|
101
|
+
if encoding is None:
|
|
102
|
+
encoding = "wav"
|
|
103
|
+
|
|
104
|
+
if encoding == "wav":
|
|
105
|
+
encoding = metadata.Encoding.Value("WAV")
|
|
106
|
+
encoder = functools.partial(
|
|
107
|
+
tf.audio.encode_wav, sample_rate=sample_rate
|
|
108
|
+
)
|
|
109
|
+
else:
|
|
110
|
+
raise ValueError("Unknown encoding: %r" % encoding)
|
|
111
|
+
|
|
112
|
+
with tf.name_scope(name), tf.control_dependencies(
|
|
113
|
+
[tf.assert_rank(audio, 3)]
|
|
114
|
+
):
|
|
115
|
+
limited_audio = audio[:max_outputs]
|
|
116
|
+
encoded_audio = tf.map_fn(
|
|
117
|
+
encoder, limited_audio, dtype=tf.string, name="encode_each_audio"
|
|
118
|
+
)
|
|
119
|
+
if labels is None:
|
|
120
|
+
limited_labels = tf.tile([""], tf.shape(input=limited_audio)[:1])
|
|
121
|
+
else:
|
|
122
|
+
limited_labels = labels[:max_outputs]
|
|
123
|
+
tensor = tf.transpose(a=tf.stack([encoded_audio, limited_labels]))
|
|
124
|
+
summary_metadata = metadata.create_summary_metadata(
|
|
125
|
+
display_name=display_name,
|
|
126
|
+
description=description,
|
|
127
|
+
encoding=encoding,
|
|
128
|
+
)
|
|
129
|
+
return tf.summary.tensor_summary(
|
|
130
|
+
name="audio_summary",
|
|
131
|
+
tensor=tensor,
|
|
132
|
+
collections=collections,
|
|
133
|
+
summary_metadata=summary_metadata,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def pb(
|
|
138
|
+
name,
|
|
139
|
+
audio,
|
|
140
|
+
sample_rate,
|
|
141
|
+
labels=None,
|
|
142
|
+
max_outputs=3,
|
|
143
|
+
encoding=None,
|
|
144
|
+
display_name=None,
|
|
145
|
+
description=None,
|
|
146
|
+
):
|
|
147
|
+
"""Create a legacy audio summary protobuf.
|
|
148
|
+
|
|
149
|
+
This behaves as if you were to create an `op` with the same arguments
|
|
150
|
+
(wrapped with constant tensors where appropriate) and then execute
|
|
151
|
+
that summary op in a TensorFlow session.
|
|
152
|
+
|
|
153
|
+
Arguments:
|
|
154
|
+
name: A unique name for the generated summary node.
|
|
155
|
+
audio: An `np.array` representing audio data with shape `[k, t, c]`,
|
|
156
|
+
where `k` is the number of audio clips, `t` is the number of
|
|
157
|
+
frames, and `c` is the number of channels. Elements should be
|
|
158
|
+
floating-point values in `[-1.0, 1.0]`.
|
|
159
|
+
sample_rate: An `int` that represents the sample rate, in Hz.
|
|
160
|
+
Must be positive.
|
|
161
|
+
labels: Deprecated. Do not set.
|
|
162
|
+
max_outputs: Optional `int`. At most this many audio clips will be
|
|
163
|
+
emitted. When more than `max_outputs` many clips are provided, the
|
|
164
|
+
first `max_outputs` many clips will be used and the rest silently
|
|
165
|
+
discarded.
|
|
166
|
+
encoding: A constant `str` indicating the desired encoding. You
|
|
167
|
+
can choose any format you like, as long as it's "wav". Please see
|
|
168
|
+
the "API compatibility note" below.
|
|
169
|
+
display_name: Optional name for this summary in TensorBoard, as a
|
|
170
|
+
`str`. Defaults to `name`.
|
|
171
|
+
description: Optional long-form description for this summary, as a
|
|
172
|
+
`str`. Markdown is supported. Defaults to empty.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
A `tf.Summary` protobuf object.
|
|
176
|
+
|
|
177
|
+
API compatibility note: The default value of the `encoding`
|
|
178
|
+
argument is _not_ guaranteed to remain unchanged across TensorBoard
|
|
179
|
+
versions. In the future, we will by default encode as FLAC instead of
|
|
180
|
+
as WAV. If the specific format is important to you, please provide a
|
|
181
|
+
file format explicitly.
|
|
182
|
+
"""
|
|
183
|
+
if labels is not None:
|
|
184
|
+
warnings.warn(_LABELS_WARNING)
|
|
185
|
+
|
|
186
|
+
# TODO(nickfelt): remove on-demand imports once dep situation is fixed.
|
|
187
|
+
import tensorflow.compat.v1 as tf
|
|
188
|
+
|
|
189
|
+
audio = np.array(audio)
|
|
190
|
+
if audio.ndim != 3:
|
|
191
|
+
raise ValueError("Shape %r must have rank 3" % (audio.shape,))
|
|
192
|
+
if encoding is None:
|
|
193
|
+
encoding = "wav"
|
|
194
|
+
|
|
195
|
+
if encoding == "wav":
|
|
196
|
+
encoding = metadata.Encoding.Value("WAV")
|
|
197
|
+
encoder = functools.partial(
|
|
198
|
+
encoder_util.encode_wav, samples_per_second=sample_rate
|
|
199
|
+
)
|
|
200
|
+
else:
|
|
201
|
+
raise ValueError("Unknown encoding: %r" % encoding)
|
|
202
|
+
|
|
203
|
+
limited_audio = audio[:max_outputs]
|
|
204
|
+
if labels is None:
|
|
205
|
+
limited_labels = [b""] * len(limited_audio)
|
|
206
|
+
else:
|
|
207
|
+
limited_labels = [
|
|
208
|
+
tf.compat.as_bytes(label) for label in labels[:max_outputs]
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
encoded_audio = [encoder(a) for a in limited_audio]
|
|
212
|
+
content = np.array([encoded_audio, limited_labels]).transpose()
|
|
213
|
+
tensor = tf.make_tensor_proto(content, dtype=tf.string)
|
|
214
|
+
|
|
215
|
+
if display_name is None:
|
|
216
|
+
display_name = name
|
|
217
|
+
summary_metadata = metadata.create_summary_metadata(
|
|
218
|
+
display_name=display_name, description=description, encoding=encoding
|
|
219
|
+
)
|
|
220
|
+
tf_summary_metadata = tf.SummaryMetadata.FromString(
|
|
221
|
+
summary_metadata.SerializeToString()
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
summary = tf.Summary()
|
|
225
|
+
summary.value.add(
|
|
226
|
+
tag="%s/audio_summary" % name,
|
|
227
|
+
metadata=tf_summary_metadata,
|
|
228
|
+
tensor=tensor,
|
|
229
|
+
)
|
|
230
|
+
return summary
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
"""Audio summaries and TensorFlow operations to create them, V2 versions.
|
|
16
|
+
|
|
17
|
+
An audio summary stores a rank-2 string tensor of shape `[k, 2]`, where
|
|
18
|
+
`k` is the number of audio clips recorded in the summary. Each row of
|
|
19
|
+
the tensor is a pair `[encoded_audio, label]`, where `encoded_audio` is
|
|
20
|
+
a binary string whose encoding is specified in the summary metadata, and
|
|
21
|
+
`label` is a UTF-8 encoded Markdown string describing the audio clip.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import functools
|
|
25
|
+
|
|
26
|
+
from tensorbored.compat import tf2 as tf
|
|
27
|
+
from tensorbored.plugins.audio import metadata
|
|
28
|
+
from tensorbored.util import lazy_tensor_creator
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def audio(
|
|
32
|
+
name,
|
|
33
|
+
data,
|
|
34
|
+
sample_rate,
|
|
35
|
+
step=None,
|
|
36
|
+
max_outputs=3,
|
|
37
|
+
encoding=None,
|
|
38
|
+
description=None,
|
|
39
|
+
):
|
|
40
|
+
"""Write an audio summary.
|
|
41
|
+
|
|
42
|
+
Arguments:
|
|
43
|
+
name: A name for this summary. The summary tag used for TensorBoard will
|
|
44
|
+
be this name prefixed by any active name scopes.
|
|
45
|
+
data: A `Tensor` representing audio data with shape `[k, t, c]`,
|
|
46
|
+
where `k` is the number of audio clips, `t` is the number of
|
|
47
|
+
frames, and `c` is the number of channels. Elements should be
|
|
48
|
+
floating-point values in `[-1.0, 1.0]`. Any of the dimensions may
|
|
49
|
+
be statically unknown (i.e., `None`).
|
|
50
|
+
sample_rate: An `int` or rank-0 `int32` `Tensor` that represents the
|
|
51
|
+
sample rate, in Hz. Must be positive.
|
|
52
|
+
step: Explicit `int64`-castable monotonic step value for this summary. If
|
|
53
|
+
omitted, this defaults to `tf.summary.experimental.get_step()`, which must
|
|
54
|
+
not be None.
|
|
55
|
+
max_outputs: Optional `int` or rank-0 integer `Tensor`. At most this
|
|
56
|
+
many audio clips will be emitted at each step. When more than
|
|
57
|
+
`max_outputs` many clips are provided, the first `max_outputs`
|
|
58
|
+
many clips will be used and the rest silently discarded.
|
|
59
|
+
encoding: Optional constant `str` for the desired encoding. Only "wav"
|
|
60
|
+
is currently supported, but this is not guaranteed to remain the
|
|
61
|
+
default, so if you want "wav" in particular, set this explicitly.
|
|
62
|
+
description: Optional long-form description for this summary, as a
|
|
63
|
+
constant `str`. Markdown is supported. Defaults to empty.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
True on success, or false if no summary was emitted because no default
|
|
67
|
+
summary writer was available.
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
ValueError: if a default writer exists, but no step was provided and
|
|
71
|
+
`tf.summary.experimental.get_step()` is None.
|
|
72
|
+
"""
|
|
73
|
+
audio_ops = getattr(tf, "audio", None)
|
|
74
|
+
if audio_ops is None:
|
|
75
|
+
# Fallback for older versions of TF without tf.audio.
|
|
76
|
+
from tensorflow.python.ops import gen_audio_ops as audio_ops
|
|
77
|
+
|
|
78
|
+
if encoding is None:
|
|
79
|
+
encoding = "wav"
|
|
80
|
+
if encoding != "wav":
|
|
81
|
+
raise ValueError("Unknown encoding: %r" % encoding)
|
|
82
|
+
summary_metadata = metadata.create_summary_metadata(
|
|
83
|
+
display_name=None,
|
|
84
|
+
description=description,
|
|
85
|
+
encoding=metadata.Encoding.Value("WAV"),
|
|
86
|
+
)
|
|
87
|
+
inputs = [data, sample_rate, max_outputs, step]
|
|
88
|
+
# TODO(https://github.com/tensorflow/tensorboard/issues/2109): remove fallback
|
|
89
|
+
summary_scope = (
|
|
90
|
+
getattr(tf.summary.experimental, "summary_scope", None)
|
|
91
|
+
or tf.summary.summary_scope
|
|
92
|
+
)
|
|
93
|
+
with summary_scope(name, "audio_summary", values=inputs) as (tag, _):
|
|
94
|
+
# Defer audio encoding preprocessing by passing it as a callable to write(),
|
|
95
|
+
# wrapped in a LazyTensorCreator for backwards compatibility, so that we
|
|
96
|
+
# only do this work when summaries are actually written.
|
|
97
|
+
@lazy_tensor_creator.LazyTensorCreator
|
|
98
|
+
def lazy_tensor():
|
|
99
|
+
tf.debugging.assert_rank(data, 3)
|
|
100
|
+
tf.debugging.assert_non_negative(max_outputs)
|
|
101
|
+
limited_audio = data[:max_outputs]
|
|
102
|
+
encode_fn = functools.partial(
|
|
103
|
+
audio_ops.encode_wav, sample_rate=sample_rate
|
|
104
|
+
)
|
|
105
|
+
encoded_audio = tf.map_fn(
|
|
106
|
+
encode_fn,
|
|
107
|
+
limited_audio,
|
|
108
|
+
dtype=tf.string,
|
|
109
|
+
name="encode_each_audio",
|
|
110
|
+
)
|
|
111
|
+
# Workaround for map_fn returning float dtype for an empty elems input.
|
|
112
|
+
encoded_audio = tf.cond(
|
|
113
|
+
tf.shape(input=encoded_audio)[0] > 0,
|
|
114
|
+
lambda: encoded_audio,
|
|
115
|
+
lambda: tf.constant([], tf.string),
|
|
116
|
+
)
|
|
117
|
+
limited_labels = tf.tile([""], tf.shape(input=limited_audio)[:1])
|
|
118
|
+
return tf.transpose(a=tf.stack([encoded_audio, limited_labels]))
|
|
119
|
+
|
|
120
|
+
# To ensure that audio encoding logic is only executed when summaries
|
|
121
|
+
# are written, we pass callable to `tensor` parameter.
|
|
122
|
+
return tf.summary.write(
|
|
123
|
+
tag=tag, tensor=lazy_tensor, step=step, metadata=summary_metadata
|
|
124
|
+
)
|