逆向工程之还原源代码演示

Laya小游戏开发,laya3D美术篇——1——关于laya自带的几个shader的基础运用讲解。 用laya材质,还原app中的光照效果,以及laya几种shader的讲解与使用。 阅读详情

Basic binary reconstruction from assembler
          by c0ntex | c0ntexb@gmail.com      
------------------------------------------

This paper will provide a quick overview of how to perform reverse engineering against a simple .exe binary.
By using the assembly of a binary, it can be trivial to gain a basic understanding of the executable, which
will allow for the source code to be retrieved almost exactly as the developer designed it.

In this example we are only using a small program and as such it is easy to do, on a larger exe it would take
much longer and a more rigerous review of the assembler would be required.


// IDA assembler dump
; seh.exe
.text:0040102B                 push    ebp
.text:0040102C                 mov     ebp, esp  
.text:0040102E                 sub     esp, 0Ch
.text:00401031                 cmp     [ebp+argc], 2
.text:00401035                 jz      short loc_40104B
.text:00401037                 push    offset aUsageSeh_exeBu ; "Usage: seh.exe <buffer>/n"
.text:0040103C                 call    _printf
.text:00401041                 add     esp, 4
.text:00401044                 push    1               ; int
.text:00401046                 call    _exit

.text:0040104B loc_40104B:                             ; CODE XREF: _main+Aj
.text:0040104B                 lea     eax, [ebp+var_C] 
.text:0040104E                 push    eax             ; char * 
.text:0040104F                 mov     ecx, [ebp+argv] 
.text:00401052                 push    ecx             ; int 
.text:00401053                 call    sub_401000 
.text:00401058                 add     esp, 8 
.text:0040105B                 xor     eax, eax 
.text:0040105D                 mov     esp, ebp
.text:0040105F                 pop     ebp 
.text:00401060                 retn 
.text:00401060 _main           endp

.text:00401000 sub_401000      proc near               ; CODE XREF: _main+284p
.text:00401000
.text:00401000 arg_0           = dword ptr  8
.text:00401000 arg_4           = dword ptr  0Ch
.text:00401000
.text:00401000                 push    ebp
.text:00401001                 mov     ebp, esp
.text:00401003                 mov     eax, [ebp+arg_0]
.text:00401006                 mov     ecx, [eax+4]
.text:00401009                 push    ecx             ; char *
.text:0040100A                 mov     edx, [ebp+arg_4]
.text:0040100D                 push    edx             ; char *
.text:0040100E                 call    _strcpy
.text:00401013                 add     esp, 8
.text:00401016                 mov     eax, [ebp+arg_4]
.text:00401019                 push    eax
.text:0040101A                 push    offset aMySehf00IsBett ; "/nMy sehf00 is better than your sehf00 -"...
.text:0040101F                 call    _printf
.text:00401024                 add     esp, 8
.text:00401027                 xor     eax, eax
.text:00401029                 pop     ebp
.text:0040102A                 retn
.text:0040102A sub_401000      endp


So from the above assembler, we can start to replay the instructions into the equivilent c language and have
a fairly good, though not exact, representation of the c *in this case* code used to build the executable.

If there is a piece of code that you are unsure what it's function is, you can write a test c file and run
it through IDA to verify the instructions against what you thought / expected to see.

Dumping the first function only to show how it is done:


push    ebp       ;Back up original stack pointer
mov     ebp, esp      ;            procedure prologue
sub     esp, 0Ch      ;Allocate 12 bytes of space
cmp     [ebp+argc], 2      ;Verify there are 2 arguments passed
jz      short loc_40104B     ;if there are, jump to loc_40104B
push    offset aUsageSeh_exeBu ; "Usage: seh.exe <buffer>/n" ;if not, push error message on stack
call    _printf       ;print the error message
add     esp, 4       ;add 4 to esp
push    1               ; int     ;push exit value
call    _exit       ;exit


probably giving us:


