tensorflow 1.14 的 demo 02 —— tensorboard 远程访问

tensorflow 1.14.0, 提供远程访问 tensorboard 服务的方法

第一步生成 events 文件:

在上一篇demo的基础上加了一句,如下,

 tf.summary.FileWriter("./tmp/summary", graph=sess1.graph)

hello_tensorboard_remote.py

import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'def tf114_demo():a = 3b = 4c = a + bprint("a + b in py =",c)a_t = tf.constant(3)b_t = tf.constant(4)c_t = a_t + b_tprint("TensorFlow add a_t + b_t =", c_t)with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value= ", c_t_value)return Nonedef graph_demo():a_t = tf.constant(3)b_t = tf.constant(4)c_t = a_t + b_tprint("TensorFlow add a_t + b_t =", c_t)default_g = tf.get_default_graph()print("default_g:\n",default_g)print("a_t g:", a_t.graph)print("c_t g:", c_t.graph)with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value= ", c_t_value)print("sess g:", sess.graph)new_g = tf.Graph()with new_g.as_default():a_new = tf.constant(20)b_new = tf.constant(30)c_new = a_new + b_newprint("c_new:", c_new)print("a_new g:",a_new.graph)print("b_new g:",c_new.graph)with tf.Session() as sess1:c_t_value = sess1.run(c_t)
#               print("c_new_value:", c_new_value)print("sess1 g:", sess1.graph)tf.summary.FileWriter("./tmp/summary", graph=sess1.graph)with tf.Session(graph=new_g) as new_sess:c_new_value = new_sess.run((c_new))print("c_new_value:", c_new_value)print("new_sess graph properties:", new_sess.graph)
#               return Noneif __name__ == "__main__":
#       tf114_demo()graph_demo()

运行 tensorflow1 的 app:

python3 hello_tensorboard_remote.py

ls ./tmp/summary/ 

启动 tensorboard 网络服务:

tensorboard --logdir="./tmp/summary" --port 6789

6789是自己选定的端口号,尝试任选;

运行状态如下:

远程访问tensorboard:

在同一个网络内的主机网页浏览器的地址栏中输入:

http://10.208.14.37:6789

效果如下,显示出来了示例中非常简单的一个计算图:

如果是本机访问,则在地址栏里输入

http://127.0.0.1:6006

demo03 convolutional_network_raw.py

tf.summary.FileWriter("./tmp/summary", graph=sess.graph)

""" Convolutional Neural Network.Build and train a convolutional neural network with TensorFlow.
This example is using the MNIST database of handwritten digits
(http://yann.lecun.com/exdb/mnist/)Author: Aymeric Damien
Project: https://github.com/aymericdamien/TensorFlow-Examples/
"""from __future__ import division, print_function, absolute_importimport tensorflow as tf# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)# Training Parameters
learning_rate = 0.001
num_steps = 200
batch_size = 128
display_step = 10# Network Parameters
num_input = 784 # MNIST data input (img shape: 28*28)
num_classes = 10 # MNIST total classes (0-9 digits)
dropout = 0.75 # Dropout, probability to keep units# tf Graph input
X = tf.placeholder(tf.float32, [None, num_input])
Y = tf.placeholder(tf.float32, [None, num_classes])
keep_prob = tf.placeholder(tf.float32) # dropout (keep probability)# Create some wrappers for simplicity
def conv2d(x, W, b, strides=1):# Conv2D wrapper, with bias and relu activationx = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME')x = tf.nn.bias_add(x, b)return tf.nn.relu(x)def maxpool2d(x, k=2):# MaxPool2D wrapperreturn tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1],padding='SAME')# Create model
def conv_net(x, weights, biases, dropout):# MNIST data input is a 1-D vector of 784 features (28*28 pixels)# Reshape to match picture format [Height x Width x Channel]# Tensor input become 4-D: [Batch Size, Height, Width, Channel]x = tf.reshape(x, shape=[-1, 28, 28, 1])# Convolution Layerconv1 = conv2d(x, weights['wc1'], biases['bc1'])# Max Pooling (down-sampling)conv1 = maxpool2d(conv1, k=2)# Convolution Layerconv2 = conv2d(conv1, weights['wc2'], biases['bc2'])# Max Pooling (down-sampling)conv2 = maxpool2d(conv2, k=2)# Fully connected layer# Reshape conv2 output to fit fully connected layer inputfc1 = tf.reshape(conv2, [-1, weights['wd1'].get_shape().as_list()[0]])fc1 = tf.add(tf.matmul(fc1, weights['wd1']), biases['bd1'])fc1 = tf.nn.relu(fc1)# Apply Dropoutfc1 = tf.nn.dropout(fc1, dropout)# Output, class predictionout = tf.add(tf.matmul(fc1, weights['out']), biases['out'])return out# Store layers weight & bias
weights = {# 5x5 conv, 1 input, 32 outputs'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32])),# 5x5 conv, 32 inputs, 64 outputs'wc2': tf.Variable(tf.random_normal([5, 5, 32, 64])),# fully connected, 7*7*64 inputs, 1024 outputs'wd1': tf.Variable(tf.random_normal([7*7*64, 1024])),# 1024 inputs, 10 outputs (class prediction)'out': tf.Variable(tf.random_normal([1024, num_classes]))
}biases = {'bc1': tf.Variable(tf.random_normal([32])),'bc2': tf.Variable(tf.random_normal([64])),'bd1': tf.Variable(tf.random_normal([1024])),'out': tf.Variable(tf.random_normal([num_classes]))
}# Construct model
logits = conv_net(X, weights, biases, keep_prob)
prediction = tf.nn.softmax(logits)# Define loss and optimizer
loss_op = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)
train_op = optimizer.minimize(loss_op)# Evaluate model
correct_pred = tf.equal(tf.argmax(prediction, 1), tf.argmax(Y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))# Initialize the variables (i.e. assign their default value)
init = tf.global_variables_initializer()# Start training
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True)) as sess:# Run the initializersess.run(init)for step in range(1, num_steps+1):batch_x, batch_y = mnist.train.next_batch(batch_size)# Run optimization op (backprop)sess.run(train_op, feed_dict={X: batch_x, Y: batch_y, keep_prob: 0.8})if step % display_step == 0 or step == 1:# Calculate batch loss and accuracyloss, acc = sess.run([loss_op, accuracy], feed_dict={X: batch_x,Y: batch_y,keep_prob: 1.0})print("Step " + str(step) + ", Minibatch Loss= " + \"{:.4f}".format(loss) + ", Training Accuracy= " + \"{:.3f}".format(acc))print("Optimization Finished!")# Calculate accuracy for 256 MNIST test imagesprint("Testing Accuracy:", \sess.run(accuracy, feed_dict={X: mnist.test.images[:256],Y: mnist.test.labels[:256],keep_prob: 1.0}))tf.summary.FileWriter("./tmp/summary", graph=sess.graph)

