2014年10月22日星期三

深度网络实现手写体识别 - 太白路上的小混混

本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订
深度网络实现手写体识别 - 太白路上的小混混  阅读原文»

基于自动编码机(autoencoder),这里网络的层次结构为一个输入层,两个隐层,后面再跟着一个softmax分类器:

采用贪婪算法,首先把input和feature1看作一个自动编码机,训练出二者之间的参数,然后用feature1层的激活值作为输出,输入到feature2,即把feature1和feature2再看作一个自动编码机,训练出这两层之间的参数,这两步都没有用到分类标签,所以是无监督学习,最后把feature2的激活值作为提取的的特征,输入到分类器,这里需要标签来计算代价函数,从而由优化这个代价函数来训练出feature2与分类器之间的参数,所以这一步是有监督学习,这一步完成之后,把测试样本输入网络,最后会输出该样本分别属于每一类的概率,选出最大概率对应的类别,就是最终的分类结果。

为了使得分类结果更加精确,可以对训练出的参数进行微调,就是在有监督学习之后,我们利用有标签的训练数据可以计算出分类残差,然后利用这个残差反向传播,对已经训练出的参数进行进一步微调,会对最终预测的精度有很大提升

下面是第一层训学习出的特征:

可以看出都是一些笔迹的边缘

作为对比,训练结果显示,微调之后,分类准确度有大幅提升,所以在训练深度网络之后,利用部分标签数据进行微调是一件很有必要的学习

Before Finetuning Test Accuracy: 91.760%
After Finetuning Test Accuracy: 97.710%

下面是部分程序代码,需要用到,完整代码请先下载minFunc.rar,然后下载stacked_exercise.rar,minFunc.rar里面是lbfgs优化函数,在优化网络参数时需要用到。

%% CS294A/CS294W Stacked Autoencoder Exercise

% Instructions
% ------------
%
% This file contains code that helps you get started on the
% sstacked autoencoder exercise. You will need to complete code in
% stackedAECost.m
% You will also need to have implemented sparseAutoencoderCost.m and
% softmaxCost.m from previous exercises. You will need the initializeParameters.m
% loadMNISTImages.m, and loadMNISTLabels.m files from previous exercises.
%
% For the purpose of completing the assignment, you do not need to
% change the code in this file.
%
%%======================================================================
%% STEP 0: Here we provide the relevant parameters values that will
% allow your sparse autoencoder to get good filters; you do not need to
% change the parameters below.

inputSize
= 28 * 28;
numClasses
= 10;
hiddenSizeL1
= 200; % Layer 1 Hidden Size
hiddenSizeL2
= 200; % Layer 2 Hidden Size
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

%%======================================================================
%% STEP 1: Load data from the MNIST database
%
% This loads our training data from the MNIST database files.

% Load MNIST database files
trainData
= loadMNISTImages('train-images.idx3-ubyte');
trainLabels
= loadMNISTLabels('train-labels.idx1-ubyte');

trainLabels(trainLabels
== 0) = 10; % Remap 0 to 10 since our labels need to start from 1

%%======================================================================
%% STEP 2: Train the first sparse autoencoder
% This trains the first sparse autoencoder on the unlabelled STL training
% images.
% If you've correctly implemented sparseAutoencoderCost.m, you don't need
% to change anything here.


% Randomly initialize the parameters
sae1Theta
= initializeParameters(hiddenSizeL1, inputSize);