int main(int argc, char **argv)
{
 if(argc != 2) {
   printf("Usage: seh.exe <buffer>/n");
   _exit(1);
  }
something()
}


Do this with each function until we have sourced the entire image. Performing this type of resolution on all
the assembler will provide something like the following:


int main(int argc, char **argv)
{
        char varc[12];
        if(argc != 2) {
                printf("Usage: seh.exe <buffer>/n");
                _exit(1);
        }
        locfunc(argv, varc);
        return(0);
}

locfunc(char **argv, char *varc);
        strcpy(varc, argv[1]);
        printf("My sehf00 is better than your sehf00/n");
        return(0);
}

As you can see we have a fairly complete piece of code, the actual program below is the initial code used to
compile seh.exe and it is obvious that we were real close to the correct syntax. This just shows that even in
a situation when you do not have the applications source to hand, it is still fairly trivial to make by using
a dissassembler to see exactly how the program fits together.

This can be an important skill to have if you want to examine or modify an executable in some manner when you
do not have source code. Say that this application was a piece of malware or a worm that you found on your
system. It would be useful to understand how it worked and perhaps how it got there. By reverse engineering
it, functionality can become apparent straight away and allow you do determine how the program works and what
it does.

// Original seh.exe source
#include<stdio.h>
#include<string.h>
#include<windows.h>

int blah(char *argv[], char *sehheh)
{
        strcpy(sehheh, argv[1]);
 
        printf("/nMy sehf00 is better than your sehf00 -> [%s]/n", sehheh);

        return(0);
}

int main(int argc, char *argv[]){

        char sehheh[12];

        if (argc != 2){
                printf("Usage: myseh.exe <buffer>/n");
                exit(1);
        }

        blah(argv, sehheh);

        return(0);
}

I hope this short paper has been useful in showing how easy it is to perform some basic reverse engineering
of a compiled executable.

160个CrackMe之108 mfc程序 寻找按钮事件,代码还原(下) ·分析该CrackMe按钮事件 这个check就是个按钮,现在用visual studio提供的工具看看这个按钮id ·选择自己的Spy++(不会用的话百度查一下) 找到check按钮id是1 ·那该程序的检查按钮事件就为 AFX_MSGMAP_ENTRY 按钮;按钮。nMessage = WM_COMMAND ; 按钮。nCode = BN_CLICKED ; 按钮。nID = 1 ; 按钮。nLastID = 1 ; 按钮。nSig = AfxSigCmd_v ; 阅读详情

相关推荐

Python逆向工程入门:从PyInstaller打包程序还原源代码的完整流程

Python作为一种解释型语言,其源代码在执行前会被编译为字节码文件(.pyc),这一机制旨在提升程序的加载效率。理解字节码与源代码之间的转换原理,是掌握Python程序内部运行机制的关键。在软件安全分析、第三方库行为审查以及学习优秀代码实现等场景中,逆向工程技术具有重要价值。通过使用PyInstaller Extractor等工具进行解包,定位并修复字节码文件头,再借助uncompyle6等反编译工具,可以将打包后的可执行文件逐步还原为可读的Python源代码。本文以PyInstaller打包的程序为例,

weixin_26965807的博客 352

逆向-获取一个网站中一个功能的源代码

前言 只是一个分享经验贴,自己也是小白,对于逆向了解不多。只不过有需求,那么就要找出思路完成,分享一下我的思路。 范例 以在线JSON校验格式网站的压缩JSON功能逆向需求源代码 网址:在线JSON校验格式网站 1、首先,devtool工具在Elements中找到按钮的源代码,如下图,我们可以看到其有两个属性对我们有用,id和data-html,type和class就不多说了。 2、紧接着我们ctrl+F,打开搜索框,将id复制进去,寻找页面中是否有与id关联的代码。在本案例中并无,因此,我们进入d

News777的博客 2573

Python逆向工程实战:从PyInstaller打包的EXE文件还原源代码

