zoukankan      html  css  js  c++  java
  • Deep Learning 2_深度学习UFLDL教程:矢量化编程(斯坦福大学深度学习教程)

    1前言

        本节主要是让人用矢量化编程代替效率比较低的for循环。

        在前一节的Sparse Autoencoder练习中已经实现了矢量化编程,所以与前一节的区别只在于本节训练集是用MINIST数据集,而上一节训练集用的是从10张图片中随机选择的8*8的10000张小图块。综上,只需要在前一节的代码中稍微修改一下就可。

    2练习步骤

    1.下载数据集及UFLDL提供的加载数据集的函数,并把他们和上节程序放在同一文件夹中。要注意的是UFLDL提供的加载数据集的函数中程序用的数据集名称是train-images-idx3-ubyte,要把他改为train-images.idx3-ubyte。可用如下程序检查MINIST数据集是否可加载成功。

    % Change the filenames if you've saved the files under different names
    % On some platforms, the files might be saved as 
    % train-images.idx3-ubyte / train-labels.idx1-ubyte
    images = loadMNISTImages('train-images.idx3-ubyte');
    labels = loadMNISTLabels('train-labels.idx1-ubyte');
     
    % We are using display_network from the autoencoder code
    display_network(images(:,1:100)); % Show the first 100 images
    disp(labels(1:10));
    

      运行之后得到如下结果就表示已经可以正确加载:

    2.矢量化Sparse Autoencoder程序,即上一节程序,因上节已实现,故此步骤可免去。

    3.学习手写数字库的特征。

        前言中已经说了,本步只需要在上节中稍微修改一下即可,具体如下:

    ①修改初始参数,把train.m文件中把step0里面的各个参数调整成这样:

    visibleSize = 28*28;   % number of input units 输入层单元数
    hiddenSize = 196;     % number of hidden units隐藏层单元数
    sparsityParam = 0.1;   % desired average activation of the hidden units.稀疏值
                         % (This was denoted by the Greek alphabet rho, which looks like a lower-case "p",
    		     %  in the lecture notes). 
    lambda = 3e-3;     % weight decay parameter 权重衰减系数      
    beta = 3;            % weight of sparsity penalty term稀疏值惩罚项的权重   
    

    ②修改训练集,把step1里面的patches的产生改为:

    %% STEP 1: Implement sampleIMAGES  第1步:实现图片采样
    %
    %  实现图片采样后,函数display_network从训练集中随机显示200张
    %  After implementing sampleIMAGES, the display_network command should
    %  display a random sample of 200 patches from the dataset
    images = loadMNISTImages('train-images.idx3-ubyte');
    patches = images(:,1:10000);
    
    % patches = sampleIMAGES;
    display_network(patches(:,randi(size(patches,2),200,1)),8);%从10000张中随机选择200张显示
    
    
    %  Obtain random parameters theta初始化参数向量theta
    theta = initializeParameters(hiddenSize, visibleSize);
    

     4.其他一切不变,但是为了提高效率,可把train.m中的 STEP 3: Gradient Checking这步注释掉,因为在本例中训练集更大,梯度检查会比较慢。然后运行train.m可得到可视化结果为:

    Elapsed time is 365.887537 seconds.

    ……

  • 相关阅读:
    BitmapDrawable
    Understanding Density Independence in Android
    HttpURLConnection
    [Unity3D]事半功倍:界面插件NGUI的使用教程与实例
    lua下标
    数组形参
    Hibernate的一级缓存
    必备技术
    idea 跳转实现类-快捷键
    JavaSE面试题:单例设计模式
  • 原文地址:https://www.cnblogs.com/dmzhuo/p/4920762.html
Copyright © 2011-2022 走看看