zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然深度学习TensorBoard可视化:projector_data_prepare

    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')

  • 相关阅读:
    计算某一日期是在一年中第几周
    动态生成web表-asp.net table
    sql server 小技巧(7) 导出完整sql server 数据库成一个sql文件,包含表结构及数据
    循环取月的三位英语名 Jan Feb
    Python面向对象编程
    算法
    UDP Sockets in C#
    C++ 11
    GNU Make
    C++ 11
  • 原文地址:https://www.cnblogs.com/tszr/p/12098354.html
Copyright © 2011-2022 走看看