首页 > 其他 > 详细

吴裕雄--天生自然深度学习TensorBoard可视化:projector_data_prepare

时间:2019-12-25 19:14:50      阅读:95      评论:0      收藏:0      [点我收藏+]
import os
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

from tensorflow.examples.tutorials.mnist import input_data

%matplotlib inline

LOG_DIR = F:\\temp\\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("F:\\TensorFlowGoogle\\201806-github\\datasets\\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)
plt.imshow(sprite_image,cmap=gray)
技术分享图片
技术分享图片

 

 

技术分享图片

技术分享图片

吴裕雄--天生自然深度学习TensorBoard可视化:projector_data_prepare

原文:https://www.cnblogs.com/tszr/p/12098354.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!