谷歌助力,快速实现 Java 应用容器化

稀疏注意力机制:DeepSeek 如何用算法创新打破大模型成本瓶颈 在自然语言处理和代码生成领域,Transformer 架构的注意力机制是核心组件,但其计算复杂度与序列长度的平方成正比,导致处理长上下文时算力与显存需求急剧上升,形成了高性能、长上下文与低成本之间的“不可能三角”。稀疏注意力机制通过算法创新,将计算模式从“全员大会”转变为高效的“小组讨论”,仅计算局部窗口和关键全局token之间的关联,从而将复杂度近似降至线性。这项技术价值在于,它从架构层面重塑了计算范式,使得在保持模型关键能力的前提下,大幅降低了训练和推理的资源消耗。其应用场景广泛,尤其适合需要处理长代码 阅读详情

 

Google 在 2018 年下旬开源了一款新的 Java 工具 Jib,可以轻松地将 Java 应用程序容器化。通过 Jib,我们不需要编写 Dockerfile 或安装 Docker,通过集成到 Maven 或 Gradle 插件,就可以立即将 Java 应用程序容器化。

 

一、什么是 Jib

Jib 是一个快速而简单的容器镜像构建工具,它作为 Maven 或 Gradle 的一部分运行,不需要编写 Dockerfile 或运行 Docker 守护进程。它从 Maven 或 Gradle 中构建我们的 Docker 镜像, 并只将发生变更的层(而不是整个应用程序)推送到注册表来节省宝贵的构建时间。现在,我们对 Docker 构建流程和 Jib 构建流程进行对比。Docker 构建流程,如下所示。

 

Jib 构建流程,则是这样的。

 

二、实战出真知

1. 构建一个简单的 Java 工程

我们编写一个简单的 Java 类。

 
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); System.out.println("http://blog.720ui.com"); } } 

紧接着,我们再创建一个 pom.xml 文件。

 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.lianggzone.sample.lib</groupId> <artifactId>helloworld-samples</artifactId> <version>0.1</version> <packaging>jar</packaging> <name>helloworld-samples</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <jib-maven-plugin.version>1.0.2</jib-maven-plugin.version> <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> </properties> <dependencies> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!-- Jib --> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>${jib-maven-plugin.version}</version> <configuration> <from> <image>registry.cn-hangzhou.aliyuncs.com/lianggzone/oracle_java8</image> </from> <to> <image>registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-helloworld:v1</image> </to> <container> <jvmFlags> <jvmFlag>-Xms512m</jvmFlag> <jvmFlag>-Xdebug</jvmFlag> </jvmFlags> <mainClass>com.lianggzone.HelloWorld</mainClass> </container> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 

