重磅:Swagger3.0 官方 starter 诞生了,其它的都可以扔了~

Dubbo集成Knife4j (Swagger 生成doc.html) Apache Dubbo™ 是一款高性能Java RPC框架。Apache Dubbo Spring Boot Project使得使用Dubbo作为RPC框架轻松创建Spring Boot应用程序。Swagger 是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法、参数和模型紧密集成到服务器端的代码,允许 API 来始终保持同步。Swagger 让部署管理和使用功能强大的 API 从未如此简单。 阅读详情

点击上方“芋道源码”,选择“设为星标”

管她前浪,还是后浪?

能浪的浪,才是好浪!

每天 8:55 更新文章,每天掉亿点点头发...

源码精品专栏

 

来源:blog.youkuaiyun.com/wangzhihao1994/article/details/108408420

  • 资料

  • swagger介绍

  • springfox介绍

  • SpringFox 3.0.0 发布

  • 整合使用

  • 一些常用注解说明

  • 示例

  • 参考


资料

  • swagger 官网:swagger.io

  • springfox 官网:springfox

  • springfox Github 仓库:springfox / springfox

  • springfox-demos Github 仓库:springfox / springfox-demos

  • springfox Maven 仓库:Home » io.springfox

swagger介绍

对于 Rest API 来说很重要的一部分内容就是文档,Swagger 为我们提供了一套通过代码和注解自动生成文档的方法,这一点对于保证 API 文档的及时性将有很大的帮助。

Swagger 是一套基于 OpenAPI 规范(OpenAPI Specification,OAS)构建的开源工具,可以帮助我们设计、构建、记录以及使用 Rest API。

OAS本身是一个API规范,它用于描述一整套API接口,包括一个接口是哪种请求方式、哪些参数、哪些header等,都会被包括在这个文件中。它在设计的时候通常是YAML格式,这种格式书写起来比较方便,而在网络中传输时又会以json形式居多,因为json的通用性比较强。

Swagger 主要包含了以下三个部分:

  • Swagger Editor:基于浏览器的编辑器,我们可以使用它编写我们 OpenAPI 规范。

  • Swagger UI:它会将我们编写的 OpenAPI 规范呈现为交互式的 API 文档,后文我将使用浏览器来查看并且操作我们的 Rest API。

  • Swagger Codegen:它可以通过为 OpenAPI(以前称为 Swagger)规范定义的任何 API 生成服务器存根和客户端 SDK 来简化构建过程。

springfox介绍

由于Spring的流行,Marty Pitt编写了一个基于Spring的组件swagger-springmvc,用于将swagger集成到springmvc中来,而springfox则是从这个组件发展而来。

通常SpringBoot项目整合swagger需要用到两个依赖:springfox-swagger2和springfox-swagger-ui,用于自动生成swagger文档。

  • springfox-swagger2:这个组件的功能用于帮助我们自动生成描述API的json文件

  • springfox-swagger-ui:就是将描述API的json文件解析出来,用一种更友好的方式呈现出来。

SpringFox 3.0.0 发布

官方说明:

  • SpringFox 3.0.0 发布了,SpringFox 的前身是 swagger-springmvc,是一个开源的 API doc 框架,可以将 Controller 的方法以文档的形式展现。

  • 首先,非常感谢社区让我有动力参与这个项目。在这个版本中,在代码、注释、bug报告方面有一些非常惊人的贡献,看到人们在问题论坛上跳槽来解决问题,我感到很谦卑。它确实激励我克服“困难”,开始认真地工作。有什么更好的办法来摆脱科维德的忧郁!

  • 注意:这是一个突破性的变更版本,我们已经尽可能地保持与springfox早期版本的向后兼容性。在2.9之前被弃用的api已经被积极地删除,并且标记了将在不久的将来消失的新api。所以请注意这些,并报告任何遗漏的内容。

新特性:

  • Remove explicit dependencies on springfox-swagger2

  • Remove any @EnableSwagger2… annotations

  • Add the springfox-boot-starter dependency

  • Springfox 3.x removes dependencies on guava and other 3rd party libraries (not zero dep yet! depends on spring plugin and open api libraries for annotations and models) so if you used guava predicates/functions those will need to transition to java 8 function interfaces.

此版本的亮点:

  • Spring5,Webflux支持(仅支持请求映射,尚不支持功能端点)。

  • Spring Integration支持(非常感谢反馈)。

  • SpringBoot支持springfox Boot starter依赖性(零配置、自动配置支持)。

  • 具有自动完成功能的文档化配置属性。

  • 更好的规范兼容性与2.0。

  • 支持OpenApi 3.0.3。

  • 零依赖。几乎只需要spring-plugin,swagger-core ,现有的swagger2注释将继续工作并丰富openapi3.0规范。

兼容性说明:

  • 需要Java 8

  • 需要Spring5.x(未在早期版本中测试)

  • 需要SpringBoot 2.2+(未在早期版本中测试)

注意:

应用主类增加注解@EnableOpenApi,删除之前版本的SwaggerConfig.java。

启动项目,访问地址:http://localhost:8080/swagger-ui/index.html,注意2.x版本中访问的地址的为http://localhost:8080/swagger-ui.html

整合使用

Maven项目中引入springfox-boot-starter依赖:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>
12345

application.yml配置

spring:
  application:
    name: springfox-swagger
server:
  port: 8080

# ===== 自定义swagger配置 ===== #
swagger:
  enable: true
  application-name: ${spring.application.name}
  application-version: 1.0
  application-description: springfox swagger 3.0整合Demo
  try-host: http://localhost:${server.port}
12345678910111213

使用@EnableOpenApi注解,启用swagger配置

@EnableOpenApi
@Configuration
public class SwaggerConfiguration {

}
12345

自定义swagger配置类SwaggerProperties

@Component
@ConfigurationProperties("swagger")
public class SwaggerProperties {
    /**
     * 是否开启swagger,生产环境一般关闭,所以这里定义一个变量
     */
    private Boolean enable;

    /**
     * 项目应用名
     */
    private String applicationName;

    /**
     * 项目版本信息
     */
    private String applicationVersion;

    /**
     * 项目描述信息
     */
    private String applicationDescription;

    /**
     * 接口调试地址
     */
    private String tryHost;

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getApplicationVersion() {
        return applicationVersion;
    }

    public void setApplicationVersion(String applicationVersion) {
        this.applicationVersion = applicationVersion;
    }

    public String getApplicationDescription() {
        return applicationDescription;
    }

    public void setApplicationDescription(String applicationDescription) {
        this.applicationDescription = applicationDescription;
    }

    public String getTryHost() {
        return tryHost;
    }

    public void setTryHost(String tryHost) {
        this.tryHost = tryHost;
    }
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768

一个完整详细的springfox swagger配置示例:

import io.swagger.models.auth.In;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.boot.SpringBootVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
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.oas.annotations.EnableOpenApi;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;

import java.lang.reflect.Field;
import java.util.*;

@EnableOpenApi
@Configuration
public class SwaggerConfiguration implements WebMvcConfigurer {
    private final SwaggerProperties swaggerProperties;

    public SwaggerConfiguration(SwaggerProperties swaggerProperties) {
        this.swaggerProperties = swaggerProperties;
    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30).pathMapping("/")

                // 定义是否开启swagger,false为关闭,可以通过变量控制
                .enable(swaggerProperties.getEnable())

                // 将api的元信息设置为包含在json ResourceListing响应中。
                .apiInfo(apiInfo())

                // 接口调试地址
                .host(swaggerProperties.getTryHost())

                // 选择哪些接口作为swagger的doc发布
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()

                // 支持的通讯协议集合
                .protocols(newHashSet("https", "http"))

                // 授权信息设置,必要的header token等认证信息
                .securitySchemes(securitySchemes())

                // 授权信息全局应用
                .securityContexts(securityContexts());
    }