Python逆向工程是软件安全分析和代码审计领域的重要技术,其核心原理在于解析程序二进制文件的结构与数据。通过分析Python打包工具(如PyInstaller)生成的EXE文件格式,可以提取被封装和处理的字节码文件。这项技术的价值在于帮助开发者恢复丢失的源代码、进行安全漏洞分析或学习优秀代码实现。在实际应用场景中,逆向工程常用于软件维护、安全研究和教育领域。本文以PyInstaller打包的EXE文件为例,详细介绍了使用PyInstaller Extractor工具进行解包、修复.pyc文件头结构、以及通

aodiyi6351的博客 407

小程序逆向之源码获取

没错这就是你微信里加载过的所有小程序,从文件夹的名称很难看出来哪一个是,但是可以从文件的时间上,找到你操作目标小程序相近时间的文件夹,点进文件夹,找到后缀是wxapkg的文件就是我们想要的文件。用微信开发者工具加载源码,就可以愉快的找你想要的东西了,但是需要提醒的一点就是,反编译小程序没有文章讲的那么简单,会出现各种小问题(环境、依赖、分包等等),欢迎大家一起探索。2、上一步得到的文件是加密过的,是不能拿来直接用的,所有就需要我们先要将找到的文件解密,需要一个小工具。2、找到PC端加载小程序的文件。

学习python 3161

逆向工程源码.zip

逆向工程核心原理一书的源代码,有需要的朋友可以下载。

c++逆向工程源代码

c++逆向工程源代码

逆向pyinstaller打包的exe程序获取源代码

由于 Python 程序使用简单,并且拥有丰富的第三方库,有很多人会用 Python 程序编写小工具或者恶意文件,偶尔会遇到需要对 Python 编译打包的 exe 程序进行逆向的需求,特此记录一下逆向过程。

fishfishfishman的博客 5704

论文研究-基于源代码分析的逆向建模.pdf

逆向建模通过对源代码进行分析,提取出代码中的对象信息、结构信息、流程信息等,生成对象间的关系描述、结构描述、系统流程描述等设计模型描述。逆向建模过程中对源代码的分析处理与编译过程的前端处理相似,只是处理的复杂程度与产生的目标结果不同,因此可以采用编译技术对源代码进行处理。通过逆向建模可以弥补软件设计中缺少或缺失的模型设计文档,帮助代码阅读者更好地理解程序,帮助软件的测试和优化。介绍了对C/C 源代码进行逆向建模的实现。

使用jad反编译class文件

jad:反编译工具 可以将class文件反编译成java文件 假设将jad.exe安装在f:/java/jad目录下 如果*.class文件和jad程序不在同一个目录,就要用到path环境变量, 将jad 所在目录加到path路径中即可:set path=%path%;f:/java/jad 若要了解jad更为详细的使用帮助信息,直接运行jad.exe查看   1.反编译单个文件

hfutxrg的专栏 1363

android如何将apk反编译成为源代码

android如何将apk反编译成为源代码,里面提供了工具以及反编译教程,有兴趣的可以下载来看看。

开关电源PCB安规设计避坑指南:从光耦开槽到变压器挡墙,这些细节决定认证成败

本文深入解析开关电源PCB安规设计中的关键细节,包括光耦开槽、变压器挡墙工艺等12个致命要点。通过实际案例和工艺参数表,揭示如何避免认证失败,特别强调爬电距离和电气间隙的精确控制,助力工程师提升产品安全性和认证通过率。

weixin_42548893的博客 205

Python字节码逆向工程解决方案:pycdc实现.pyc文件源代码还原

在软件开发与维护过程中,当面临仅有Python字节码文件(.pyc)而缺失源代码的困境时,开发者往往陷入被动局面。**pycdc**作为一款基于C++开发的专业逆向工程工具,通过精准解析Python字节码结构,实现从编译后文件到可读源代码的高效转换。本文将系统介绍这一工具的技术架构、实战应用及高级拓展,帮助技术人员掌握字节码逆向的核心方法,解决代码恢复、安全审计与跨版本兼容分析等关键问题。 ##

