本文整理匯總了Python中tensorboard.summary.custom_scalar_pb方法的典型用法代碼示例。如果您正苦於以下問題:Python summary.custom_scalar_pb方法的具體用法?Python summary.custom_scalar_pb怎麽用?Python summary.custom_scalar_pb使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorboard.summary
的用法示例。
在下文中一共展示了summary.custom_scalar_pb方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tb_layout
# 需要導入模塊: from tensorboard import summary [as 別名]
# 或者: from tensorboard.summary import custom_scalar_pb [as 別名]
def tb_layout():
episode_rewards = layout_pb2.Category(
title="Episode Reward",
chart=gen_multiline_charts(
[
("Shaped Reward", [r"shaping/eprewmean_true"]),
("Episode Length", [r"eplenmean"]),
("Sparse Reward", [r"shaping/epsparsemean"]),
("Dense Reward", [r"shaping/epdensemean"]),
("Dense Reward Annealing", [r"shaping/rew_anneal_c"]),
("Unshaped Reward", [r"ep_rewmean"]),
("Victim Action Noise", [r"shaping/victim_noise"]),
]
),
)
game_outcome = layout_pb2.Category(
title="Game Outcomes",
chart=gen_multiline_charts(
[
("Agent 0 Win Proportion", [r"game_win0"]),
("Agent 1 Win Proportion", [r"game_win1"]),
("Tie Proportion", [r"game_tie"]),
("# of games", [r"game_total"]),
]
),
)
training = layout_pb2.Category(
title="Training",
chart=gen_multiline_charts(
[
("Policy Loss", [r"policy_loss"]),
("Value Loss", [r"value_loss"]),
("Policy Entropy", [r"policy_entropy"]),
("Explained Variance", [r"explained_variance"]),
("Approx KL", [r"approxkl"]),
("Clip Fraction", [r"clipfrac"]),
]
),
)
# Intentionally unused:
# + serial_timesteps (just total_timesteps / num_envs)
# + time_elapsed (TensorBoard already logs wall-clock time)
# + nupdates (this is already logged as step)
time = layout_pb2.Category(
title="Time",
chart=gen_multiline_charts([("Total Timesteps", [r"total_timesteps"]), ("FPS", [r"fps"])]),
)
categories = [episode_rewards, game_outcome, training, time]
return summary_lib.custom_scalar_pb(layout_pb2.Layout(category=categories))
示例2: finalize_autosummaries
# 需要導入模塊: from tensorboard import summary [as 別名]
# 或者: from tensorboard.summary import custom_scalar_pb [as 別名]
def finalize_autosummaries() -> None:
"""Create the necessary ops to include autosummaries in TensorBoard report.
Note: This should be done only once per graph.
"""
global _finalized
tfutil.assert_tf_initialized()
if _finalized:
return None
_finalized = True
tfutil.init_uninitialized_vars([var for vars_list in _vars.values() for var in vars_list])
# Create summary ops.
with tf.device(None), tf.control_dependencies(None):
for name, vars_list in _vars.items():
name_id = name.replace("/", "_")
with tfutil.absolute_name_scope("Autosummary/" + name_id):
moments = tf.add_n(vars_list)
moments /= moments[0]
with tf.control_dependencies([moments]): # read before resetting
reset_ops = [tf.assign(var, tf.zeros(3, dtype=_dtype)) for var in vars_list]
with tf.name_scope(None), tf.control_dependencies(reset_ops): # reset before reporting
mean = moments[1]
std = tf.sqrt(moments[2] - tf.square(moments[1]))
tf.summary.scalar(name, mean)
tf.summary.scalar("xCustomScalars/" + name + "/margin_lo", mean - std)
tf.summary.scalar("xCustomScalars/" + name + "/margin_hi", mean + std)
# Group by category and chart name.
cat_dict = OrderedDict()
for series_name in sorted(_vars.keys()):
p = series_name.split("/")
cat = p[0] if len(p) >= 2 else ""
chart = "/".join(p[1:-1]) if len(p) >= 3 else p[-1]
if cat not in cat_dict:
cat_dict[cat] = OrderedDict()
if chart not in cat_dict[cat]:
cat_dict[cat][chart] = []
cat_dict[cat][chart].append(series_name)
# Setup custom_scalar layout.
categories = []
for cat_name, chart_dict in cat_dict.items():
charts = []
for chart_name, series_names in chart_dict.items():
series = []
for series_name in series_names:
series.append(layout_pb2.MarginChartContent.Series(
value=series_name,
lower="xCustomScalars/" + series_name + "/margin_lo",
upper="xCustomScalars/" + series_name + "/margin_hi"))
margin = layout_pb2.MarginChartContent(series=series)
charts.append(layout_pb2.Chart(title=chart_name, margin=margin))
categories.append(layout_pb2.Category(title=cat_name, chart=charts))
layout = summary_lib.custom_scalar_pb(layout_pb2.Layout(category=categories))
return layout
示例3: _dump_tensors
# 需要導入模塊: from tensorboard import summary [as 別名]
# 或者: from tensorboard.summary import custom_scalar_pb [as 別名]
def _dump_tensors(self):
if not self._has_recorded_tensor:
return
layout_categories = []
for scope in self._scope_tensor:
chart = []
for name in self._scope_tensor[scope]:
chart.append(
layout_pb2.Chart(
title=name,
multiline=layout_pb2.MultilineChartContent(
tag=[r'name(?!.*margin.*)'.replace('name', name)
])))
category = layout_pb2.Category(title=scope, chart=chart)
layout_categories.append(category)
if layout_categories:
layout_proto_to_write = layout_pb2.Layout(
category=layout_categories)
try:
# Load former layout_proto from self._layout_writer_dir.
multiplexer = event_multiplexer.EventMultiplexer()
multiplexer.AddRunsFromDirectory(self._layout_writer_dir)
multiplexer.Reload()
tensor_events = multiplexer.Tensors(
'.', metadata.CONFIG_SUMMARY_TAG)
shutil.rmtree(self._layout_writer_dir)
# Parse layout proto from disk.
string_array = tf.make_ndarray(tensor_events[0].tensor_proto)
content = np.asscalar(string_array)
layout_proto_from_disk = layout_pb2.Layout()
layout_proto_from_disk.ParseFromString(
tf.compat.as_bytes(content))
# Merge two layout proto.
merged_layout_json = merge(
json_format.MessageToJson(layout_proto_from_disk),
json_format.MessageToJson(layout_proto_to_write))
merged_layout_proto = layout_pb2.Layout()
json_format.Parse(str(merged_layout_json), merged_layout_proto)
self._layout_writer = tf.summary.FileWriter(
self._layout_writer_dir)
layout_summary = summary_lib.custom_scalar_pb(
merged_layout_proto)
self._layout_writer.add_summary(layout_summary)
self._layout_writer.close()
except KeyError:
# Write the current layout proto into disk
# when there is no layout.
self._layout_writer = tf.summary.FileWriter(
self._layout_writer_dir)
layout_summary = summary_lib.custom_scalar_pb(
layout_proto_to_write)
self._layout_writer.add_summary(layout_summary)
self._layout_writer.close()
示例4: finalize_autosummaries
# 需要導入模塊: from tensorboard import summary [as 別名]
# 或者: from tensorboard.summary import custom_scalar_pb [as 別名]
def finalize_autosummaries() -> None:
"""Create the necessary ops to include autosummaries in TensorBoard report.
Note: This should be done only once per graph.
"""
global _finalized
tfutil.assert_tf_initialized()
if _finalized:
return None
_finalized = True
tfutil.init_uninitialized_vars([var for vars_list in _vars.values() for var in vars_list])
# Create summary ops.
with tf.device(None), tf.control_dependencies(None):
for name, vars_list in _vars.items():
name_id = name.replace("/", "_")
with tfutil.absolute_name_scope("Autosummary/" + name_id):
moments = tf.add_n(vars_list)
moments /= moments[0]
with tf.control_dependencies([moments]): # read before resetting
reset_ops = [tf.assign(var, tf.zeros(3, dtype=_dtype)) for var in vars_list]
with tf.name_scope(None), tf.control_dependencies(reset_ops): # reset before reporting
mean = moments[1]
std = tf.sqrt(moments[2] - tf.square(moments[1]))
tf.summary.scalar(name, mean)
if enable_custom_scalars:
tf.summary.scalar("xCustomScalars/" + name + "/margin_lo", mean - std)
tf.summary.scalar("xCustomScalars/" + name + "/margin_hi", mean + std)
# Setup layout for custom scalars.
layout = None
if enable_custom_scalars:
cat_dict = OrderedDict()
for series_name in sorted(_vars.keys()):
p = series_name.split("/")
cat = p[0] if len(p) >= 2 else ""
chart = "/".join(p[1:-1]) if len(p) >= 3 else p[-1]
if cat not in cat_dict:
cat_dict[cat] = OrderedDict()
if chart not in cat_dict[cat]:
cat_dict[cat][chart] = []
cat_dict[cat][chart].append(series_name)
categories = []
for cat_name, chart_dict in cat_dict.items():
charts = []
for chart_name, series_names in chart_dict.items():
series = []
for series_name in series_names:
series.append(layout_pb2.MarginChartContent.Series(
value=series_name,
lower="xCustomScalars/" + series_name + "/margin_lo",
upper="xCustomScalars/" + series_name + "/margin_hi"))
margin = layout_pb2.MarginChartContent(series=series)
charts.append(layout_pb2.Chart(title=chart_name, margin=margin))
categories.append(layout_pb2.Category(title=cat_name, chart=charts))
layout = summary_lib.custom_scalar_pb(layout_pb2.Layout(category=categories))
return layout