swagger详细教程

SpringBoot集成Swagger SpringBoot集成Swagger 1、Swagger简介 前后端分离 前端 : 前端控制器、视图层 后端 : 后端控制器、服务层、数据访问层 前后端通过API进行交互 前后端相对独立且松耦合 前后端甚至可以部署在不同的服务器上 产生一个问题: 前后端集成联调,前端人员和后端人员无法做到,“及时协商,尽早解决”,最终导致问题集中爆发 解决问题 首先制定schema[计划的提纲],实时更新最新API,降低集成的风险; 前后端分离: 前端测试后端接口:postman (早些年) 后端提供接口, 阅读详情

环境 ; maven项目 , springboot+spring+mybatis ,JDK1.8

一. 引入swagger jar包

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.7.0</version>
</dependency>
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>2.7.0</version>
</dependency>

二. 编写配置类

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static com.google.common.collect.Lists.newArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/swagger/**").addResourceLocations("classpath:/static/swagger/");
    }


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            //加了ApiOperation注解的类,才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            //包下的类,才生成接口文档
            .apis(RequestHandlerSelectors.basePackage("com.modules.oss.controller")) //这个路径需要根据你自己的项目层级来写
            .paths(PathSelectors.any())
            .build();
//            .securitySchemes(security());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("测试项目api")
            .description("测试项目后台api接口文档")
            .termsOfServiceUrl("https://blog.youkuaiyun.com")
            .version("2.1")
            .build();
    }
    private List<ApiKey> security() {
        return newArrayList(
            new ApiKey("token", "token", "header")
        );
	}
}

三. 接口类

@Api(value = "分类",description = "分类接口")
@RestController
@RequestMapping("oss/sysclassify")
public class SysClassifyController {
    @Autowired
    private SysClassifyService sysClassifyService;

    /**
     * 列表
     */

//    @RequestMapping("/list")
    @ApiOperation(value = "分类列表",notes = "列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params",value = "map集合",paramType = "query",dataType = "int",required = true)
    })
    @PostMapping("/list")
//    @RequiresPermissions("oss:sysclassify:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysClassifyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(notes = "测试查询单个分类接口",value = "查询分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "分类ID",paramType = "path",dataType = "Long",required = true)
    })
    @GetMapping("/info/{id}")
    public R info( @PathVariable("id") Long id){
			SysClassifyEntity sysClassify = sysClassifyService.selectById(id);

        return R.ok().put("sysClassify", sysClassify);
    }

四.实体类

@ApiModel
@TableName("sys_classify")
public class SysClassifyEntity implements Serializable {
private static final long serialVersionUID = 1L;

/**
 * 
 */
@ApiModelProperty("分类ID")
@TableId
private Long id;
/**
 * 类名
 */
@ApiModelProperty("类名")
private String name;
/**
 * 上级id
 */
@ApiModelProperty("上级id")
private Long parentid;
/**
 * 所属层级
 */
@ApiModelProperty("所属层级")
private Integer level;
/**
 * 分类类型:1 区域分类 2 内部分类
 */
@ApiModelProperty("分类类型:1 区域分类 2 内部分类")
private Integer type;
/**
 * 分类分组:1 区域分类 2 内部分类
 */
@ApiModelProperty("1 区域分类 2 内部分类")
private Integer group;

五 . 访问地址
刚开始我也是按照上面的配置弄好以后,一直不显示我配置的那几个接口,后来才知道,访问的地址不对 , 正确的地址是
http://localhost:8080/swagger-ui.html
当然上边是根路径是 "/"的时候 ,
如果你的根路径是带有项目名的,那就是这样
http://localhost:8080/你的项目名/swagger-ui.html
注意 : 地址千万不要搞错,要不然你会怀疑自己的配置是否出问题 然而呢,有时候并不是配置出问题,而是你没有去正确的地址查看

六.国际化(接口测试页面显示中文)
这里写图片描述
根据上面jar包的层级,在你的项目下创建同样的目录结构
这里写图片描述
你自己新建的swagger-ui.html里的内容复制下边的代码粘贴进去即可

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Swagger API</title>
    <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/images/favicon-32x32.png" sizes="32x32"/>
    <link rel="icon" type="image/png" href="webjars/springfox-swagger-ui/images/favicon-16x16.png" sizes="16x16"/>
    <link href='webjars/springfox-swagger-ui/css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
    <link href='webjars/springfox-swagger-ui/css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
    <link href='webjars/springfox-swagger-ui/css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
    <link href='webjars/springfox-swagger-ui/css/reset.css' media='print' rel='stylesheet' type='text/css'/>
    <link href='webjars/springfox-swagger-ui/css/print.css' media='print' rel='stylesheet' type='text/css'/>

