Tensorflow细节-P309-高维向量可视化
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import os
from tensorflow.examples.tutorials.mnist import input_data
LOG_DIR = 'log'
SPRITE_FILE = 'mnist_sprite.jpg'
META_FIEL = "mnist_meta.tsv"
def create_sprite_image(images):
"""Returns a sprite image consisting of images passed as argument. Images should be count x width x height"""
if isinstance(images, list):
images = np.array(images)
img_h = images.shape[1]
img_w = images.shape[2]
n_plots = int(np.ceil(np.sqrt(images.shape[0]))) # 大图长和宽的值
spriteimage = np.ones((img_h * n_plots, img_w * n_plots)) # 一块白板
for i in range(n_plots):
for j in range(n_plots):
this_filter = i * n_plots + j
if this_filter < images.shape[0]:
this_img = images[this_filter] # 往里填充
spriteimage[i * img_h:(i + 1) * img_h,
j * img_w:(j + 1) * img_w] = this_img
return spriteimage
mnist = input_data.read_data_sets("./MNIST_data", one_hot=False)
to_visualise = 1 - np.reshape(mnist.test.images, (-1, 28, 28)) # 数字由白变黑
sprite_image = create_sprite_image(to_visualise)
path_for_mnist_sprites = os.path.join(LOG_DIR, SPRITE_FILE)
plt.imsave(path_for_mnist_sprites, sprite_image, cmap='gray') # 这里写入的是jpg文件
plt.imshow(sprite_image, cmap='gray')
path_for_mnist_metadata = os.path.join(LOG_DIR, META_FIEL)
with open(path_for_mnist_metadata,'w') as f: # 这里写入的是tsv文件
f.write("Index\tLabel\n")
for index,label in enumerate(mnist.test.labels):
f.write("%d\t%d\n" % (index,label))
Tensorflow细节-P309-高维向量可视化的更多相关文章
- Tensorboard教程:高维向量可视化
Tensorflow高维向量可视化 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 强烈推荐Tensorflow实战Google深度学习框架 实验平台: Tensorflow1.4. ...
- Tensorflow细节-P309-监控指标可视化
注意下面一个点就ok了 with tf.name_scope('input_reshape'): # 注意看这里,图片的生成 image_shaped_input = tf.reshape(x, [- ...
- 词向量可视化--[tensorflow , python]
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ---------------------------------- ...
- Tensorflow细节-Tensorboard可视化-简介
先搞点基础的 注意注意注意,这里虽然很基础,但是代码应注意: 1.从writer开始后边就错开了 2.writer后可以直接接writer.close,也就是说可以: writer = tf.summ ...
- Tensorflow 搭建神经网络及tensorboard可视化
1. session对话控制 matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([[2],[2]]) product = tf.matmul(m ...
- 超简单tensorflow入门优化程序&&tensorboard可视化
程序1 任务描述: x = 3.0, y = 100.0, 运算公式 x×W+b = y,求 W和b的最优解. 使用tensorflow编程实现: #-*- coding: utf-8 -*-) im ...
- Tensorflow细节-P312-PROJECTOR
首先进行数据预处理,需要生成.tsv..jpg文件 import matplotlib.pyplot as plt import numpy as np import os from tensorfl ...
- TensorFlow基础笔记(9) Tensorboard可视化显示以及查看pb meta模型文件的方法
参考: http://blog.csdn.net/l18930738887/article/details/55000008 http://www.jianshu.com/p/19bb60b52dad ...
- Tensorflow细节-P319-使用GPU基本的操作
如果什么都不加,直接运行装了GPU的Tensorflow,结果是这样子的 import tensorflow as tf a = tf.constant([1.0, 2.0, 3.0], shape= ...
随机推荐
- Python之颜色的表示
字背景颜色范围:40----49 40:黑 41:深红 42:绿 43:黄色 44:蓝色 45:紫色 46:深绿 47:白色 字颜色:30-----------39 30:黑 31:红 32:绿 33 ...
- C++ 二叉搜索树原理及其实现
首先是概念:二叉搜索树又称二叉排序树,它具有以下的性质: 若是左子树不为空,则左子树上所有节点的值小于根节点的值 若是右子树不为空,则右子树上所有结点的值大于根节点的值 二叉搜索树的左右子树也是二叉搜 ...
- 「UR#5」怎样跑得更快
「UR#5」怎样跑得更快 膜这个您就会了 下面是复读机mangoyang 我们要求 \[ \sum_{j=1}^n \gcd(i,j)^{c-d} j^d x_j=\frac{b_i}{i^d} \] ...
- sudo apt-get install libstdc++6
sudo apt-get install libstdc++6 yum install libncurses.so.5 sudo apt-get install libncurses.so.5 su ...
- MVC中根据后台绝对路径读取图片并显示在IMG中
数据库存取图片并在MVC3中显示在View中 根据路径读取图片: byte[] img = System.IO.File.ReadAllBytes(@"d:\xxxx.jpg"); ...
- 矩量母函数(Moment Generating Function,mgf,又称:动差生成函数)
在统计学中,矩又被称为动差(Moment).矩量母函数(Moment Generating Function,简称mgf)又被称为动差生成函数. 称exp(tξ)的数学期望为随机变量ξ的矩量母函数,记 ...
- Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现
Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现 一丶进程基础知识 什么是程序: 程序就是一堆文件 什么是进程: 进程就是一个正在 ...
- 【MySQL】数据库中间件Atlas
1.介绍 Atlas 是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上,修改 ...
- 【转载】华为荣耀V9手机如何设置WiFi热点共享
有时候我们在电脑的时候发现没有无线网络以及有线网络,如果你的手机有相应网络,并且流量足够(当前很多手机流量套餐都是不限量了),可以开启手机上的Wifi热点进行流量共享使用,开启Wifi流量热点后,电脑 ...
- UAVCAN DSDL介绍
原文:http://uavcan.org/Specification/3._Data_structure_description_language/ DSDL:Data structure descr ...