    /**
     * API 页面上半部分展示信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title(swaggerProperties.getApplicationName() + " Api Doc")
                .description(swaggerProperties.getApplicationDescription())
                .contact(new Contact("lighter", null, "123456@gmail.com"))
                .version("Application Version: " + swaggerProperties.getApplicationVersion() + ", Spring Boot Version: " + SpringBootVersion.getVersion())
                .build();
    }

    /**
     * 设置授权信息
     */
    private List<SecurityScheme> securitySchemes() {
        ApiKey apiKey = new ApiKey("BASE_TOKEN", "token", In.HEADER.toValue());
        return Collections.singletonList(apiKey);
    }

    /**
     * 授权信息全局应用
     */
    private List<SecurityContext> securityContexts() {
        return Collections.singletonList(
                SecurityContext.builder()
                        .securityReferences(Collections.singletonList(new SecurityReference("BASE_TOKEN", new AuthorizationScope[]{new AuthorizationScope("global", "")})))
                        .build()
        );
    }

    @SafeVarargs
    private final <T> Set<T> newHashSet(T... ts) {
        if (ts.length > 0) {
            return new LinkedHashSet<>(Arrays.asList(ts));
        }
        return null;
    }

    /**
     * 通用拦截器排除swagger设置,所有拦截器都会自动加swagger相关的资源排除信息
     */
    @SuppressWarnings("unchecked")
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        try {
            Field registrationsField = FieldUtils.getField(InterceptorRegistry.class, "registrations", true);
            List<InterceptorRegistration> registrations = (List<InterceptorRegistration>) ReflectionUtils.getField(registrationsField, registry);
            if (registrations != null) {
                for (InterceptorRegistration interceptorRegistration : registrations) {
                    interceptorRegistration
                            .excludePathPatterns("/swagger**/**")
                            .excludePathPatterns("/webjars/**")
                            .excludePathPatterns("/v3/**")
                            .excludePathPatterns("/doc.html");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121

一些常用注解说明

  • @Api:用在controller类,描述API接口

  • @ApiOperation:描述接口方法

  • @ApiModel:描述对象

  • @ApiModelProperty:描述对象属性

  • @ApiImplicitParams:描述接口参数

  • @ApiResponses:描述接口响应

  • @ApiIgnore:忽略接口方法

示例

项目Demo:springfox-swagger

效果图:

example

参考

  • 在 Spring Boot 项目中使用 Swagger 文档

  • Springfox 3.0.0(包含springfox-swagger2-3.0.0)即OpenAPI 3的发布与系统集成



欢迎加入我的知识星球,一起探讨架构,交流源码。加入方式,长按下方二维码噢:

已在知识星球更新源码解析如下:

最近更新《芋道 SpringBoot 2.X 入门》系列,已经 20 余篇,覆盖了 MyBatis、Redis、MongoDB、ES、分库分表、读写分离、SpringMVC、Webflux、权限、WebSocket、Dubbo、RabbitMQ、RocketMQ、Kafka、性能测试等等内容。

提供近 3W 行代码的 SpringBoot 示例,以及超 4W 行代码的电商微服务项目。

获取方式:点“在看”,关注公众号并回复 666 领取,更多内容陆续奉上。

兄弟,艿一口,点个赞!????

Odin - Inspector and Serializer v3.0.3.unitypackage ☄️ OdinInspector.com:了解 Odin Inspector 的一切。 ☄️ 手册:快速入门 ☄️ 支持:提交任何问题 ☄️ 路线图:下一步是什么? 在 2019 年 5 月 28 日之前购买了 Odin?从 https://odininspector.com/download 免费获得 Odin 源代码和验证器插件 Odin 能够完美部署到原有的工作流程中,无需费力的集成工作,让您能够序列化任何内容,并使用 80 多个全新检测器属性、无样板代码和更多功能来使用 Unity! 看看 2.1 版有什么更新! ☄️ 亮点 ☄️ - 轻松集成 - 纯编辑器模式 - Odin 编辑器窗口 - 输入验证 - 序列化任何对象 - 强大的列表 - 惊人的扩展性 - 调色板 - 字典 - 还有更多! · 轻松集成: Odin 很容易操作,并且不会打破你的已有工作流程。实际上你甚至不需要继承任何东西,也就是说你的现有编辑器将继续与 Odin 适用。 · 纯编辑器模式: 仅使用 Odin 的编辑器改进,完全禁用序列化。 · Odin 编辑器窗口: 您现在可以使用 Odin 来快速创建自定义的编辑器窗口,帮助组织您的项目和游戏数据。 · 输入验证: 通过允许您的开发者设置场景和输入验证来赋能您的整个团队,让 Unity 的使用对艺术家和开发者来说变得前所未有的容易。 · 序列化任何对象: Odin 使用我们评级很高的自定义序列化协议,让您既可以继承我们的 SerializedBehaviour、SerializedScriptableObject 等,也可以为您已有的类添加几行新代码,让可以序列化的任何内容都得到序列化。是的,甚至是多态类型! 在 2018.3 以上版本中,Odin 序列化的预制件由于嵌套的预制系统而被弃用。 · 功能强大的列表: 所有实现 Microsoft IList 接口的数组和列表均由我们强大的列表绘制器绘制; 拖放、插入和删除单个项目、多维数组、表、交叉列表,甚至是跨窗口的项目拖动、分页、嵌套列表绘制和更多! · 惊人的可扩展性: 强大而灵活的 API 让你轻易扩展和修改检查器的绘制方式。快速创建全新的属性组类型和自定义绘画器! • 更多内容! Odin 还添加了词典、自定义布局、资源列表、值下拉列表、嵌入式编辑器、调色板,甚至更多内容! ☄️平台支持 ☄️ 功能丰富且得到优化的 Odin 序列化器支持: - 桌面 - Android - iOS - WebGL - PlayStation - Xbox - Nintendo Switch - Oculus - 所有的 IL2CPP 平台 - UWP 仅得到 IL2CPP 后端的支持 ☄️ 实用链接 ☄️ - 文档 - 路线图 - 社区 - 问题跟踪器 - 发行说明 - 网站 - 支持 ☄️社区 ☄️ 加入 Discord 中的讨论,获取对任何问题的支持和解答。 Odin 处于不断开发的阶段中,该论坛有助于让我们确定接下来应向 Odin 添加哪些新功能。因此请与我们分享您的建议,或者与其他社区成员的建议达成一致。 举报该资源 Odin - Inspector and Serializer 立即下载

相关推荐

专治疑难系列 - 解决打印机凭证冲突问题

一、问题描述 二、解决方法 三、问题已解决

Passerby_Wang的博客 2万+

3.0.3版本发行说明

openGauss 3.0.3 版本是基于3.0.0的补丁版本,总体特性、接口与3.0.0保持一致。在3.0.0版本的基础上,进行了缺陷修复,以及主干分支部分特性回合。

2401_83143557的博客 1480

Oracle19c安装,基本配置教程(超详细)

安装有出错的风险,卸载也是比较麻烦的,所以先提前设置一个还原点,在windows中的步骤如下,如果对自己有信心,可以直接跳过该部分开始安装oracle在设置中进入创建还原点的界面开始创建还原点上面已经成功创建了还原点,如果安装oracle时出现问题,自己也无法解决,恢复到安装之前即可,恢复步骤如下经过上面的步骤,Oracle我们就能够正常使用了,我们就使用自己在sql plus里面创建的账号即可,创建的表会默认存放在我们自己创建的表空间里面。

秃头披风侠的博客 7万+

在spring官网上下载spring的jar包及API文档

1.在浏览器搜索spring,进入spring官网 2.在spring官网里面点击PROJECTS 3.点击SPRING FRAMEWORK 4.点击 “猫” 5.在中间找到Downloading Artifacts下面的downloading Spring artifacts,点击进入。 6.在下面找到Manually doenloading S

Mao的博客 5951

OpenMontage:AI代理驱动的端到端视频生产系统实战指南

在当今内容创作领域,自动化视频生成技术正成为提升生产效率的关键。其核心原理在于通过智能体(Agent)架构,将复杂的视频制作流程拆解为可被AI理解和执行的标准化任务,从而实现从创意到成片的端到端自动化。这项技术的核心价值在于大幅降低了专业视频制作的门槛,使非专业用户也能快速产出具有一定专业度的内容。其典型应用场景包括社交媒体短片、产品演示、知识科普视频的批量生产。OpenMontage正是这一技术理念的杰出实践,它构建了一个完整的代理驱动视频生产系统,将AI编码助手转变为能自主规划并执行脚本撰写、素材检索、

weixin_35757191的博客 649

Ubuntu系统下主板GPU温控pwm风扇

在Linux系统下——以Ubuntu为例,配置主板sys_fan等接口连接pwm温控风扇转速根据NVIDIA GPU温度,为服务器GPU等无主动散热显卡提供散热。

罗思哲的博客 5040

CentOS 安装hadoop3.0.3 版本踩坑

坑坑坑,全是坑 1、but there is no HDFS_NAMENODE_USER defined. Aborting operation. [root@xcff sbin]# ./start-dfs.sh Starting namenodes on [localhost] ERROR: Attempting to operate on hdfs namenode as root E...

poem_2010的博客 1442

AudioTrack音频播放流程深度解析

深入解析Android AudioTrack音频播放的完整链路:从Java API到Native层,从共享内存Ring Buffer机制到FAST Track低延迟优化,配合源码分析带你彻底搞懂Android音频播放的底层原理

Cheson的专栏 942

Mac Mouse Fix 3.0.3版本授权验证故障分析

Mac Mouse Fix是一款针对macOS系统的鼠标增强工具,其3.0.3版本出现了一个影响用户体验的关键问题:用户在购买授权后无法成功完成验证。具体表现为用户在尝试验证授权时,系统错误地提示"请确保您的计算机在线后重试验证授权",而实际上用户的网络连接是正常的。 ## 技术背景 这类授权验证问题通常涉及以下几个技术环节: 1. **授权验证机制**:软件需要与服务器通信验证授权的有效性 ...

gitblog_07913的博客 1244

PVE 8.0 保姆级换源教程:从Debian到LXC仓库,一次搞定国内镜像(附弹窗去除)

本文提供PVE 8.0保姆级换源教程,涵盖从Debian基础源到LXC仓库的国内镜像配置,并附赠去除订阅弹窗的实用技巧。通过详细步骤和命令示例,帮助用户快速优化ProxmoxVE环境,提升下载速度并消除干扰提示,适用于虚拟化平台的高效管理。

weixin_33282146的博客 414

微信电脑版本不会自动下载图片吗?——没有找到解决方法。——只会默认下载doc等文件,图片不行,需要自己另存为——有什么办法解决吗?

微信电脑版本不会自动下载图片吗?——没有找到解决方法。——只会默认下载doc等文件,图片不行,需要自己另存为——有什么办法解决吗?此外,用户还可以选择将接收到的图片、视频和文件保存到指定的文件夹中。‌用户可以在微信设置中调整这一设置。

qq_15963745的博客 5096

Swagger(丝袜哥)3.0 官方 Starter 终于出了,真的香吗?!

点击上方“芋道源码”,选择“设为星标”管她前浪,还是后浪?能浪的浪,才是好浪!每天 8:55 更新文章,每天掉亿点点头发...源码精品专栏原创 | Java 2020 超神之路,很肝~...

芋艿V 551

Android 12.0 kenel中修改rom系统内部存储的大小

在12.0的系统rom产品开发定制中,在对一些产品开发中的配置需求方面,由于在产品后续订单中,有些产品是出口的,但是硬件方面已经定板,时间比较仓促,所以 就需要软件方面在rom内部存储的大小方面作假,修改rom真实的大小容量,所以就需要在kenel驱动部分来修改这部分的值最好了,接下来分析下计算rom容量的 相关代码,然后做出相关的修改,来实现功能

安卓兼职framework和app工程师的博客 1678

Swagger 3.0 官方教材出炉,野生的可以扔了!

点击“开发者技术前线”,选择“星标????”让一部分开发者看到未来链接:blog.csdn.net/wangzhihao1994/article/details/108408420开始之...

开发者技术前线-DevolperFront 1333

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

dubbo2.7.9升级到dubbo3.0.7+nacos1.4.3+springboot2.6.6成功实践笔记

升级过程中遇到一堆的坑,不过都一一解决了,主要是版本冲突,启动失败 以下是正确配置: springboot依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.6</version>

5859

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

SpringFox 3尝鲜 集成SpringBoot生成Swagger接口文档

SpringFox简介 SpringFox是一个开源的API Doc的框架, 它的前身是swagger-springmvc,可以将我们的Controller中的方法以文档的形式展现。官方定义为:Automated JSON API documentation for API's built with Spring。 SpringFox3快速应用 maven项目依赖 <dependency> <groupId>io.springfox</groupI...

在每次的突破中遇见更好的自己 4124

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Firefly 3.0.3 发布,Java 的 Web 框架

Firefly 3.0.3 稳定版发布,Firefly 3.0.3 修复了20多处bug,增强了框架的性能,并提供了更完善的文档和例子程序,文档地址:http://www.fireflysource.com/docs/firefly-guide.html 。 现在Firefly已经提交到Apache Central Repository: ? 1

xinghuifu203的专栏 622

Spring Framework 3.0.3是一个经过几周微调并结合社区反馈后发布的版本

Spring Framework 3.0.3 是 Spring 框架的一个维护性小版本(maintenance release),发布于 2010 年 9 月左右。它并非“经过几周微调”后发布的全新重大版本,而是对 3.0.x 系列的稳定性与兼容性修复版本,主要包含: - 修复了 3.0.0–3.0.2 中发现的关键 Bug(如 AOP、Web MVC、JDBC、事务管理等模块的问题); - 增强了与 Java EE 6(如 Servlet 3.0)、JDK 6+ 的兼容性; - 集成社区反馈,提升文档和

[Blog][Domain] programb.blog.youkuaiyun.com 730

探索CSerialPortV3.0.3:高效稳定的串口通信解决方案

探索CSerialPortV3.0.3:高效稳定的串口通信解决方案 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 CSerialPortV3.0.3是一款专为串口通信设计的类库,经过精心更新和修正,旨在为开发者提供一个更加稳定、高效的串口通信工具。该版本发布于2018年6月21日,针对之前版本中的关键问题进行了深入的修复和功能增强,确保了在各种应用场景下的可靠性和性能...

gitblog_09796的博客 429

Spring 3.0.3 is Now Available

Releases Adam Fitzgerald June 16, 2010 Juergen Hoeller has announced that Spring 3.0.3 is now available. This minor release addresses over 100 minor issues and catches up with some recent third-party releases. Download | Documentation | Javadoc API | Chang

[Blog][Domain] programb.blog.youkuaiyun.com 570

Odin - Inspector and Serializer v3.0.3

Odin - Inspector and Serializer v3.0.3 去发现同类优质开源项目:https://gitcode.com/ Unity游戏序列化编辑器插件Odin - Inspector and Serializer v3.0.3,这是一款功能强大的Unity编辑器插件,可以帮助开发者更加高效地进行序列化和数据检查。 Odin插件提供了一个直观、易用的界面,让开发者可以轻松地自...

gitblog_06769的博客 476
上一篇: IDEA 调试技巧,比 Eclipse 强太多了!
下一篇: 拒绝 kill -9,让 SpringBoot 优雅停机!
公众号-芋道源码
博客等级 码龄10年 1636粉丝 377原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值