gitblog_01170的博客 1137

自考计算机系统原理(第六章计算机系统概论)-13015

名词解释 I/O 硬件 I/O软件 用户空间I/O软件 内核空间I/O 软件 系统调用处理程序 系统调用服务例程 设备驱动程序 中断服务程序 系统级1/O函数 虚拟文件系统 文件描述符 文件元数据 流缓冲区 索引节点 目录文件 目录项 系统打开文件表 磁盘高速缓存 高速缓存 RAM I / O 控制方式 程序直接控制I/O 就绪状态 中断控制I/O 中断屏蔽字 多重中断 中断嵌套 DMA 方式 DMA 控制器 设备控制器 I/O端口 控制端口 数据端口 状态端口 I/O 地址空间 独立编址方式 统一编址方

qq_23872947的博客 1150

写给小白看的,逆向工程怎么上路?

什么是逆向工程 先给大家出一道思考题 用C语言设计一个程序,验证输入的密码是否是“12345678”,如果验证成功,就输出“success”,如果验证失败,则输出“failed”。 我想,大部分新手小白估计会这么写: #include <stdio.h> #include <string.h> int main() { char buf[10] = {0}; scanf("%s", buf); if (strcmp(buf, "12345678") .

MachineGunJoe666 8341

点云直线检测-3DLineDetection复现

点云直线分割-Fast 3D line detection

阁楼 8156

学Simulink--复杂路况场景实例:基于Simulink的智能车辆高速公路行驶仿真(超车与车道变换)

本文详细介绍了基于Simulink的智能车辆高速公路超车仿真系统设计方法。系统包含多车道交通流建模、三层超车决策逻辑(触发条件、可行性检查、执行许可)、五次多项式变道轨迹规划以及横向纵向协同控制等核心模块。通过设定三车道场景(自车初始速度100km/h,前方慢车72km/h),演示了如何实现安全高效的左变道超车全过程(5秒完成3.75m横向移动),并验证了变道平滑性(最大横向加速度1.8m/s²)和安全距离(最小TTC 5.2s)。文章还强调了传感器融合的必要性,并提供了从交通流生成到控制器设计的完整Sim

xiaoheshang_123的博客 397

Java逆向工程从字节码到源码的还原技术

Java字节码是Java虚拟机(JVM)执行的指令集,通过javac编译器将源代码编译为.class文件。逆向工程的核心在于通过分析字节码结构重建高级语言逻辑。通过持续改进的静态分析与动态追踪技术,Java字节码到源码的还原精度正在不断提升,但始终需要平衡代码可读性、还原准确性和技术可行性之间的关系。- 基于LVA(Local Variable Table)的变量类型恢复。### Java逆向工程:从字节码到源码的还原技术。- 基于深度学习的代码风格恢复。2. FernFlower引擎。

ehPhUkST的博客 285

SI案例分享--考虑ESD保护二极管的差分线阻抗仿真

PCB设计中的cut out参考面早已是SI评估中常用的阻抗优化方式,通过合理的仿真建模,可以提供合适的设计参考,并保持与测试结果的高度一致性。

一只豌豆象的博客 1438

GitHub_Trending/ms/MS-DOS源代码逆向工程:从二进制到C语言的还原

MS-DOS作为个人计算机历史上极具影响力的操作系统,其1.25和2.0版本的原始源代码为我们研究早期操作系统架构提供了珍贵的素材。本文将带你了解如何通过逆向工程技术,将MS-DOS的二进制文件还原为C语言代码,揭开这个经典操作系统的神秘面纱。 ## 为什么选择MS-DOS进行逆向工程? MS-DOS操作系统在20世纪80年代至90年代初期广泛应用于个人计算机,是许多人接触计算机的入门系统。通

gitblog_00131的博客 365