$ python3 convolutional_network_raw.py

另一台网内的机器上访问结果:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/34524.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

PG常用SQL

数据库 创建数据库 PostgreSQL 创建数据库可以用以下三种方式: 1、使用 CREATE DATABASE SQL 语句来创建。2、使用 createdb 命令来创建。3、使用 pgAdmin 工具。 CREATE DATABASE 创建数据库 CREATE DATABASE 命令需要在 PostgreSQL 命令窗口来执行&#xff0…

【数据结构】哈希表

总结自代码随想录 哈希表的原理: 对象通过HashCode()函数会返回一个int值;将int值与HashTable的长度取余,该余数就是该对象在哈希表中的下标。

Delta动态对冲

Delta动态对冲 1.前言 期权交易有四种基本交易方式:买入看涨期权、卖出看涨期权、买入看跌期权和卖出看跌期权。通过四种基本交易方式与不同行权价期权的结合又能衍生出各种各样的垂直价差组合、跨式组合、宽跨式组合等等组合。而无论期权组合的配置多么复杂,其最基本的属性…

python ffmpeg合并ts文件

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家:点击跳转 当你从网站下载了一集动漫,然后发现是一堆ts文件,虽然可以打开,但是某个都是10秒左右,…

编写一个函数,将参数字符串反向排列(C语言递归实现)

比如&#xff1a;char arr[ ]"abcdef";逆序之后数组的内容变成&#xff1a;fedcba a b c d e f \0 1.交换a和f 2.逆序中间的bcde 1.交换b和e 2.逆序中间的cd 1.交换c和d 2.c和d之间有一个元素或者没有元素就停止 #include <string.h> void Reverse(char* ps) {…

代码随想录第46天 | 139. 单词拆分、多重背包

139. 单词拆分 确定dp数组以及下标的含义 dp[i] : 字符串长度为i的话&#xff0c;dp[i]为true&#xff0c;表示可以拆分为一个或多个在字典中出现的单词。 确定递推公式 如果确定dp[j] 是true&#xff0c;且 [j, i] 这个区间的子串出现在字典里&#xff0c;那么dp[i]一定是tru…

智安网络|恶意软件在网络安全中的危害与应对策略

恶意软件是指一类具有恶意目的的软件程序&#xff0c;恶意软件是网络安全领域中的一个严重威胁&#xff0c;给个人用户、企业和整个网络生态带来巨大的危害。通过潜伏于合法软件、邮件附件、下载链接等途径传播&#xff0c;破坏用户计算机系统、窃取敏感信息、进行勒索等不法行…

什么是DNS的递归查询和迭代查询?

在 DNS 查询中&#xff0c;有两种主要的查询方式&#xff1a;递归查询和迭代查询。它们的工作方式和关系如下&#xff1a; 递归查询 (Recursive Query)&#xff1a; 当一个客户端&#xff08;例如你的电脑或手机&#xff09;向 DNS 服务器&#xff08;通常是你的本地 DNS 服务器…

centos7 安装 docker 不能看菜鸟教程的 docker 安装,有坑

特别注意 不能看菜鸟教程的 docker 安装&#xff0c;有坑 如果机器不能直接上网&#xff0c;先配置 yum 代理 proxyhttp://172.16.0.11:8443 配置文件修改后即刻生效&#xff0c;再执行 yum install 等命令&#xff0c;就可以正常安装软件了。 参考 https://blog.csdn.net/c…

docker desktop搭建 nginx

【docker 桌面版】windows 使用 docker 搭建 nginx 拉取 nginx 镜像 docker pull nginx运行容器 docker run -d -p 80:8081 --name nginx nginx本地磁盘创建 nginx 目录 D:\DockerRep\nginx复制 docker 中的 nginx 配置文件 查看运行的容器 docker ps -a docker cp 9f0f82d66dd…

最新版高效多元化广告联盟系统源码,实时监控移动广告联盟,支持多种广告效果

诚丰广告联盟系统是一款强大的广告联盟解决方案&#xff0c;旨在提高网站在百度搜索引擎中的排名和可见性。我们的系统具有以下特点&#xff1a; 1. 高负载能力&#xff1a;我们的服务器每天能够承载至少200万个PV流量&#xff0c;保证您的网站能够稳定运行&#xff0c;并提供…

MySQL8安装教程 保姆级(Windows))

下载 官网: mysql官网点击Downloads->MySQL Community(GPL) Downloads->MySQL Community Server(或者点击MySQL installer for Windows) Windows下有两种安装方式 在线安装 一般带有 web字样 这个需要联网离线安装 一般没有web字样 安装 下载好之后,版本号可以不一样&…

uniapp----分包

系列文章目录 uniapp-----封装接口 uniapp-----分包 目录 系列文章目录 uniapp-----封装接口 uniapp-----分包 前言 二、使用步骤 1.创建文件 ​编辑 2.min.js的修改 2.1 subPackages 代码如下&#xff08;示例&#xff09;&#xff1a; 2.2 preloadRule 代码如下&am…

QT之时钟

QT之时钟 会用到一个时间类:qtime 定时类:qtimer #------------------------------------------------- # # Project created by QtCreator 2023-08-13T10:49:31 # #-------------------------------------------------QT += core guigreaterThan(QT_MAJOR_VERSION,…

【HBZ分享】ES的评分score机制的原理

score类型 基础评分boost&#xff0c;默认2.2&#xff0c;逆向文档频率值(IDF)&#xff1a;表示该词再文档中(ES中)出现的次数越多&#xff0c;表示越不重要&#xff0c;评分越低关键词在文档中出现的频率(TF)&#xff1a;表示该词在文档中出现的频率&#xff0c;频率越高表示…

开发工具Eclipse的使用

&#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 接下来看看由辉辉所写的关于Eclipse使用的相关操作吧 目录 &#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 一.Eclipse是什么 二.使用Eclipse的…

09-1_Qt 5.9 C++开发指南_Qchart概述

Qt Charts 可以很方便地绘制常见的折线图、柱状图、饼图等图表&#xff0c;不用自己耗费时间和精力开发绘图组件或使用第三方组件了。 本章首先介绍 Qt Charts 的基本特点和功能&#xff0c;以画折线图为例详细说明 Qt Charts 各主要部件的操作方法&#xff0c;再介绍各种常用…

分布式数据库设计

1、分库分表 为解决单库存储数据量太大导致的操作数据库效率问题&#xff0c;一般采用的是分库分表的方式。 分库&#xff1a;即将原本存储在一个库的数据分布到多个库中。 分表&#xff1a;即将原本存储在一个表的数据按照业务特性或数据特性进行拆分&#xff0c;将数据拆分到…

git unable to get local issuer certificate (_ssl.c:1007)>

原因1&#xff1a;Git无法验证SSL证书 这个错误通常是由于Git无法验证SSL证书导致的。您可以尝试以下方法解决此问题&#xff1a; 确认您的计算机上是否安装了正确的SSL证书。如果没有&#xff0c;请下载并安装它们。您可以使用以下命令在Mac上安装SSL证书&#xff1a; brew…

使用maven打包时如何跳过test,有三种方式

方式一 针对spring项目&#xff1a; <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> …