{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.simplefilter(action='ignore')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import tensorflow as tf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. 创建计算图并执行" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "area: 48\n" ] } ], "source": [ "width = tf.placeholder('int32', name='width')\n", "height = tf.placeholder('int32', name='height')\n", "area = tf.multiply(width, height, name='area')\n", "\n", "with tf.Session() as sess:\n", " sess.run(tf.global_variables_initializer())\n", " print('area:', sess.run(area, feed_dict={width: 6, height: 8}))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. 将计算图写入log文件, 用于在 TensorBoard 中查看" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "tf.summary.merge_all() # 将所有要显示在 TensorBoard 的数据整合\n", "train_writer = tf.summary.FileWriter('log/graph_area', sess.graph)" ] } ], "metadata": { "kernelspec": { "display_name": "tensorflow-keras-practice", "language": "python", "name": "tensorflow-keras-practice" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }