微服务SpringCloud开弓之Eureka服务注册与发现《三》

半监督的医学分割数据集(LA, Pancreas, ACDC和PROMISE12)分享 这篇文章提供了四个常用的半监督医学分割数据集,所有数据集都已经被处理成了.h5文件。下载之后就可以直接使用 阅读详情

1、Eureka基础知识

  • 什么是服务治理

在这里插入图片描述

  • 什么是服务注册

在这里插入图片描述

在这里插入图片描述

  • Eureka两组件

在这里插入图片描述

2、单机Eureka构建步骤

  • IDEA生成EurekaServer端服务注册中心

    • 建Module

      cloud-eureka-server7001

    • 改POM

        <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
      
    • 写YML

      eureka:
        instance:
          hostname: localhost #eureka服务端的实例名称
        client:
          #false表示不向注册中心注册自己
          register-with-eureka: false
          #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
          fetch-registry: false
          service-url:
            #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
            defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
      
    • 主启动

      @SpringBootApplication
      @EnableEurekaServer
      public class EurekaMain7001 {
          public static void main(String[] args) {
              SpringApplication.run(EurekaMain7001.class,args);
          }
      }
      

    测试

    • http://localhost:7001/
      在这里插入图片描述
  • IDEA生成Eurekaclient端注册到服务端

    • 配置Pom

         <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
              </dependency>
      <dependency>
      
    • yam

      eureka:
        client:
          #false表示不向注册中心注册自己
          register-with-eureka: true
          #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
          fetch-registry: true
          service-url:
            #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
           defaultZone: http://localhost:7001/eureka
      
    • 主启动

      @SpringBootApplication
      @EnableEurekaClient
      public class PaymentMain8001 {
          public static void main(String[] args) {
              SpringApplication.run(PaymentMain8001.class,args);
          }
      }
      
      • 测试

      1、先启动EurekaServer
      ​2、http://localhost:7001/
      3、测试
      在这里插入图片描述

    ​ 4、自我保护机制

在这里插入图片描述

注意

com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

yam的配置注意缩进以及空格问题

3、集群Eureka构建步骤

在这里插入图片描述

解决办法: 搭建Eureka注册中心集群,实现负载均衡+故障容错

互相注册,互相守望

  • 新建cloud-eureka-server7002

    参考cloud-eureka-server7001

  • 改POM

       <dependencies>
            <!--eureka-server-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
            <!--        引用自定义的api通用包,可以使用Payment支付Entity-->
            <dependency>
                <groupId>com.atguigu.springcloud</groupId>
                <artifactId>cloud-api-common</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <!--一般为通用配置-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
  • 修改映射配置

    1、修改映射配置添加hosts文件

    ​ 127.0.0.1 eureka7001.com

    ​ 127.0.0.1 eureka7002.com

    2、刷新hosts文件

    ​ ipconfig /flushdns

  • 配yml

    7001中的yaml

    server:
      port: 7001
    spring:
      application:
        name: cloud-eureka-service
    eureka:
      instance:
        # eureka服务端的实例名称
        hostname: eureka7001.com
      client:
        # false表示不向注册中心注册自己
        register-with-eureka: false
        # false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要检索服务
        fetch-registry: false
        service-url:
          # 设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
          defaultZone: http://eureka7002.com:7002/eureka/
    

    7002中的yaml

    server:
      port: 7002
    spring:
      application:
        name: cloud-eureka-service2
    eureka:
      instance:
        hostname:  eureka7002.com
      client:
        register-with-eureka: false
        fetch-registry: false
        service-url:
          defaultZone: http://eureka7001.com:7001/eureka/
    

    主启动

    @SpringBootApplication
    @EnableEurekaServer
    public class EurekaMain7002 {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaMain7002.class,args);
        }
    }
    

    将支付服务8001微服务发布到上面2台Eureka集群配置中

    • 配yaml
    
    eureka:
      client:
        #false表示不向注册中心注册自己
        register-with-eureka: true
        #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
        fetch-registry: true
        service-url:
          #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
    #      defaultZone: http://localhost:7001/eureka
          defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
    

    将订单服务80微服务发布到上面2台Eureka集群配置中

    • 配yaml
    server:
      port: 80
    
    spring:
      application:
        name:  Cloud-order-service
    eureka:
      client:
        #false表示不向注册中心注册自己
        register-with-eureka: true
        #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
        fetch-registry: true
        service-url:
          #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
          #      defaultZone: http://localhost:7001/eureka
          defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
    

    测试01

    • 先要启动EurekaServer,7001/7002服务
    • 再要启动服务提供者provider,8001
    • 再要启动消费者,80
    • http://localhost/consumer/payment/get/31

