kubectl源码分析之api-resources

Elasticsearch 报错 error At least one unigram is required but all tokens were ngrams 【代码】Elasticsearch 报错 error At least one unigram is required but all tokens were ngrams。 阅读详情

 欢迎关注我的公众号:

 目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:

istio多集群探秘,部署了50次多集群后我得出的结论

istio多集群链路追踪,附实操视频

istio防故障利器,你知道几个,istio新手不要读,太难!

istio业务权限控制,原来可以这么玩

istio实现非侵入压缩,微服务之间如何实现压缩

不懂envoyfilter也敢说精通istio系列-http-rbac-不要只会用AuthorizationPolicy配置权限

不懂envoyfilter也敢说精通istio系列-02-http-corsFilter-不要只会vs

不懂envoyfilter也敢说精通istio系列-03-http-csrf filter-再也不用再代码里写csrf逻辑了

不懂envoyfilter也敢说精通istio系列http-jwt_authn-不要只会RequestAuthorization

不懂envoyfilter也敢说精通istio系列-05-fault-filter-故障注入不止是vs

不懂envoyfilter也敢说精通istio系列-06-http-match-配置路由不只是vs

不懂envoyfilter也敢说精通istio系列-07-负载均衡配置不止是dr

不懂envoyfilter也敢说精通istio系列-08-连接池和断路器

不懂envoyfilter也敢说精通istio系列-09-http-route filter

不懂envoyfilter也敢说精通istio系列-network filter-redis proxy

不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager

不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册

 

————————————————