%% ---------------------- YOUR CODE HERE ---------------------------------
% Instructions: Train the first layer sparse autoencoder, this layer has
% an hidden size of "hiddenSizeL1"
% You should store the optimal parameters in sae1OptTheta
addpath minFunc
/;
options
= struct;
options.Method
= 'lbfgs';
options.maxIter
= 400;
options.display
= 'on';
%训练出第一层网络的参数
[sae1OptTheta, cost]
= minFunc(@(p) sparseAutoencoderCost(p,...
inputSize,hiddenSizeL1,lambda,...
sparsityParam,beta,trainData),...
sae1Theta,options);
save(
'step2.mat', 'sae1OptTheta');
W1
= reshape(sae1OptTheta(1:hiddenSizeL1 * inputSize), hiddenSizeL1, inputSize);
display_network(W1
'SqlServer2008 跨服务器同步数据 - 小丑不戴面具  阅读原文»

最近工作中需要跨服务器同步数据,在数据库DB1中的表T1插入数据,同时触发T1的触发器(这里暂不讨论触发器的效率问题),向另一台服务器DB2中的相同的一张表T2插入数据,查看了一些资料说,

需要打开DTC(分布式交易协调器)协调跨多个数据库、消息队列、文件系统等资源管理器的事务,

于是按照网上说的,将自己的DTC打开启动,步骤如下:

DTC位置:控制面板--管理工具--服务--Distributed Transaction Coordinator

然后在本机SqlServer里新建一个触发器测试了一下,提示“该伙伴事务管理器已经禁止了它对远程/网络事务的支持”

出现这个问题的原因是对方电脑没有配置好DTC,所以需要将另一台服务器也做如下配置:

两台服务器电脑做如下配置(windows2003系统):

2. 单击“添加/删除 Windows 组件”。
3. 选择“应用程序服务器”,然后单击“详细信息”。
4. 选择“启用网络 DTC 访问”,然后单击“确定”。
5. 单击“下一步”;单击“完成”。
6. 在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务"。
7. 右键“我的电脑”->“属性”,在MSDTC选项卡中,点击“安全配置”按钮。
8. 在安全配置窗口中做如下设置:
(1)选中“网络DTC访问”
(2)在客户端管理中选中“允许远程客户端”“允许远程管理”
(3)在事务管理通讯中选“允许入站”“允许出站”“不要求进行验证”
(4)保证DTC登陆账户为:NT Authority\NetworkService 
(5)单击"确定"。这样将会提示您"MS DTC 将会停止并重新启动。
所有的依赖服务将被停止。请按'是'继续"。单击"是"继续。

我当时先拿同事的电脑做了下测试,同事的系统是Win7,按上面的步骤没有找到“应用程序服务器”,需要按下面的方法操作:

Vista, Windows 7,Windows Server 2008 MSDTC配置
1. 打开“控制面板(Control Panel)�管理工具(Administrative Tools)�组件服务(Component
Service)”(或者开始-运行 “Dcomcnfg.exe”)


2. 打开“组件服务(Component Service)�计算机(Computers)”


3. 在“我的电脑(My Computer)”上点击右键,点击“属性(Properties)”

4. 在Local DTC Properties对话框中,点击“安全(Security)”选项卡。 在安全配置选项卡中做如下设置:

选中“网络DTC访问(Network DTC Access)” 在客户端管理(Client and Administration)中选中“允许远程客户端(Allow remote Clients)”
和“允许远程管理(Allow Remote Administration)”
在事务管理通讯(Transaction Manager Communication)中选“允许入站(Allow
Inbound)”“允许出站(Allow Outbound)”“不要求进行验证(No Authentication Required)”
保证DTC登陆账户为:NT Authority\Network Service

再次测试出现提示:“其他会话正在使用事务的上下文”,这是因为对方服务器表中也有触发器,需要进行一下判断。

下面给出测试的例子:

--创建测试表
CREATE TABLE [dbo].[TB1](
[id] [int] NULL,
[age] [money] NULL
)
ON [PRIMARY]

GO

--创建链接服务器
exec sp_addlinkedserver 'it38 ', ' ', 'SQLOLEDB ', '172.16.3.38' --对方服务器地址
exec sp_addlinkedsrvlogin 'it38 ', 'false ',null, 'sa', 'sa' --对方服务器用户名密码
--
删除创建的链接服务器时使用
--
exec sp_dropserver 'it38 ', 'droplogins '
--
为表testTB2创建触发器
CREATE TRIGGER [dbo].[tr_qiao] on [dbo].[TB1]
FOR INSERT
AS
BEGIN
SET NOCOUNT ON
SET XACT_ABORT ON
INSERT INTO it245.hlldb.dbo.t(id,age)
SELECT id, age FROM inserted;
END
GO

--***********************************************
--
插入一条数据测试
INSERT INTO TB1(id,age) values(5,55);


本文链接:SqlServer2008 跨服务器同步数据,转载请注明。

阅读更多内容

没有评论:

发表评论