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= ...
随机推荐
- Linux下signal信号汇总
SIGHUP /* Hangup (POSIX). */ 终止进程 终端线路挂断 SIGINT /* Interrupt (ANSI). */ 终止进程 中断进程 Ctrl+C SIGQUIT /* ...
- es常用操作
1.查看所有索引 _cat/indices?v 2.删除索引 DELETE my_index 3.查询缓存 curl /my_index/_search?request_cache=true' -d' ...
- 从损失函数优化角度:讨论“线性回归(linear regression)”与”线性分类(linear classification)“的联系与区别
1. 主要观点 线性模型是线性回归和线性分类的基础 线性回归和线性分类模型的差异主要在于损失函数形式上,我们可以将其看做是线性模型在多维空间中“不同方向”和“不同位置”的两种表现形式 损失函数是一种优 ...
- 《JAVA高并发编程详解》-volatile和synchronized
- 2019 58同城java面试笔试题 (含面试题解析)
本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.58同城等公司offer,岗位是Java后端开发,最终选择去了58同城. 面试了很多家公司,感觉大部分公司考察的点 ...
- kafka汇总
Kafka 1. kafka概念 kafka是一个高吞吐亮的.分布式.基于发布/订阅(也就是一对多)的消息系统,最初由Linkedln公司开发的,使用Scala语言编写的,目前是Apache的开源项目 ...
- Matlab装饰模式
装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.根据https://www.runoob.com/design-pattern/decorator ...
- springboot多环境下maven打包
前言: 最近在项目中使用springboot时发现,采用在pom中定义不同的profile,并且maven打包时 采用-P参数并不能替换我application.properties文件中指定占位符的 ...
- tmp-scmj
1.apk下载 http://app6.wpf2x4.cn/?downloadfrom=sichuan 麻将图: Big_mahjonghn_tiles_sr.png
- iview input绑定enter事件
在使用iview Input组件是,需要enter粗发相关的请求事件,但是在Input组件内不起效果: <Input placeholder="请输入查询信息" style= ...