type APIResourceOptions struct {//apiResource结构体
	Output     string
	APIGroup   string
	Namespaced bool
	Verbs      []string
	NoHeaders  bool
	Cached     bool

	genericclioptions.IOStreams
}
func NewAPIResourceOptions(ioStreams genericclioptions.IOStreams) *APIResourceOptions {
	return &APIResourceOptions{//初始化结构体
		IOStreams:  ioStreams,
		Namespaced: true,
	}
}
//创建apiResources命令
func NewCmdAPIResources(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
	o := NewAPIResourceOptions(ioStreams)//初始化结构体

	cmd := &cobra.Command{//创建cobra命令
		Use:     "api-resources",
		Short:   "Print the supported API resources on the server",
		Long:    "Print the supported API resources on the server",
		Example: apiresourcesExample,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(o.Complete(cmd, args))//准备
			cmdutil.CheckErr(o.Validate())//校验
			cmdutil.CheckErr(o.RunAPIResources(cmd, f))//运行
		},
	}

	cmd.Flags().BoolVar(&o.NoHeaders, "no-headers", o.NoHeaders, "When using the default or custom-column output format, don't print headers (default print headers).")//no-headers选项
	cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "Output format. One of: wide|name.")//output选项

	cmd.Flags().StringVar(&o.APIGroup, "api-group", o.APIGroup, "Limit to resources in the specified API group.")//api-group选项
	cmd.Flags().BoolVar(&o.Namespaced, "namespaced", o.Namespaced, "If false, non-namespaced resources will be returned, otherwise returning namespaced resources by default.")//namespaced选项
	cmd.Flags().StringSliceVar(&o.Verbs, "verbs", o.Verbs, "Limit to resources that support the specified verbs.")//verbs选项
	cmd.Flags().BoolVar(&o.Cached, "cached", o.Cached, "Use the cached list of resources if available.")//cached选项
	return cmd
}
准备
func (o *APIResourceOptions) Complete(cmd *cobra.Command, args []string) error {
	if len(args) != 0 {//参数不等于0个报错
		return cmdutil.UsageErrorf(cmd, "unexpected arguments: %v", args)
	}
	return nil
}
//校验
func (o *APIResourceOptions) Validate() error {
	supportedOutputTypes := sets.NewString("", "wide", "name")
	if !supportedOutputTypes.Has(o.Output) {//output必须是name或wide
		return fmt.Errorf("--output %v is not available", o.Output)
	}
	return nil
}
//运行
func (o *APIResourceOptions) RunAPIResources(cmd *cobra.Command, f cmdutil.Factory) error {
	w := printers.GetNewTabWriter(o.Out)//获取writer
	defer w.Flush()

	discoveryclient, err := f.ToDiscoveryClient()//获取discoveryClient
	if err != nil {
		return err
	}

	if !o.Cached {//如果没有指定cache
		// Always request fresh data from the server
		discoveryclient.Invalidate()//使缓存失效
	}

	errs := []error{}
	lists, err := discoveryclient.ServerPreferredResources()//获取资源列表
	if err != nil {
		errs = append(errs, err)
	}

	resources := []groupResource{}//创建groupResource slice

	groupChanged := cmd.Flags().Changed("api-group")//判断api-group是否设置
	nsChanged := cmd.Flags().Changed("namespaced")//判断namespaced是否设置

	for _, list := range lists {//遍历list
		if len(list.APIResources) == 0 {//如果apiReosurce为空则跳过
			continue
		}
		gv, err := schema.ParseGroupVersion(list.GroupVersion)//解析GroupVersion
		if err != nil {
			continue
		}
		for _, resource := range list.APIResources {//遍历ApiResources
			if len(resource.Verbs) == 0 {//如果动作为空,跳过
				continue
			}
			// filter apiGroup
			if groupChanged && o.APIGroup != gv.Group {//设置了api-group,group不相等则跳过
				continue
			}
			// filter namespaced
			if nsChanged && o.Namespaced != resource.Namespaced {//设置了namespaced,namespaced不相等则跳过
				continue
			}
			// filter to resources that support the specified verbs
			if len(o.Verbs) > 0 && !sets.NewString(resource.Verbs...).HasAll(o.Verbs...) {//设置了verbs,如果资源的verbs,不包含所有的设置的verbs则表过
				continue
			}
			resources = append(resources, groupResource{// append groupResource
				APIGroup:    gv.Group,
				APIResource: resource,
			})
		}
	}

	if o.NoHeaders == false && o.Output != "name" {//如果没有指定no-headers,并且output不为name
		if err = printContextHeaders(w, o.Output); err != nil {//打印头
			return err
		}
	}

	sort.Stable(sortableGroupResource(resources))//对groupResources进行排序
	for _, r := range resources {//遍历groupResoruces
		switch o.Output {
		case "name"://如果output为name
			name := r.APIResource.Name
			if len(r.APIGroup) > 0 {
				name += "." + r.APIGroup
			}
			if _, err := fmt.Fprintf(w, "%s\n", name); err != nil {//打印name
				errs = append(errs, err)
			}
		case "wide"://如果output为wide
			if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%s\t%v\n",
				r.APIResource.Name,
				strings.Join(r.APIResource.ShortNames, ","),
				r.APIGroup,
				r.APIResource.Namespaced,
				r.APIResource.Kind,
				r.APIResource.Verbs); err != nil {//打印拼接的字符串
				errs = append(errs, err)
			}
		case ""://如果output为空
			if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\t%s\n",
				r.APIResource.Name,
				strings.Join(r.APIResource.ShortNames, ","),
				r.APIGroup,
				r.APIResource.Namespaced,
				r.APIResource.Kind); err != nil {// 打印拼接的字符串
				errs = append(errs, err)
			}
		}
	}

	if len(errs) > 0 {
		return errors.NewAggregate(errs)
	}
	return nil
}
//打印头
func printContextHeaders(out io.Writer, output string) error {
	columnNames := []string{"NAME", "SHORTNAMES", "APIGROUP", "NAMESPACED", "KIND"}
	if output == "wide" {//如果是wide,增加verbs
		columnNames = append(columnNames, "VERBS")
	}
	_, err := fmt.Fprintf(out, "%s\n", strings.Join(columnNames, "\t"))// 打印头
	return err
}

k8s use-context是什么 kubectl的命令用于在 Kubernetes 集群中切换上下文(context),从而方便地在多个集群或命名空间之间进行操作。一个上下文定义了kubectl使用的和的组合。 阅读详情

相关推荐

MCP协议实战:构建企业级AI模型控制中枢