    <link href='/spring-boot-mybatis/src/main/resourse/META-INF/resources/swagger.css' type='text/css'/>

    <script src='webjars/springfox-swagger-ui/lib/object-assign-pollyfill.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/jquery-1.8.0.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/jquery.slideto.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/jquery.wiggle.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/handlebars-4.0.5.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/lodash.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/backbone-min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/swagger-ui.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack_extended.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/jsoneditor.min.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/marked.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lib/swagger-oauth.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/springfox.js' type='text/javascript'></script>

    <!--中文js -->
    <script src='webjars/springfox-swagger-ui/lang/translator.js' type='text/javascript'></script>
    <script src='webjars/springfox-swagger-ui/lang/zh-cn.js' type='text/javascript'></script>
    <style type="text/css">



    </style>
</head>

<body class="swagger-section">
<div id='header'>
    <div class="swagger-ui-wrap">
        <a id="logo" href="http://swagger.io"><img class="logo__img" alt="swagger" height="30" width="30" src="webjars/springfox-swagger-ui/images/logo_small.png" /><span class="logo__title">swagger</span></a>
        <form id='api_selector'>
            <div class='input'>
                <select id="select_baseUrl" name="select_baseUrl"/>
            </div>
            <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
            <div id='auth_container'></div>
            <div class='input'><a id="explore" class="header__btn" href="#" data-sw-translate>Explore</a></div>
        </form>
    </div>
</div>

<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>

七.至此大功告成

