• MNIST数据可视化


    一、数据准备

    image

    二、数据说明

    image

    image

    可以看出图片数据在偏移量为第16字节开始存,每28X28字节存放一张手写字图片。而label是从偏移量为第8字节开始存,每个字节存放一个label。

    三、matlab2016实现可视化

    在数据同目录下新建show_mnist_data.m

    clc;
    clear;
    close all;
    image_file_name='t10k-images-idx3-ubyte';
    index_file_name='t10k-labels-idx1-ubyte';
    
    fid1=fopen(image_file_name,'rb');
    fid2=fopen(index_file_name,'rb');
    
    image_data=fread(fid1,'uint8');
    index_data=fread(fid2,'uint8');
    
    fclose(fid1);
    fclose(fid2);
    
    image_data=image_data(17:end);
    index_data=index_data(9:end);
    image_buffer=zeros(28,28);
    
    for k=1:100:length(image_data)/28/28
        figure(100);
        for t=1:100
            image_buffer=reshape(image_data((k+t-2)*28*28+1:(k+t-1)*28*28),28,28);
            subplot(10,10,t);
            imshow(uint8(image_buffer)');
            title(num2str(index_data(k+t-1)));
        end
        pause;
    end

    效果:

    image

    说明:

    1、因为matlab数组元素下标是从1开始的,所以图片从第17字节开始,label从第9字节开始存。

    2、reshape操作,重新定义了数组的形状,重新定义的形状按列的方向开始存,从上到下,再从左到右存,所以imshow图片的时候,要对图片进行转置才能正常显示。

  • 相关阅读:
    外部存储 使用详解
    内部存储 使用详解
    SQLite 使用详解
    SharePerference 使用详解
    Preference 使用详解
    Notification 使用详解
    PopupWindow 使用详解
    Fragment 使用详解
    Dialog 使用详解
    ListView 使用详解
  • 原文地址:https://www.cnblogs.com/smbx-ztbz/p/9191674.html
Copyright © 2020-2023  润新知