Model Control Protocol(MCP)是一种面向大模型服务治理的标准化控制协议,核心解决多模型、多工具、多业务方场景下的统一调度、策略管控与语义路由问题。其原理基于能力契约(Capability Contract)与约束解析引擎,通过工具注册中心实现模型服务的主动报备与生命周期管理,并依托gRPC强类型IDL保障跨语言、低延迟、高可靠的服务交互。技术价值在于将AI服务从‘硬编码适配’升级为‘协议驱动治理’,显著提升可审计性、灰度发布效率与SLO保障能力。典型应用于金融风控、电商智能客服、医疗

love android 440

k8s实战之kubectl

本课程将详细介绍k8s所有命令,以及命令的go源码分析,学习知其然,知其所以然

Gemini 3.5 Flash长程Agentic能力深度实测与工程化落地指南

Agentic AI并非简单多步调用,而是指大模型在复杂任务中持续维护状态、自主规划工具链、闭环验证结果的系统性能力。其核心挑战在于上下文一致性、运行时语义理解及MCP等外部工具协同——这直接决定AI能否替代工程师完成端到端工程任务。当前主流模型如Gemini 3.5 Flash已在17步以上长程推理中展现稳定性,但仍在自我调试、符号与运行时语义对齐、跨协议状态感知等关键维度存在瓶颈。本文基于VS Code实战场景,解析Agentic工作流构建方法、GEMINI.md上下文建模技巧、MCP服务器选型策略及真

weixin_33725239的博客 410

helm源码分析之pull

发布一个k8s部署视频:https://edu.youkuaiyun.com/course/detail/26967 课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。 腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518 第二个视频发布https://edu.youkuaiyun.com/c..

mark's technic world 1370

Qwen3-Coder:MoE架构与256K上下文驱动的编程智能体

编程大模型正从代码补全迈向系统级任务执行,其核心在于对长上下文的理解能力与工具调用的工程化支持。MoE(Mixture of Experts)架构通过稀疏激活显著降低推理显存占用和延迟,使4800亿参数模型可在单张A100上稳定运行;256K上下文并非堆砌文本容量,而是支撑跨文件、跨配置、跨工具的项目级建模,为智能体编程、浏览器自动化和Tool Calling提供基础语义空间。Qwen3-Coder以Instruct范式强化指令遵循能力,将自然语言需求精准映射为可执行代码或结构化工具调用请求,适用于DevO

weixin_34060741的博客 370

基于MCP和A2A协议的多智能体协作框架实战:餐厅预订系统开发

AI Agent作为人工智能技术的重要分支,通过模拟人类智能行为来解决复杂问题。其核心原理在于将大语言模型与工具调用能力相结合,实现自主决策和任务执行。在工程实践中,多智能体协作技术能够显著提升系统处理复杂业务场景的能力,通过分工协作实现更高效的业务流程处理。MCP(Model Context Protocol)协议作为标准化工具交互框架,统一了智能体与外部工具、数据源之间的通信标准,解决了传统API调用的碎片化问题。A2A(Agent-to-Agent)协议则专注于智能体间的通信架构设计,通过智能体卡片、

weixin_34355559的博客 358

K8s(1)

K8s的架构还是采用的主从架构。其中有一个Master,它会被用来连接Kubectl,实现REST API,以及scheduler(bind pod to node视图)的实现。加上Controller Manager(CM,监控cluster是否达成指定状态的LOOP,参见)和etcd记录持久化状态数据。 而在slave端上,有kubelet运行,和主端进行通信。Kubelet就控制着各个POD...

SpanningWings的博客 111

Kubernetes Kubectl top 命令

kubectl top命令可显⽰节点和Pod对象的资源使⽤信息,它依赖于集群中的资源指标API来收集各项指标数据。它包含有node和pod两个⼦命令,可分别⽤于显⽰Node对象和Pod对象的相关资源占⽤率。,例如下⾯显⽰所有节点的资源占⽤状况的结果中显⽰了各节点累计CPU资源占⽤时长及百分⽐,以及内容空间占⽤量及占⽤⽐例。⽽名称空间级别的Pod对象资源占⽤率的使⽤⽅式会略有不同,使⽤时,⼀般应该限定名称空间及使⽤标签选择器过滤出⽬标Pod对象。列出Node资源占⽤率命令的语法格式为。