4、支付服务提供者8001集群环境搭建

  • 新建cloud-provider-payment8002

    参考cloud-provider-payment8001

  • 改POM

    与cloud-provider-payment8001相同

       <dependencies>
            <!--        eureka-client-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
            <dependency>
                <groupId>com.atguigu.springcloud</groupId>
                <artifactId>cloud-api-common</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
            </dependency>
            <!--mysql-connector-java-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
  • YAML

    eureka:
      client:
        #false表示不向注册中心注册自己
        register-with-eureka: true
        #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
        fetch-registry: true
        service-url:
          #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
    #      defaultZone: http://localhost:7001/eureka
          defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
    
  • 主启动

@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8002 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8002.class,args);
    }
}
  • 业务类

    和8001一样

  • 修改8001/8002的controller

在这里插入图片描述

负载均衡

  • 订单服务访问地址不能写死

在这里插入图片描述

在这里插入图片描述

  • 使用@LoadBalanced注解赋予RestTemplate负载均衡的能力

    @Configuration
    public class ApplicationContextConfig {
    
        @Bean
        @LoadBalanced  //使用@LoadBalanced注解赋予RestTemplate负载均衡的能力
        public RestTemplate getRestTemplate(){
            return  new RestTemplate();
        }
    }
    
  • ApplicationContextBean

    Ribbon的负载均衡功能

  • 测试

在这里插入图片描述

5、actuator微服务信息完善

  • 主机名称:服务名称修改以及没有IP提示

    当前问题

在这里插入图片描述

修改cloud-provoder-payment8001、cloud-provoder-payment8001

eureka:
  client:
    #false表示不向注册中心注册自己
    register-with-eureka: true
    #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
    fetch-registry: true
    service-url:
      #设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个地址
#      defaultZone: http://localhost:7001/eureka
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
  instance:
    instance-id: payment8001\8002
    prefer-ip-address: true

效果

在这里插入图片描述

6、服务发现Discovery

对于注册eureka里面的微服务,可以通过服务发现来获得该服务的信息

  • 修改cloud-provider-payment8001的Controller

    import org.springframework.cloud.client.discovery.DiscoveryClient;
    @Resource
        private DiscoveryClient discoveryClient;
    
    
    
     @GetMapping(value = "/payment/discovery")
        public  Object discovery(){
    
            List<String> services = discoveryClient.getServices();
            for (String element : services) {
                log.info("########element:"+element);
            }
    
            List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PROVIDER-SERVICE");
            for (ServiceInstance instance : instances) {
                log.info(instance.getServiceId()+"\t"+instance.getHost()+"\t"+instance.getPort()+"\t"+instance.getUri());
            }
            return this.discoveryClient;
        }
    
  • 8001的启动类

    @SpringBootApplication
    @EnableEurekaClient
    @EnableDiscoveryClient
    public class PaymentMain8001 {
       public static void main(String[] args) {
           SpringApplication.run(PaymentMain8001.class,args);
       }
    }
    
  • 自测

    在这里插入图片描述

  • 结果
    在这里插入图片描述

6、eureka自我保护

  • 故障现象

在这里插入图片描述

  • 原因

在这里插入图片描述

一句话:某时刻 一个微服务不可用了,Eureka不会立刻清理,依旧会对该服务的信息进行保存

属于CAP里面的AP分支

  • 怎么禁止自我保护

    注册中心eurekaServer端7001

    • 出产默认,自我保护机制是开启的

      eureka.server.enable-self-preservation=true

    • 使用eureka.server.enable-self-preservation=false 可以禁用自我保护模式

在这里插入图片描述

自我保护机制关闭后的结果:

在这里插入图片描述

生产者客户端eurekaClient端8001

  • 默认

    eureka.instance.lease-renewal-interval-in-seconds=30
    eureka.instance.lease-expiration-duration-in-seconds=90
    
  • 配置

在这里插入图片描述

  • 测试

在这里插入图片描述
欢迎转载和分享,记得点赞呀

【图像拼接】源码精读:Parallax-Tolerant Unsupervised Deep Image Stitching(UDIS++) 注:Pytorch代码。【图像拼接论文精读】专栏对应文章【图像拼接】论文精读:Parallax-Tolerant Unsupervised Deep Image Stitching(UDIS++)配合对应的文章阅读,效果更佳!注:请重点关注代码段中的注释!!!有一些讲解的东西直接写在代码段的注释中了,同时多关注红色字体和绿色字体!!!我认为深度学习方法和传统方法有很多相似之处。比如:深度学习中的损失函数和传统方法中的对齐项、失真项等其实原理相同,只是求解方式不同。 阅读详情

相关推荐

ZYNQ专题-7020驱动KSZ9031 PHY芯片

之所以有这篇文章,得益于Alinx的开发板。

Anitawen的博客 4961

报错集--Mybatis相关

400: 403: 404: 405: 415: 500:

Sky306680478的博客 1095

工业级24V电源保护电路深度解析:五重防护机制详解

