TensorFlow学习笔记(6):TensorBoard之Embeddings
本文基于TensorFlow官网的How-Tos写成。
TensorBoard是TensorFlow自带的一个可视化工具,Embeddings是其中的一个功能,用于在二维或三维空间对高维数据进行探索。
An embedding is a map from input data to points in Euclidean space.
本文使用MNIST数据讲解Embeddings的使用方法。
代码
# -*- coding: utf-8 -*-
# @author: 陈水平
# @date: 2017-02-08
# @description: hello world program to set up embedding projector in TensorBoard based on MNIST
# @ref: http://yann.lecun.com/exdb/mnist/, https://www.90168.org/images/mnist_10k_sprite.png
#
import numpy as np
import tensorflow as tf
from tensorflow.contrib.tensorboard.plugins import projector
from tensorflow.examples.tutorials.mnist import input_data
import os
PATH_TO_MNIST_DATA = "MNIST_data"
LOG_DIR = "log"
IMAGE_NUM = 10000
# Read in MNIST data by utility functions provided by TensorFlow
mnist = input_data.read_data_sets(PATH_TO_MNIST_DATA, one_hot=False)
# Extract target MNIST image data
plot_array = mnist.test.images[:IMAGE_NUM] # shape: (n_observations, n_features)
# Generate meta data
np.savetxt(os.path.join(LOG_DIR, 'metadata.tsv'),www.90168.org mnist.test.labels[:IMAGE_NUM], fmt='%d')
# Download sprite image
# https://www.tensorflow.org/images/mnist_10k_sprite.png, 100x100 thumbnails
PATH_TO_SPRITE_IMAGE = os.path.join(LOG_DIR, 'mnist_10k_sprite.png')
# To visualise your embeddings, there are 3 things you need to do:
# 1) Setup a 2D tensor variable(s) that holds your embedding(s)
session = tf.InteractiveSession()
embedding_var = tf.Variable(plot_array, name='embedding')
tf.global_variables_initializer().run()
# 2) Periodically save your embeddings in a LOG_DIR
# Here we just save the Tensor once, so we set global_step to a fixed number
saver = tf.train.Saver()
saver.save(session, os.path.join(LOG_DIR, "model.ckpt"), global_step=0)
# 3) Associate metadata and sprite image with your embedding
# Use the same LOG_DIR where you stored your checkpoint.
summary_writer = tf.summary.FileWriter(LOG_DIR)
config = projector.ProjectorConfig()
# You can add multiple embeddings. Here we add only one.
embedding = config.embeddings.add()
embedding.tensor_name = embedding_var.name
# Link this tensor to its metadata file (e.g. labels).
embedding.metadata_path = os.path.join(LOG_DIR, 'metadata.tsv')
# Link this tensor to its sprite image.
embedding.sprite.image_path = PATH_TO_SPRITE_IMAGE
embedding.sprite.single_image_dim.extend([28, 28])
# Saves a configuration file that TensorBoard will read during startup.
projector.visualize_embeddings(summary_writer, config)
首先,从这里下载图片,放到log目录下;然后执行上述代码;最后,执行下面的命令启动TensorBoard。
tensorboard --logdir=log
执行后,命令行会显示如下提示信息:
Starting TensorBoard 39 on port 6006
(You can navigate to http://xx.xxx.xx.xxx:6006)
打开浏览器,输入上面的链接地址,点击导航栏的EMBEDDINGS即可看到效果:
资源
TensorFlow学习笔记(6):TensorBoard之Embeddings的更多相关文章
- Tensorflow学习笔记2019.01.03
tensorflow学习笔记: 3.2 Tensorflow中定义数据流图 张量知识矩阵的一个超集. 超集:如果一个集合S2中的每一个元素都在集合S1中,且集合S1中可能包含S2中没有的元素,则集合S ...
- tensorflow学习笔记——使用TensorFlow操作MNIST数据(2)
tensorflow学习笔记——使用TensorFlow操作MNIST数据(1) 一:神经网络知识点整理 1.1,多层:使用多层权重,例如多层全连接方式 以下定义了三个隐藏层的全连接方式的神经网络样例 ...
- tensorflow学习笔记——使用TensorFlow操作MNIST数据(1)
续集请点击我:tensorflow学习笔记——使用TensorFlow操作MNIST数据(2) 本节开始学习使用tensorflow教程,当然从最简单的MNIST开始.这怎么说呢,就好比编程入门有He ...
- Tensorflow学习笔记2:About Session, Graph, Operation and Tensor
简介 上一篇笔记:Tensorflow学习笔记1:Get Started 我们谈到Tensorflow是基于图(Graph)的计算系统.而图的节点则是由操作(Operation)来构成的,而图的各个节 ...
- Tensorflow学习笔记2019.01.22
tensorflow学习笔记2 edit by Strangewx 2019.01.04 4.1 机器学习基础 4.1.1 一般结构: 初始化模型参数:通常随机赋值,简单模型赋值0 训练数据:一般打乱 ...
- TensorFlow学习笔记之--[compute_gradients和apply_gradients原理浅析]
I optimizer.minimize(loss, var_list) 我们都知道,TensorFlow为我们提供了丰富的优化函数,例如GradientDescentOptimizer.这个方法会自 ...
- 深度学习-tensorflow学习笔记(1)-MNIST手写字体识别预备知识
深度学习-tensorflow学习笔记(1)-MNIST手写字体识别预备知识 在tf第一个例子的时候需要很多预备知识. tf基本知识 香农熵 交叉熵代价函数cross-entropy 卷积神经网络 s ...
- 深度学习-tensorflow学习笔记(2)-MNIST手写字体识别
深度学习-tensorflow学习笔记(2)-MNIST手写字体识别超级详细版 这是tf入门的第一个例子.minst应该是内置的数据集. 前置知识在学习笔记(1)里面讲过了 这里直接上代码 # -*- ...
- tensorflow学习笔记(4)-学习率
tensorflow学习笔记(4)-学习率 首先学习率如下图 所以在实际运用中我们会使用指数衰减的学习率 在tf中有这样一个函数 tf.train.exponential_decay(learning ...
- tensorflow学习笔记(3)前置数学知识
tensorflow学习笔记(3)前置数学知识 首先是神经元的模型 接下来是激励函数 神经网络的复杂度计算 层数:隐藏层+输出层 总参数=总的w+b 下图为2层 如下图 w为3*4+4个 b为4* ...
随机推荐
- 以后要进行数据收集,打开邮箱就行了 | formtalk入驻Office 应用商店
『数据收集』,作为一项工作,存在感高的忽视不了——不管你在企业里是什么角色(大部分),Ta似乎都在你的工作范围内. 你是人事:收集招聘数据.员工信息: 你是采购:收集供应商信息.商品数据: 你是市场: ...
- python基础教程总结14——测试
1. 先测试,后编码 对程序的各个部分建立测试也是非常重要的(这也称为单元测试).测试驱动编程:Test-driven programming 1)精确的需求说明: 程序设计的理念是以编写测试程序开始 ...
- Oracle 11g 新特性 – HM(Hang Manager)简介
在这篇文章中我们会对oracle 11g 新特性—hang 管理器(Hang Manager) 进行介绍.我们需要说明,HM 只在RAC 数据库中存在. 在我们诊断数据库问题的时候,经常会遇到一些数据 ...
- Android开发出现 StackOverflowError
问题:StackOverflowError 在HTC或者摩托罗拉的手机上测试出现 StackOverflowError 的错误. 06-12 10:28:31.750: E/AndroidRuntim ...
- 查看numpy的类型
查看一个变量的类型:type(img) 查看array中的数据值的类型:img.dtype 查看array的形状:img.shape
- leetcode 179. Largest Number 、剑指offer33 把数组排成最小的数
这两个题几乎是一样的,只是leetcode的题是排成最大的数,剑指的题是排成最小的 179. Largest Number a.需要将数组的数转换成字符串,然后再根据大小排序,这里使用to_strin ...
- 实验1 c语言最基本内容
part 1 验证性内容 总结:经受了数组和结构体的双重折磨后,发现这部分好简单...现在没啥问题了... part 2 补全程序 1.判断奇偶 // 程序功能: // 要求用户从键盘输入一个整数 ...
- Mysql查询指定用户并列排名 类似rank函数
SELECT total.* FROM ( SELECT obj.uid, obj.score, CASE WHEN @rowtotal = obj.score THEN @rownum WHEN @ ...
- javaweb基础(3)_tomcat下部署项目
一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:
- JDBC连接数据库报错:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. ......
问题:Java程序使用JDBC连接MySQL数据库时,控制台报错如下: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' ...