专注基础架构领域 2551

JMeter 接口与性能测试实战:从脚本构建到高并发压测的完整指南

接口测试与性能测试是保障系统稳定性的关键环节,而 JMeter 作为开源工具,凭借强大的脚本构建能力与灵活的组件体系,成为自动化测试与压力测试的主流选择。理解其线程组并发模型、参数化数据驱动原理及断言校验机制,能够有效提升测试脚本的健壮性与可维护性。本文系统梳理 JMeter 的核心使用路径,覆盖 HTTP 请求配置、CSV 参数化、断言校验、100 用户并发模型设计及报告解读,并针对 HTTPS 录制证书、BeanShell 断言失效、并发取值冲突等高频报错给出排查思路,同时拓展文件上传与 MQTT 插件

weixin_34319817的博客 305

从零搭建Obsidian智能知识库:Ollama本地模型与Copilot插件实战指南

本文详细介绍了如何从零搭建Obsidian智能知识库,结合Ollama本地模型与Copilot插件实现高效知识管理。通过本地部署AI助手,用户可以在保证隐私安全的同时,快速检索和整理笔记,提升工作效率。文章涵盖硬件准备、Ollama部署、插件配置及实战技巧,适合需要高效知识管理的专业人士。

weixin_29230773的博客 632

Robocopy 参数进阶:/MIR 镜像同步与 /PURGE 删除操作的风险规避指南

本文深入解析Robocopy的/MIR镜像同步与/PURGE删除操作的高级用法及风险规避策略。通过实际案例和四重防护机制,指导用户安全实现目录同步,避免数据丢失风险,特别适用于远程主机间的数据复制与备份场景。

weixin_33462927的博客 361

突破AWX Operator部署困境:从日志分析到数据库修复的全栈排障指南

作为Kubernetes环境中Ansible自动化的核心组件,AWX Operator的部署故障常常让管理员陷入困境: - operator日志中充斥着模糊的错误信息 - PostgreSQL数据库初始化失败却找不到具体原因 - Pod状态显示Running但AWX界面始终无法访问 - 调试配置修改后问题依旧反复出现 本文将系统梳理AWX Operator故障排查方法论,通过12个实战场

gitblog_00817的博客 436

Aurora8b10b光口通信实战:复位时序与IP核配置详解

本文深入解析了Aurora 8B10B协议在FPGA高速光口通信中的核心实践,重点剖析了确保链路稳定启动的关键复位时序与IP核配置细节。通过详解全双工与单工模式下的复位流程、Vivado中IP核的物理层与链路层参数设置,并结合用户逻辑设计实例,为工程师实现可靠的高速数据传输提供了清晰的实战指南。

weixin_29280219的博客 178

【kubernetes v1.21】(kube-apiserver 3)kube-apiserver Admission Control 与 CRD 超深度分析

Part 3: kube-apiserver Admission Control 与 CRD 超深度分析

zhonglinzhang 73

Win10 / Win11 启用 Hyper-V 虚拟机详细教程(图文+命令行全攻略)

摘要:本文详细介绍Windows10/11系统启用Hyper-V虚拟化平台的方法,包含专业版/企业版的图形界面和PowerShell命令行操作,以及家庭版通过脚本强制启用的特殊方案。内容涵盖版本支持对比、操作步骤图解、常见问题解答和性能优化建议,帮助开发者快速搭建虚拟化环境进行多系统测试。附微软官方文档参考链接和详细操作示意图。

ElioXu 7086

如何理解反步法设计控制器?

假设以二阶系统为例,被控对象的系统状态方程为: 基于反步控制的具体方法如下: 1.1步骤一 定义期望状态为xd,状态误差e1,为: e1=x1-xd; 则e1的导数为: 1.2步骤二 定义虚拟控制量为: e2定义为: 1.3步骤三 定义Lyapunov能量函数为: 1.4步骤四 定义总Lyapunov能量函数为: 因此设计的控制律为: 设计c>0,则: 满足Lyapunov的稳定性判定条件...

weixin_42736130的博客 2万+

juju reactive charm (by quqi99)