自恢复保险丝(PPTC,Positive Temperature Coefficient)是一种过流保护元件✅可恢复:过流后自动恢复,无需更换⚡响应快:电流超标立即动作🔄多次使用:在额定范围内可反复使用第1层(F1):阻挡过流 → 物理熔断第2层(D3):吸收浪涌 → 能量泄放第3层(Q1):防止反接 → 逻辑阻断第4层(Q2/Q3):抵御过压 → 主动切断第5层(CR):平滑启动 → 时序控制设计哲学:"让每一级保护专注做好一件事"通过这篇文章,我们深入理解了:✅自恢复保险丝。

qq_58068673的博客 3561

IDEA 配置文件 properties.load(inputstream) NullPOINTEXCEPTION:create breakpoint解决

NULLPOINTEXCEPTION:create breakpoint解决方法

weixin_48205264的博客 2763

python利用IQR方法与3σ方法进行异常值处理(含代码)

python利用IQR方法进行异常值处理

weixin_46713695的博客 2031

从 VS Code 创建 ABAP Development Objects,包、命名、传输请求和 Clean Core 的一条线打通

文章摘要: SAP ABAP开发工具正从传统SAP GUI/Eclipse向VS Code迁移,通过ABAP Development Tools扩展实现代码编辑、调试和传输管理。文章重点分析了创建ABAP对象背后的治理逻辑:1)对象创建涉及包结构、命名规范、传输层等关键设计决策;2)VS Code通过命令面板(Ctrl+Shift+P)提供统一创建入口;3)对象类型选择反映架构意图,应从业务模型角度规划;4)Package是重要的治理边界,需按业务能力分区;5)命名和描述需体现业务语义;6)传输请求标记对象

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 172

Java-NullPointerException异常的正确解决方法

Java-NullPointerException异常的正确解决方法

wgq2020的博客 405

RK3568平台开发系列讲解(外设篇)CAN的使用

📢 本篇章带大家快速了解CAN的使用。

内核笔记 2351

jdbc.properties 文件报空指针

java.lang.NullPointerExceptionCreatebreakpoint 空指针异常 方法一:将jdbc.properties 文件放在resources下 方法二:在文件的url后加 ?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

bobi8888的博客 559

ESP32-C3入门教程 蓝牙篇①——基于Blufi 的 WiFi 智能配网

文章目录一、前言二、WiFi配网方式三、快速运行四、运行效果五、ESP32-C3程序流程5.1 主程序5.2 回调函数5.3 SmartConfig线程5.4 流程图六、关键函数6.1 设置SmartConfig的协议类型6.2 启动SmartConfig6.3 停止SmartConfig七、其他八、参考 一、前言 本文基于VS Code IDE进行编程、编译、下载、运行等操作 基础知识点请查阅:ESP32-C3入门教程 基础篇①——基于VS Code构建Hello World 二、WiFi配网方式 W

7763

2026华为OD机试 新系统真题题库目录|机考题库 + 算法考点详解

华为OD机试 新系统真题题库目录|机考题库 + 算法考点详解华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2026e卷,od机试,2026E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2026华为od,如何备战华为od,华为od算法,华为od手撕代码,华为OD机试2024年最新题库,

KJ.JK 4680

无法命中当前断点

我是VS2020遇到的。如果也遇到这个问题了,而且你也把网上的方法都试过了,都没效果,那就请你看过来。 我是前后端分离的,每次调试都需要重新发布,我的发布地址在C盘,但是不知道谁把地址改成D盘签入了TFS,导致我拿到的最新代码是f新代码是发布在D盘,这样就导致我修改了代码发布打断点测试的时候一直提示无法命中当前断点。 所以如果你遇到的是这种问题,只需要把发布地址改成你前端访问的地址就可以了。 由这个案例可以联想到,其实大部分断点无效都是类似的原因:你真正需要调试的程序与你打断点的根本不是同一个,所.

BSX_null 332

AUTOSAR进阶图解==>AUTOSAR_SWS_ECUStateManager

AUTOSAR ECU State Manager 摘要 AUTOSAR ECU状态管理器(EcuM)是Classic Platform 4.4.0规范中的核心模块,负责管理ECU的整个生命周期,包括启动、运行、关机和睡眠等状态转换。EcuM通过协调各基础软件模块的初始化过程,确保系统可靠运行。 主要功能包括: 启动管理 - 控制从硬件初始化到应用运行的完整启动序列 状态转换 - 管理RUN/POST_RUN/SHUTDOWN等状态切换 唤醒验证 - 区分真实与虚假唤醒事件 关机序列 - 确保安全关机保存关

一名留德华的,康德的信徒的,专注于汽车电子领域的博客 2467

微服务SpringCloud开弓之Zookeeper服务注册与发现《四》