由于默认访问谷歌的 gcr.io 仓库,而国内访问 gcr.io 不稳定会经常导致网络超时,所以笔者使用了国内的阿里云镜像服务,那么就不需要访问谷歌的仓库了。现在,我们执行 mvn compile jib:build 命令进行自动化构建,它会从 <from> 拉取镜像,并把生成的镜像上传到 <to> 设置的地址。这里,笔者还通过 ` 设置了一些 JVM 参数。

 
mvn compile jib:build 

此外,如果”登录失败,未授权”,需要通过 docker login 登录鉴权一下。此外,更好的做法是,你可以考虑在Maven 中放置凭据。

 
<settings> ... <servers> ... <server> <id>registry.cn-hangzhou.aliyuncs.com</id> <username>你的阿里云账号</username> <password>你的阿里云密码</password> </server> </servers> </settings> 

最后,执行完成后,我们可以在阿里云镜像仓库获取镜像。

 

大功告成,现在,我们来验证一把。我们通过 docker pull 拉取镜像,并运行。

 
docker pull registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-helloworld:v1 docker run --name jib-helloworld -it registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-helloworld:v1 /bin/bash 

执行结果,如下所示。

 

2. 构建一个 SpringBoot 的可运行 Jar

我们来一个复杂一些的项目,构建一个 SpringBoot 的项目。关于 SpringBoot 的使用,可以阅读笔者之前的文章: http://blog.720ui.com/columns/springboot_all/ 。现在,我们首先需要搭建一个工程,并创建一个启动类。

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

同时,需要一个 Web 的接口。

 
@RestController public class WebController { @RequestMapping("/blog") public String index() { return "http://blog.720ui.com"; } } 

紧接着,我们再创建一个 pom.xml 文件。

 
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> </parent> <groupId>com.lianggzone.sample.lib</groupId> <artifactId>springboot-samples</artifactId> <version>0.1</version> <packaging>jar</packaging> <name>springboot-samples</name> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <jib-maven-plugin.version>1.0.2</jib-maven-plugin.version> <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin.version}</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <!-- Jib --> <plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>${jib-maven-plugin.version}</version> <configuration> <from> <image>registry.cn-hangzhou.aliyuncs.com/lianggzone/oracle_java8</image> </from> <to> <image>registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-springboot:v1</image> </to> <container> <jvmFlags> <jvmFlag>-Xms512m</jvmFlag> <jvmFlag>-Xdebug</jvmFlag> </jvmFlags> </container> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 

现在,我们执行 mvn compile jib:build 命令进行自动化构建。执行完成后,我们可以在阿里云镜像仓库获取镜像。

 

现在,我们再来验证一把。我们通过 docker pull 拉取镜像,并运行。

 
docker pull registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-springboot:v1 docker run -p 8080:8080 --name jib-springboot -it registry.cn-hangzhou.aliyuncs.com/lianggzone/jib-springboot:v1 /bin/bash 

执行结果,如下所示。

 

现在,我们访问 http://localhost:8080/blog ,我们可以正常调用 API 接口了。

 

3. 构建一个 WAR 工程

Jib 还支持 WAR 项目。如果 Maven 项目使用 war-packaging 类型,Jib 将默认使用 distroless Jetty 作为基础镜像来部署项目。要使用不同的基础镜像,我们可以自定义 <container><appRoot> , <container> <entrypoint> 和 <container> <args> 。以下是使用 Tomcat 镜像的案例。

 
<configuration> <from> <image>tomcat:8.5-jre8-alpine</image> </from> <container> <appRoot>/usr/local/tomcat/webapps/ROOT</appRoot> </container> </configuration>

喜欢的点点关注,点点赞。

对Java技术,架构技术感兴趣的同学,欢迎加QQ群585550789,一起学习,相互讨论。

群内已经有小伙伴将知识体系整理好(源码,笔记,PPT,学习视频),欢迎加群领取。

 

jibDockerBuild发生Unauthorized for registry-1.docker.io/library/openjdk 项目场景: 在使用gradlew :jibDockerBuild 构建项目镜像时发生错误jibDockerBuild发生Unauthorized for registry-1.docker.io/library/openjdk 问题描述: 项目中使用了如下: @Override public void run() { bytes = mmInStream.read(buffer); mHandler.obtainMessage(READ_DA 阅读详情

相关推荐

ADS122U04IPWR+PIC18F8722工业温度采集系统设计

温度采集是工业测控的基础环节,其核心在于高精度ADC与可靠MCU的协同——既要抑制热电偶微伏级信号的本底噪声,又要保障宽温、强干扰环境下数据采集的确定性与时序稳定性。ADS122U04IPWR凭借24位ΔΣ架构、集成低温漂基准与PGA,显著提升信噪比和冷端补偿精度;PIC18F8722则以硬件PWM恒流源、自动地址识别USART等特性,实现低纹波激励与高效RS485多节点通信。该组合在HVAC、制药灭菌、窑炉监控等场景中验证了-40℃~85℃长期运行的鲁棒性,适用于需复用老平台、严控BOM成本且拒绝复杂软件

weixin_34205826的博客 340

google java 开源_谷歌开源Java镜像构建工具Jib

容器的出现让Java开发人员比以往任何时候都更接近“编写一次,到处运行”的工作流程,但要对Java应用程序进行容器化并非易事:你必须编写Dockerfile,以root身份运行Docker守护进程,等待构建完成,最后将镜像推送到远程注册中心。但并非所有的Java开发人员都是容器专家,像以前那样只需要构建一个JAR包的日子已经结束了吗?为了应对这一挑战,谷歌开源了一个Java容器化工具Jib,有了这...

weixin_35632603的博客 370

1、云、大数据与Spring Boot:构建企业级应用的技术指南

本文深入探讨了云技术、大数据处理及Spring Boot框架在企业级应用开发中的应用。从云与大数据的现状与挑战出发,介绍了数据科学、云特性与基础设施,以及构建企业级应用所需的关键工具与技术。通过对比传统Spring框架与Spring Boot,展示了Spring Boot在简化开发、支持云原生方面的优势,并结合示例演示了如何使用Spring Boot创建高效、可扩展的应用。文章适合希望了解现代企业应用开发技术的开发者和架构师。

peach的博客 134

Google开源其Java容器化工具Jib,简化镜像构建全流程

作者|Appu Goundan、Qingyang Chen编辑|无明容器的出现让 Java开发人员比以往任何时候都更接近“编写一次,到处运行”的工作流程,但要对 Java应用程序进行容器化并非易事:你必须编写 Dockerfile,以 root身份运行 Docker守护进程,等待构建完成,最后将镜像推送到远程注册中心。但并非所有的 Java开发人员都是容器专家,像以前那样只需要构建一个 JAR包的...

varyall的专栏 3385

Eclipse Google Cloud 插件

Google 云 Eclipse 插件

嵌入式接口通识知识之PCIe接口

PCIe x1接口是最常见的一种,插槽的长度是最短的,仅有25mm。PCIe x4接口有四个数据通道,提供比x1接口更高的带宽,插槽的长度为39mm,分为前后两组,一组22根针脚用于供电,剩下的42根针脚是数据针脚。插槽全长89mm,有164根针脚,分为前后两组,较短的插槽有22根针脚,主要用于供电,较长的插槽142根,主要用于数据传输,具有16通道所带来的高带宽。PCIe x8接口有八个数据通道,插槽全长56mm,有98跟针脚,分为前后两组,较短的22根针脚用于供电,剩下的76根针脚是数据针脚。

2301_76587520的博客 1323

java 容器_谷歌助力,快速实现 Java 应用容器化

Google 在 2018 年下旬开源了一款新的 Java 工具 Jib,可以轻松地将 Java 应用程序容器化。通过 Jib,我们不需要编写 Dockerfile 或安装 Docker,通过集成到 Maven 或 Gradle 插件,就可以立即将 Java 应用程序容器化。一、什么是 JibJib 是一个快速而简单的容器镜像构建工具,它作为 Maven 或 Gradle 的一部分运行,不需要编写...

weixin_39840235的博客 278

Echats-wordcloud 文字云图的踩坑点【Unknown series wordCloud】

一直都是报 【ECharts Unknown series wordCloud】这玩意可能要刷脸,祝你好运吧~

Sky_Bug的博客 2424

‌谷歌云代理商:什么是‌谷歌云计算?

是谷歌提供的云计算服务,旨在帮助企业、开发者和组织通过互联网访问谷歌的全球基础设施和先进技术。谷歌云计算提供了广泛的计算、存储、数据库、人工智能(AI)、机器学习(ML)、网络和安全服务,帮助用户构建、部署和管理应用程序。

feixiangdeniao1的博客 1591

从ORCAP-1589警告看Cadence ORCAD的DRC设置:如何避免‘网络别名’引发的潜在短路风险

本文深入解析Cadence ORCAD中ORCAP-1589警告的深层含义,探讨网络别名可能引发的短路风险及DRC设置优化方案。通过分析网络别名的设计意图、DRC规则配置及最佳实践,帮助工程师有效规避设计风险,提升电路设计的可靠性和规范性。

weixin_34194829的博客 306

深入解析公网IP与内网IP:NAT技术原理与实战配置指南

IP地址是互联网通信的基础,它作为网络设备的唯一逻辑标识,负责数据包的寻址与路由,是实现端到端通信的核心。其工作原理基于互联网协议,通过源地址和目的地址的匹配,确保信息在全球网络中准确传递。理解IP地址的技术价值在于,它是构建稳定网络应用、实现服务互联互通的前提,尤其在云计算、微服务架构和物联网场景中至关重要。在实际应用中,开发者常面临内外网访问、服务部署和网络调试等挑战,这通常涉及公网IP与内网IP的区分以及NAT(网络地址转换)技术的运用。NAT作为连接私有网络与公共互联网的关键桥梁,通过端口映射和地址

weixin_34332905的博客 407

要闻君说:谷歌云重磅发布两大技术平台;以后可以打飞滴了?SAP重组动荡;微软宣布 Azure Functions 支持 Java...

关注并标星星CSDN云计算极客头条:速递、最新、绝对有料。这里有企业新动、这里有业界要闻,打起十二分精神,紧跟fashion你可以的!每周三次,打卡即read更快、更全了...

CSDN业界要闻 513

数字IC后端手把手实战教程 | Innovus verify_drc VIA1 DRC Violation解析及脚本自动化修复方案

数字IC后端实战项目案例之Innovus verify_drc DRC Violation脚本自动化修复方案

weixin_37584728的博客 4079

全球各大科技公司竟然都在做这件事情!

全球四千多个企业,包括谷歌,苹果,Netflix,甲骨文,腾讯,华为,京东,滴滴出行,小米,去哪儿,招商银行等等,都在使用 JFrog Artifactory 作为企业级持续交付平台,实现快速发布。JFrog Artifactory 开源版已经有10万+的企业用户量。 ​ JFrog Artifactory 是风靡全球的一站式 DevOps 平台,它支持所有语言(Maven,Docker,NPM ...

cheke7682的博客 202

【Nordic实战】nRF54L15引脚规划:电源域、专用引脚与低功耗设计避坑指南

本文深入解析Nordic nRF54L15芯片的引脚规划策略,重点阐述其基于电源域(MCU域、PERI域、LP域)的GPIO分配原则。文章提供了从思维转变到实战避坑的完整指南,强调遵循专用引脚与域对应关系是实现超低功耗设计的关键,并分享了系统化的引脚规划流程与工具使用建议。

weixin_29192141的博客 328

基于RK3588平台的高分辨率多摄像头系统深度优化:从48M单摄到双摄分时复用的完整解决方案

本文深入解析了RK3588平台的高分辨率摄像头实现方案。重点介绍了:1)RK3588的MIPI PHY硬件架构,包括DCPHY和DPHY的资源配置及工作模式;2)双ISP合成技术,通过并行处理提升48M高分辨率图像的处理能力;3)以OV50C40传感器为例,详细展示了48M单摄系统的硬件连接、I2C设备配置和关键参数设置。文章为开发者提供了从硬件连接到软件配置的完整技术方案,有助于实现高性能嵌入式视觉系统。

FJN110的博客 680

国际版JAVA同城外卖跑腿团购到店多合一APP系统源码:全场景本地生活可商用

本文介绍了一套基于JAVA开发的国际版同城多合一服务系统,整合外卖、跑腿、团购和到店服务。系统采用前后端分离架构,支持多语言切换、跨境支付和时区适配,满足国际市场需求。核心优势包括:四业务深度融合、企业级JAVA架构保障稳定性、全流程闭环管理、多元变现模式。系统适用于海外华人社区、国际商圈等场景,为创业者提供一站式本地生活解决方案。通过多端协同和智能调度,实现用户、商家、跑腿员和管理员的高效联动,助力平台快速实现全球化部署和商业化运营。

m0_73514975的博客 317

手把手教你学Simulink——基于电机驱动系统的场景实例:轮毂电机在电动汽车中的分布式驱动控制仿真

本文详细介绍了基于MATLAB/Simulink和Simscape Electrical的电动汽车轮毂电机分布式驱动控制系统建模方法。内容包括系统结构设计(轮毂电机、逆变器、控制器等模块)、完整的建模过程(从基础模块导入到车辆动力学建模)、控制器设计与转矩分配策略实现,以及仿真参数设置与结果分析。通过仿真验证了该分布式驱动系统在速度跟踪、转弯性能等方面的优异表现,为电动汽车驱动系统的研究与开发提供了有效的仿真验证平台。文中还提供了相关代码示例和资料推荐,是学习Simulink电机控制系统建模的实用指南。

MHD0815的博客 4922

云原生概念你了解多少

CNCF-云原生计算基金会,2015年由谷歌牵头成立,充分利用云的分布式和弹性特点,Cloud Native云原生应用的三大特征。容器化封装、动态管理:通过集中式的编排调度系统来动态的管理和调度。面向微服务:明确服务间的依赖,互相解耦。云原生以容器、微服务、DevOps等技术为基础为代表的敏捷基础架构组成,用于帮助企业快速、持续、可靠、规模化的交付业务软件,云原生需要考虑是从开发-测试-运维一体化的需求。

itxiaoshen博客 434

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

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

收藏!Java程序员转AI大模型:从入门到进阶的完整指南

AI大模型不是“替代程序员”,而是“赋能程序员”,Java程序员转型大模型,不是“放弃过去”,而是“升级未来”。你不需要成为算法专家,只需做好“Java基础+AI工具+实战项目”的组合,就能在新赛道中脱颖而出。与其在Java内卷中焦虑,不如花1-2个月打好AI基础,用一个实战项目开启转型之路。

python12345_的博客 712

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

上一篇: 什么是JPA?Java Persistence API简介
下一篇: 学会这招,你离黑客又进了一步?
java1856905
博客等级 码龄8年 100粉丝 249原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址