sudo snap install charm --classic mkdir -p /bak/work/charms/layers export JUJU_REPOSITORY=/bak/work/charms export LAYER_PATH=$JUJU_REPOSITORY/layers cd $LAYER_PATH charm create simple cd simple sudo ...

技术并艺术着 8742

f_fs.c 初始化流程(进行中)

前言 之所以选择f_fs.c作为这系列的开始,因为usb在/driver/usb下面的内容实在太多太多,如果讲各种各样点会太分散了。所以决定切入点以实际使用为主,就是f_fs了,目前我了解这是做bulk裸传输使用的,具体的通信协议自己确定。 初始化部分 开始点从这个路径下说起, /drivers/usb/gadget/function/f_fs.c 然后f_fs.c第一个使用的是include/composite.h中的宏定义function #define DECLARE_USB_FUNCTION(_n

weixin_36406973的博客 1968

3.本地单机架构minikube

搭建minikube

weixin_47252600的博客 1148

23、工业物流中的多智能体路径规划与碰撞处理策略

本文探讨了工业4.0背景下工业物流中的多智能体路径规划(MAPF)与碰撞处理策略。分析了自动导引车(AGV)等移动资源的应用现状,综述了主流路径规划算法如A*、D*Lite、M*等,以及集中式与分布式碰撞检测方法。重点比较了五种碰撞避免策略:路径交叉、优先级、起始时间调整、无交叉路径和速度调整,提出了基于环境条件的策略选择流程,并通过流程图展示了评估、组合、测试与优化的全过程。文章强调应根据订单不确定性、时间约束、优先级和生产组织等因素综合选择或组合策略,以提升物流效率与系统可靠性。

mac99的博客 126

Jupyter notebook教程系列(二)Jupyter notebook的基本用法

Jupyter notebook的基本使用   一. 主页面 如图1-1 我们先介绍一下主页面上的内容: 1.Files页面是用于管理创建文件相关类目的。 2.Running页面主要展示的是当前正在运行当中的终端和“ipynb”格式的notebook。若想要关闭已经打开的终端和“ipynb”格式的notebook,仅仅关闭其页面是无法彻底退出程序的,需要在Running页面点击其对...

dlhlSC的博客 1438

通过 kubectl 查看 K8s 内节点、Pod 资源使用情况

kubectl describe node -n ${namespace} 例如:我要查看生产环境下所有节点的资源分配情况(生产环境的 namespace 为 product) kubectl describe node -n product

cab5的博客 8万+

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

【Kubernetes】kubectl top pod 异常?

kubectl top pod 异常?本文手把手解决,跟着小涛一块试试吧~

http://DBAtao.cn/ 1万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

精雕软件(JDpaint) 5.5 绿色版

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

centos 安装swoole问题

centos安装swoole

weixin_43946021的博客 722

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

分享kubectl的奇技淫巧

Kubectl 是 Kubernetes 最重要的命令行工具。在 Flant,我们会在 Wiki 和 Slack 上相互分享 Kubectl 的妙用(其实我们还有个搜索引擎,不过那就是另外一回事了)。多年以来,我们在 kubectl 方面积累了很多技巧,现在想要将其中的部分分享给社区。我相信很多读者对这些命令都非常熟悉;然而我还是希望读者能够从本文中有所获益,进而提高生产力。本文没什么结论,但是可以提供一个小列表,其中包含本文相关的有用链接。原文来自微信公众号《CNCF》

Vic的博客 1336

配置kubeconfig_kubectl use-context配置多集群访问

kubectl use-context配置多集群访问 今天在rancher平台上进行日常维护。在多个集群切换时,鼠标一顿点点点还是有点不够顺畅。于是在"瑞斯拜"的chrome里面找到了k8s有关多集群访问配置的桥段,下面根据实践过程做简单描述使用 kubeconfig 文件组织集群访问 通过 kubectl 连接k8s集群时,默认情况下,kubectl 会在 $HOME/.kube 目录下查找名为...

weixin_34883093的博客 3522
上一篇: kubectl源码分析之completion
下一篇: kubectl源码分析之api-versions
hxpjava1
博客等级 码龄19年 1365粉丝 511原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

hxpjava1

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

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

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

打赏作者

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

抵扣说明:

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

余额充值