目录SpringCloud整合Zookeeper替代Eureka1、注册中心Zookeeper2、服务提供者3、服务消费者 Eureka停止更新了 地址 SpringCloud整合Zookeeper替代Eureka 1、注册中心Zookeeper 关闭Linux服务器防火墙后启动Zookeeper服务器 //临时关闭 service iptables stop //禁止开机启动 chkconf...

python_start的博客 269

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

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

微服务Springcloud开弓之框架搭建《一》

微服务体系 服务注册与发现 配置中心管理 服务调用 服务网关 服务熔断 服务监控 负载均衡 全链路跟踪 服务降级 自动化构建部署 服务消息队列 服务定时任务调度操作 对微服务的实现 Eureka : 服务注册与发现 Netelix Ribbon: 服务负载与调用 Netelix Feign: 服务负载与调用 Hystrix : 服务熔断与降级 Netelix Zuul : 服...

python_start的博客 481

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

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

微服务SpringCloud开弓之Ribbon负载均衡调用《六》

目录1、概述2、Ribbon负载均衡演示3、Ribbon核心组件IRule4、Ribbon负载均衡算法 1、概述 是什么 官网资料 ​ 地址 Ribbon目前也进入维护模式 用途 LB(负载均衡) - 集中式LB - 进程内LB 2、Ribbon负载均衡演示 架构说明 总结: Ribbon其实就是一个软负载均衡的客户端组件, 他可以和其他所需请...

python_start的博客 304

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

记录一个很离谱的shiro问题

Servlet.service() for servlet [dispatchernServlet] in context with path [] threw exception [Request processingfailed; nested exception is java.util.NoSuchElementException] with root cause

随便记一下 546

Bug记录(Java): 2.字符串比较

Bug缘由 今天写一个程序,其中有一个if判断语句用了if(s == “a”)发生了错误 Bug提示 Exception in thread “main” java.lang.NullPointerException Create breakpoint at Main.main(Main.java: 35) 这里现实为空指针异常 后来发现,我用来比较的s是类中的属性,而栈区中的String变量可以用==来比较,但堆区中的String变量需要用equals方法来比较,所以应该这样写才对: if(s.equ

weixin_43108378的博客 441

IDEA 配置文件properties文件放置位置 NullPointerException Create breakpoint

1.在使用IDEA创建java web项目时,连接数据库池需要配置properties文件。java获取配置文件代码时 Properties pro=new Properties(); InputStream resourceAsStream = DruidUtil.class.getClassLoader().getResourceAsStream("druid.properties"); System.out.println(resourceAsStre

zwy12321的博客 6448

常见报错问题解决方法

常见报错问题org.springframework.beans.factory.UnsatisfiedDependencyException Create breakpoint 问题

以为很难 317

idea开发eclipse创建的项目运行找不到路径

最近转java,用idea开发项目,原项目是用eclipse创建的,但是我用idea打卡一直找不到文件路径的错误,查找了一段时间,发现是System.getProperty("user.dir")获取的路径是根目录路径,因此需要对此修改 其次,修改Working directory为:$MODULE_DIR$ 点击OK,运行程序,成功! ...

qq_34516352的博客 972

SpringCloud使用zookeeper作为注册中心

从zookeeper的安装到springcloud项目搭建全过程

Anthony_sean的博客 994

SpringCloud服务注册中心——ZooKeeper

之前学习了使用Eureka作为服务注册中心,然而Eureka已经停更,这时候我们就需要新的技术来支撑服务注册中心,ZooKeeper也可以作为服务注册中心来注册服务。

Yellow_Star的博客 470

springboot 解决java.lang.ArrayStoreException

idea工具使用 Java Exception Breakpoint 添加异常断点,在IDE里,新建一个断点,类型是Java Exception Breakpoint   当断点起效时,查看AnnotationUtils.findAnnotation(Class&lt;?&gt;, Class&lt;A&gt;, Set&lt;Annotation&gt;) line: 686 函数的...

cnsu-cmh 9388

Eureka集群构建步骤

springcloud Eureka集群构建步骤

m0_62946761的博客 1万+

Eureka集群搭建教程

为了提升注册中心稳定性,防止注册中心宕机后,服务不可用的情况,我们可以通过将Eureka注册中心搭建成集群模式,当一台注册中心微服务宕机后,另一台依然可以支持服务的注册与发现。本文将讲解下如何搭建Eureka集群,以及相关的注意事项。本文介绍了两台服务器搭建Eureka集群的方法,以及注意事项,为了保证生产环境的稳定性,建议注册中心以集群方式搭建运行。

五道口 1489
上一篇: 微服务SpringCloud开弓之 Rest微服务工程搭建《二》
下一篇: 微服务SpringCloud开弓之Zookeeper服务注册与发现《四》
漂吧
博客等级 码龄8年 15粉丝 38原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值