<jupyter_start><jupyter_text>Use TI SDK For Tensorboard 本例通过Mnist例子介绍TI SDK如何使用Tensorboard查看Tensorflow的训练模型  下载训练数据<jupyter_code>from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf

train_data_path = 'train-data'
data_sets = input_data.read_data_sets('train-data', dtype=tf.uint8, reshape=False, validation_size=5000)<jupyter_output><empty_output><jupyter_text>cos训练数据上传<jupyter_code>from ti import session
ti_session = session.Session()
inputs = ti_session.upload_data(path=train_data_path, key_prefix="train-data/mnist")<jupyter_output><empty_output><jupyter_text>Tensorboard模式 1. 您可在训练任务fit函数中传入参数run_tensorboard_locally，该值为True时，TI SDK将会在提交环境中启动Tensorboard服务；2. 您的训练代码需要处理Tensorflow检查点逻辑，写入到/opt/ml/checkpoints/目录中；TI SDK后台将会自动同步/opt/ml/checkpoints/至cos://{training_bucket}/{training_job_name}/output/checkpoints；其中{training_bucket}和{training_job_name}分别为训练任务的cos桶名称和任务名称；3. Tensorboard服务默认监听端口为6006，若6006端口不可用时，将会以此从端口6007至端口6105范围尝试可用端口，您可在训练日志输出查看Tensorboard服务端口port；4. 若提交环境为Notebook环境时，您可通过浏览器中输入域名 https://{notebook_url}/proxy/port/ ，其中{notebook_url}为您的notebook域名，即Notebook的域名后加入后缀/proxy/port/访问Tensorboard服务；5. 若提交环境为本地环境时，您可通过浏览器中输入本机域名 http://localhost:port ，访问Tensorboard服务；  训练任务提交<jupyter_code>from __future__ import absolute_import, print_function

import sys
from ti import session
from ti.tensorflow import TensorFlow

# 初始化
ti_session = session.Session()
hyperparameters = {'train-steps': 5000}

# 创建一个Tensorflow Estimator
tf_estimator = TensorFlow(role="TIONE_QCSRole",
                          train_instance_count=1,
                          train_instance_type='TI.SMALL2.1core2g',
                          py_version='py3',
                          script_mode=True,
                          hyperparameters=hyperparameters,
                          framework_version='1.14.0',
                          entry_point='tf_mnist.py',
                          source_dir='code')

# 提交Tensorflow训练任务，并使用tensorboard模式
tf_estimator.fit(inputs, run_tensorboard_locally=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08887809616318601, 'fraction_numerical': 0.01894123360854784, 'mean_word_length': 4.868945868945869, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '220965', 'license': 'Apache-2.0', 'n_tokens_mistral': 861, 'n_tokens_neox': 928, 'n_words': 78, 'path': 'ti_python_sdk/use_tensorboard/use_tensorboard.ipynb', 'repo_name': 'mengsuix/tencent-ti-examples', 'size': '2059'}