	END  !!!
Swagger完全教程 简介 Swagger 是最流行的 API 开发工具,它遵循 OpenAPI Specification(OpenAPI 规范,也简称 OAS)。 Swagger 可以贯穿于整个 API 生态,如 API 的设计、编写 API 文档、测试和部署。 Swagger 是一种通用的,和编程语言无关的 API 描述规范。 应用场景 如果你的 RESTful API 接口都开发完成了,你可以用 Swagge... 阅读详情

相关推荐

swagger使用教程——快速使用swagger

官网:https://swagger.io/swagger是一个规范和完整的框架,用于生成、描述、调用和可视化RestFul风格的web服务,总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器断的代码,允许API来始终保持同步。作用:1. 接口的文档在线自动生成。2. 功能测试。Swagger-tools:提供各种与Swagger进行集成和交互的工具。例如模式检验、Swagger 1.2文档转换成Swagger 2.0文档等功能。Swagger-core: 用于

m0_67402588的博客 1111

Swagger-的使用(详细教程)

作为后端开放人员,最烦的事就是自己写接口文档和别人没有写接口文档,不管是前端还是后端开发,多多少少都会被接口文档所折磨,前端会抱怨后端没有及时更新接口文档,而后端又会觉得编写接口文档太过麻烦。Swagger 可以较好的接口接口文档的交互问题,以一套标准的规范定义接口以及相关的信息,就能做到生成各种格式的接口文档,生成多种语言和客户端和服务端的代码,以及在线接口调试页面等等。只需要更新 Swagger 描述文件,就能自动生成接口文档,做到前端、后端联调接口文档的及时性和便利性。官网:https://swagg

xhmico的博客 7万+

Spring Boot 3项目集成Swagger3教程

欢迎来到我的小天地,这里是我记录技术点滴、分享学习心得的地方。??让我们一起在技术的道路上不断前行!??

m0_74823094的博客 1502

Swagger——快速使用swagger

swagger使用教程,springboot整合使用swagger

YR_112233的博客 8万+

Swagger 安装使用教程

Swagger是一套完整的API开发工具链,支持RESTful API的设计、测试和文档生成。主要组件包括Swagger UI(可视化文档展示)、Swagger Editor(规范文件编辑)、Swagger Codegen(代码生成)和SpringFox(Spring集成)。本文详细介绍了Swagger UI和Spring Boot的集成方法,包括配置步骤和常见问题解决方案。针对Spring Boot 3.x用户,建议使用Springdoc OpenAPI替代不兼容的SpringFox。此外还提供了本地部署

真正的大师永远怀着一颗学徒的心 1556

用Multisim仿真AD630锁定放大器:从2012年电赛A题实战到避坑指南

本文详细介绍了如何使用Multisim仿真AD630锁定放大器,从2012年电赛A题实战出发,提供完整的电路搭建、参数优化及避坑指南。重点解析AD630的开关调制架构和双相位检测的工程实现,帮助读者在强噪声背景下有效提取微弱信号,提升电子设计竞赛和工程实践中的信号处理能力。

weixin_42549451的博客 204

SpringBoot-----集成Swagger

SpringBoot集成Swagger 文章目录SpringBoot集成Swagger前后端分离:产生的问题:SwaggerSpringBoot集成Swagger配置Swagger配置扫描接口配置Swagger开关配置API分组实体配置常用注解总结 简介: 前后端分离: 前端 ->前端控制层,视图 后端 ->后端控制层,服务层,数据访问层 前后端通过API进行交互 前后端相对独立且松耦合 产生的问题: 前后端集成,前端或者后端无法左到"“及时协商,今早解决”",最终问题集中爆发 Swag

qq_44236958的博客 1304

嵌入式开发实战:LWIP中PPP协议配置全流程(含CHAP认证避坑指南)

本文是一份嵌入式开发实战指南,详细解析了如何在STM32平台上配置LWIP协议栈中的PPP协议,实现从串口到IP网络的完整连接。内容涵盖工程搭建、源码整合、关键配置、串口驱动绑定、状态管理以及CHAP认证等核心流程,并重点提供了CHAP认证失败的排查与避坑指南,帮助开发者高效打通嵌入式设备的网络连接。

plant的博客 464

Swagger保姆级教程

Swagger 学习目标: 了解Swagger的概念及作用 掌握在项目中集成Swagger自动生成API文档 Swagger简介 Swagger 号称世界上最流行的API框架 Restful Api 文档在线自动生成器 => API 文档 与API 定义同步更新 直接运行,在线测试API 支持多种语言 (如:Java,PHP等) 官网:https://swagger.io/ SpringBoot集成Swagger SpringBoot集成Swagger => springfox,两个ja

qq_24851813的博客 247

手把手教你绕过网易易盾验证码:滑块、点选、语序全攻略

本文深度解析了以网易易盾为代表的现代验证码技术,重点探讨了滑块、点选、语序及空间推理等交互式验证码的工作原理与对抗策略。文章从行为验证和空间推理的核心逻辑出发,剖析了验证码交互的数据流与关键参数,并提供了模拟人类行为轨迹、维护设备指纹等工程实践方法,旨在帮助开发者在合规前提下设计更健壮的自动化流程。

3c4x5z6v7b的博客 712

UEC++ 虚幻5笔记(数字孪生示例) day13

文件读取与写入,数字孪生入门制作

qq_44924388的博客 3844

Swagger教程二

Swagger搭建Restful接口教程二 一、前言         上一章节我们说的是swagger-ui也就是swagger1,接下来我们说的是swagger升级版swagger2         Swagger是当前最好用的Restful API文档生成的开源项目,随着swagger的越来越流行,原来需要有人把dist封装成jar,与spring相关框架结合,也就成了springfox...

愤怒的懒洋洋的博客 5万+

基于carsim与Simulink联合仿真的车辆换道轨迹规划与轨迹跟踪模型

PID_反步控制_滑膜控制三种四旋翼无人机轨迹跟踪控制算法仿真 附带对应的说明文档,提供建模过程与仿真结果文献(英文)➕PPT 描述:采用的同一种参考轨迹,都是三维仿真 三种控制方法: [1]PID控制、[2]反步控制、[3]滑膜控制(三个仿真模型) 每个仿真均应用了同一种轨迹路径,直接运行即可出三维图,可以实现四旋翼无人机轨迹的跟踪

2501_90804007的博客 1085

swagger使用教程

swagger教程,日后自己补一篇

qq_40321119的博客 477

Python 爬虫实战:去哪儿网机票价格爬取与出行比价分析

本文介绍了一个基于Python的机票价格监控系统,通过爬取去哪儿网数据实现多航线查询与智能比价。系统采用requests+BeautifulSoup+selenium技术栈,具备以下功能: 实时查询指定航线价格 历史价格追踪与分析 最低价推荐与价格预警 数据可视化展示 文章详细解析了去哪儿网的页面结构和反爬机制,提供了Selenium浏览器的完整配置方案,并实现了一个可稳定运行的机票采集爬虫。该系统能帮助用户掌握价格波动规律,选择最优购票时机,每年可节省可观的出行成本。

u014481728的博客 674

微信小程序推广策略,打开小程序领域流量大门

本文旨在为小程序开发者、运营者和企业主提供一套完整的微信小程序推广策略体系,帮助他们在竞争激烈的小程序生态中获得更多流量和用户。内容涵盖从0到1的冷启动策略,到成熟期的增长技巧。本文将首先介绍小程序的基础推广设置,然后深入探讨各种流量获取渠道,接着分析数据驱动的优化方法,最后展望未来发展趋势。小程序:无需下载安装即可使用的应用,运行在微信生态内:独立访客数:页面浏览量转化率:完成目标行为的用户比例留存率:用户在一定时间后仍活跃的比例自然流量获取:通过优化搜索、完善资料等方式获得基础流量社交裂变。

小程序开发 1031

Swagger教程

Swagger搭建Restful接口教程一 一、前言        Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件,随着现在许多公司实现了前后端分离,swagger越来越受欢迎了。        博主之前在网上查看相关博客的时候,发现这些博客说的都不是很清楚,更有甚者连版本都弄错了,明明不能实现,访问量还挺多的,表示很无奈。为了帮助大家,特意抽时间系统性的整理了...

愤怒的懒洋洋的博客 10万+

ORB-SLAM3代码详解 - 第 18 篇 · Atlas 多地图系统、地图保存与全系统调优

会跑:理解三线程架构与数据流(01/08/10/13),能编译、配参、复现各数据集结果。会改:掌握相机模型抽象(05)、g2o 顶点与边(14)、预积分(15),能接入新传感器、新相机、新约束。会调:理解每个参数背后的物理含义与耦合(03/15/16/18),能针对自己的平台与场景做精度/实时/鲁棒的权衡。ORB-SLAM3 的价值不止于一个可用的 SLAM 系统,更在于它是一套工程化的几何状态估计模板:清晰的模块边界、可替换的相机/传感器抽象、紧耦合优化的标准范式。

PX4-SLAM-PNC 173

Swagger使用的详细教程

swager的详细使用,及其空指针bug解决

mkmmkkghhhhhhhh的博客 1万+

深度学习工具包 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")

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Swagger Maven Plugin 教程

Swagger Maven Plugin 教程 1. 项目介绍 Swagger Maven Plugin 是一个Maven插件,它允许你在构建期间自动生成Swagger规范(即OpenAPI规范)以及可定制的静态文档。不同于swagger-core,这个插件不会和你的应用程序一起实时提供规范,而是在编译阶段生成JSON或YAML格式的规范文件。这有助于管理和分享RESTful API的文档。 2....

gitblog_00864的博客 669

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Swagger Diff 使用教程

Swagger Diff 使用教程 项目介绍 Swagger Diff 是一个用于比较两个不同 Swagger 规范的实用工具。它可以帮助开发者识别和理解 API 版本之间的变化,从而确保 API 的兼容性和一致性。Swagger Diff 支持 Swagger 规范的 v1.x 和 v2.0,并提供了深度比较参数、响应、注释和 HTTP 方法的功能。此外,它还支持 Swagger API 的授权...

gitblog_00827的博客 972

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Iris Swagger 项目教程

Iris Swagger 项目教程 项目介绍 Iris Swagger 是一个基于 Go 语言的 Web 框架 Iris 的 Swagger 集成项目。它允许开发者轻松地将 Swagger UI 集成到 Iris 应用中,从而为 API 文档提供一个可视化的界面。通过 Swagger,开发者可以自动生成 API 文档,并提供交互式的 API 测试工具。 项目快速启动 安装依赖 首先,确保你已经安装...

gitblog_00478的博客 706

Swagger Axios Codegen 使用教程

Swagger Axios Codegen 使用教程 1. 项目介绍 swagger-axios-codegen 是一个基于 Swagger 规范生成 Axios 客户端代码的工具。它支持 TypeScript,能够自动生成类型安全的 API 客户端代码,简化了与后端 API 的交互过程。通过该工具,开发者可以快速生成与 Swagger 文档对应的 TypeScript 代码,从而提高开发效率。 ...

gitblog_00058的博客 530

swagger完整教程

swagger完整教程 https://blog.youkuaiyun.com/jack85986370/article/details/51335134

weixin_43894213的博客 504
上一篇: JWT与cookie和token的区别
下一篇: Lombok常用注解详解
微微一笑满城空
博客等级 码龄10年 6372粉丝 114原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微微一笑满城空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值