深入URP之Shader篇1: URP Shader概述

我们知道,URP和HDRP都是基于SRP的,尽管现在可以使用Shader Graph编写Shader,但是手写Shader仍然是有一定的优势,特别是在性能方面,手写Shader可以更极致的优化,因此我们在项目中前期都是直接使用Shader Graph编写Shader,项目后期会改成手写Shader来提高性能。而在SRP中手写Shader,我们仍然使用的是Shader Lab,这个结构并没有太大的变化,但是SRP Shader中使用Shader Lab语言还是有几点不同。

聚焦游戏和图形引擎开发技术 4639

华为od 面试八股文_数据库_01_含答案

华为od 面试八股文_数据库_01_含答案

MISAYAONE的博客 2168

Java逆向工程从字节码到源代码的转换技术

字节码与源代码之间存在映射关系,但编译过程中会丢失部分信息(如变量名、注释等),这为逆向工程带来挑战。- 工具实现:JD-GUI、FernFlower、CFR等工具通过解析字节码指令重建源代码结构。- 原理分析:通过方法体Code属性还原控制流图,重建if/for/while等语法结构。- 类型推断:基于LDC、INVOKEVIRTUAL等指令操作数恢复类型声明。- LineNumberTable属性:重建代码行号映射。- 多版本字节码支持(Java 8-17)- 特性:支持Kotlin字节码转换。

nxNxXAFK的博客 352

【科研绘图系列】R语言绘制代谢物与临床表型相关性的森林图

本研究通过森林图展示了特定代谢物与三种临床比较之间的相关性分析结果。这种方法不仅直观地展示了每个代谢物的效应大小和不确定性,还允许我们比较不同代谢物在不同临床比较中的影响。森林图的结果表明,某些代谢物在特定临床比较中显示出显著的相关性,这可能为理解疾病的代谢机制提供了重要线索。

专注生信领域 566

[Java]逆向工程从字节码到源代码的转换

Java逆向工程是指通过分析已编译的字节码文件(.class)来还原出近似源代码的过程。通过深入理解Java逆向工程的原理和工具,开发人员可以更好地保护自己的代码,同时在必要时也能有效地分析和理解第三方代码的实现逻辑。4. 语法糖消失:Lambda表达式、try-with-resources等语法糖被展开。### Java逆向工程:从字节码到源代码的转换。2. 第三方库分析:理解依赖库的内部实现机制。3. 安全审计:检测代码中的安全漏洞和后门。#### 2. 字节码与源代码的关系。

ZAUZjINS的博客 425

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Java逆向工程从字节码到源代码的转换技巧

通过系统化应用这些技巧,可以有效提升Java字节码到源代码的转换质量,为代码审计、漏洞分析和技术研究提供可靠基础。Java字节码是Java虚拟机(JVM)执行的指令集,通过编译Java源代码生成。### Java逆向工程:从字节码到源代码的转换技巧。- 异常处理块映射为try-catch结构。- 常量池:存储字符串、类名、方法名等符号引用。- 属性表:包含代码指令(Code属性)- 魔数与版本号:标识字节码文件格式。- 访问标志:类或方法的修饰符信息。- 字段表与方法表:定义类成员结构。

VWRAbkOk的博客 452

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

揭秘Sourcemap逆向工程:5分钟掌握JavaScript源代码提取技术

你是否曾面对一个压缩混淆的JavaScript文件感到无从下手?想要理解前端应用的完整逻辑却只能看到一堆难以阅读的压缩代码?今天,我将为你介绍一款强大的工具——sourcemapper,它能从Sourcemap文件中快速还原完整的JavaScript源代码树,让你轻松窥探前端应用的真实面貌。 ## 什么是Sourcemap?为什么你需要了解它? Sourcemap是现代前端开发中的一项关键技术

gitblog_00489的博客 487

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 监测目录活动
下一篇: 监视程序的编制
iiprogram
博客等级 码龄25年 1068粉丝 1515原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值