in tfx_airflow/notebooks/tfx_utils.py [0:0]
def display_tensorboard(self, model_id, *other_model_ids):
"""Returns a Tensorboard link for `model_id` and `other_model_ids`.
Args:
model_id: A `int` indicating the id of a `TFXArtifactTypes.MODEL`
artifact.
*other_model_ids: (Optional) A list of `int` indicating the ids of other
`TFXArtifactTypes.MODEL` artifacts to also include in the Tensorboard
invocation for comparison.
"""
model_ids = [model_id] + list(other_model_ids)
model_artifacts = self.metadata_store.get_artifacts_by_id(model_ids)
model_ids_str = '-'.join([str(m) for m in model_ids])
log_file = os.path.join(
os.environ['HOME'],
'tensorboard_model_{}_log.txt'.format(model_ids_str),
)
output_notebook_path = os.path.join(
os.environ['HOME'],
'spawn_tensorboard_{}_output.ipynb'.format(model_ids_str),
)
tensorboard_logdir = ','.join([
'model_{}:{}'.format(m.id, m.uri) for m in model_artifacts
])
pm.execute_notebook(
'spawn_tensorboard.ipynb',
output_notebook_path,
parameters=dict(tb_logdir=tensorboard_logdir, tb_run_log=log_file),
progress_bar=False)
time.sleep(5) # Give it some time for log_filename to be flushed.
with open(log_file) as f:
for l in f:
if 'TensorBoard' in l:
# "TensorBoard 1.12.2 at http://... (Press CTRL+C to quit)"
return l.split(' ')[3]