| 利用WebClient类向服务器上载文件 |
| 作者: 孟宪会 出自: 【孟宪会之精彩世界】 发布日期: 2003-7-30 17:44:10
|
| .NET 提供了许多上载文件的方法,在Windows Form应用程序中,我们可以使用WebClient类来实现。WebClient类也有两个方法可以上载,UploadFile和OpenWrite方法,下面就是一个实际的例子,两种方法都有代码: 结果如下:
C#代码如下: <xmp>using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Net; using System.Text; using System.IO; namespace UploadFile { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button button2; private System.Windows.Forms.TextBox txtFileName; private System.Windows.Forms.TextBox txtServerPath; private System.Windows.Forms.LinkLabel linkLabel1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.label1 = new System.Windows.Forms.Label(); this.txtServerPath = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.txtFileName = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.SuspendLayout(); // // label1 // this.label1.ForeColor = System.Drawing.Color.Red; this.label1.Location = new System.Drawing.Point(8, 96); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(448, 16); this.label1.TabIndex = 0; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // txtServerPath // this.txtServerPath.Location = new System.Drawing.Point(128, 8); this.txtServerPath.Name = "txtServerPath"; this.txtServerPath.Size = new System.Drawing.Size(320, 21); this.txtServerPath.TabIndex = 1; this.txtServerPath.Text = "http://mengxianhui/aspxWeb/Images/"; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label2.ForeColor = System.Drawing.Color.Navy; this.label2.Location = new System.Drawing.Point(8, 12); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(116, 17); this.label2.TabIndex = 2; this.label2.Text = "请输入服务器地址:"; this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // button1 // this.button1.Location = new System.Drawing.Point(192, 64); this.button1.Name = "button1"; this.button1.TabIndex = 3; this.button1.Text = "上载文件"; this.button1.Click += new System.EventHandler(this.button1_Click); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown); // // txtFileName // this.txtFileName.Location = new System.Drawing.Point(128, 32); this.txtFileName.Name = "txtFileName"; this.txtFileName.Size = new System.Drawing.Size(232, 21); this.txtFileName.TabIndex = 4; this.txtFileName.Text = ""; // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this.label3.ForeColor = System.Drawing.Color.DarkBlue; this.label3.Location = new System.Drawing.Point(8, 38); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(116, 17); this.label3.TabIndex = 5; this.label3.Text = "请输入上传文件名:"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // button2 // this.button2.Location = new System.Drawing.Point(370, 32); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(80, 23); this.button2.TabIndex = 6; this.button2.Text = "浏览文件…"; this.button2.Click += new System.EventHandler(this.button2_Click); // // linkLabel1 // this.linkLabel1.Location = new System.Drawing.Point(16, 120); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.Size = new System.Drawing.Size(440, 24); this.linkLabel1.TabIndex = 7; this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.BackColor = System.Drawing.SystemColors.Control; this.ClientSize = new System.Drawing.Size(464, 157); this.Controls.Add(this.linkLabel1); this.Controls.Add(this.button2); this.Controls.Add(this.txtFileName); this.Controls.Add(this.label3); this.Controls.Add(this.txtServerPath); this.Controls.Add(this.label2); this.Controls.Add(this.button1); this.Controls.Add(this.label1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; this.Text = "WebClient 上传文件的例子"; this.Resize += new System.EventHandler(this.Form1_Resize); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } /// <summary> /// .NET SDK 上面的打开文件的类 /// </summary> private FileStream OpenFile() { OpenFileDialog dlgOpenFile = new OpenFileDialog(); dlgOpenFile.ShowReadOnly = true; if(dlgOpenFile.ShowDialog() == DialogResult.OK) { if(dlgOpenFile.ReadOnlyChecked == true) { return (FileStream)dlgOpenFile.OpenFile(); } else { string path = dlgOpenFile.FileName; return new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite); } } return null; } private void button2_Click(object sender, System.EventArgs e) { OpenFileDialog dlgOpenFile = new OpenFileDialog(); dlgOpenFile.InitialDirectory = @"C:\"; dlgOpenFile.ShowReadOnly = false; dlgOpenFile.ReadOnlyChecked = true; dlgOpenFile.Filter = "所有文件 (*.*)|*.*"; if(dlgOpenFile.ShowDialog() == DialogResult.OK) { if(dlgOpenFile.ReadOnlyChecked == true) { txtFileName.Text = dlgOpenFile.FileName.ToString(); } } } private void button1_Click(object sender, System.EventArgs e) { // 需要注意的是:txtServerPath文件夹有匿名可写的权限。 // 可以自己定义新文件名字 if(txtFileName.Text.Trim() == "" || txtServerPath.Text.Trim() == "") { MessageBox.Show("请输入你要上载的文件名字!","错误:", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { /// 得到文件名,文件扩展名字,服务器路径 string fileNamePath = txtFileName.Text.Trim(); string uriString = txtServerPath.Text.Trim(); string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf("\\") + 1); string fileNameExt = fileName.Substring(fileName.LastIndexOf(".") + 1); if(uriString.EndsWith("/") == false) uriString = uriString + "/"; uriString = uriString + fileName; /// 创建WebClient实例 WebClient myWebClient = new WebClient(); myWebClient.Credentials = CredentialCache.DefaultCredentials; // 要上传的文件 FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); //FileStream fs = OpenFile(); BinaryReader r = new BinaryReader(fs); try { //使用UploadFile方法可以用下面的格式 //myWebClient.UploadFile(uriString,"PUT",fileNamePath); byte[] postArray = r.ReadBytes((int)fs.Length); Stream postStream = myWebClient.OpenWrite(uriString,"PUT"); if(postStream.CanWrite) { postStream.Write(postArray,0,postArray.Length); label1.Text = fileName + "上传成功!"; } else { label1.Text = "文件目前不可写!"; } postStream.Close(); linkLabel1.Text = "查看上载的文件"; for(int i = linkLabel1.Links.Count - 1;i>-1;i--) linkLabel1.Links.Remove(linkLabel1.Links[i]); linkLabel1.Links.Add(0,linkLabel1.Text.Length,uriString); } catch(WebException errMsg) { label1.Text="上传失败:" + errMsg.Message; } } } private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { this.WindowState = FormWindowState.Minimized; this.linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true; string target = e.Link.LinkData as string; if(null != target) { System.Diagnostics.Process.Start(target); } else { MessageBox.Show("请用浏览器访问:" + target); } } private void Form1_Resize(object sender, System.EventArgs e) { if(this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal; } private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(txtFileName.Text.Trim() != "" && txtServerPath.Text.Trim() != "") label1.Text = "正在上传文件,请稍侯……!"; } } } </xmp> |
相关推荐
地震数据可视化必备:5分钟读懂SEGY道头字段全解析(含坐标定位指南)
本文深入解析了SEGY文件格式中道头坐标字段的提取与可视化方法。针对地震数据处理中的常见痛点,详细介绍了sx/sy、gx/gy等关键坐标字段的二进制解析、比例因子应用、单位转换及常见问题解决方案,并提供了实用的Python代码示例,帮助开发者实现从SEGY文件到三维空间可视化的完整流程。
【Linux】文件上传到Linux服务器常用方法
本文介绍几种常见的方法,把文件上传到Linux服务器中!常见有使用:scp命令、xshell软件里的xftp程序、U盘挂载、服务器自带的lrzsz程序。
Cadence Virtuoso里搞定斩波运放AC仿真:PSS+PAC保姆级设置避坑指南
然而,当工程师们尝试在Cadence Virtuoso环境中对这种特殊结构进行AC特性分析时,往往会遇到传统AC仿真方法失效的困境——这正是PSS(Periodic Steady-State)与PAC(Periodic AC)仿真组合大显身手的场景。实际项目中我们常采用"先快后精"的两步法:先用快速设置确认大体趋势,再针对关键频段进行精细仿真。例如某次设计迭代中,将harmonics从10增加到20后,发现在1MHz处的相位裕度估算误差达15°,这解释了之前样机测试时的振荡问题。
SPRINGBOOT 实现大文件上传下载、分片、断点续传教程
该说不说,最近这块好像挻火的,今天早上又有网友加我微信,也是想了解一下这块的技术和方案,也不知道这位老哥是从哪里找到的我的微信号,虽然在网上已经公开了,但是很多人还是找不到。 昨天晚上论坛里一位网友发私信给我,咨询了这个问题,他最近想了解和学习大附件上传下载的相关技术,他也是刚开始学习和接触这一块,对很多方面都不是太了解,我先花了1个小时左右的时间先给他讲解了一下基础知识,技术原理,又花了一个小时的时间帮他安装开发环境,主要就是安装开发工具和配置环境,由于在百度上面找到的很多开发工具有问题,有的不能安装,有
Kisssoft软件在行星齿轮设计上的初试
行星齿轮传动与链传动相比较,具有质量小,体积小,承载能力强,传动比大,传动效率高等优点,但在行星齿轮传动种种优点下,不可避免的带来一些缺点,对其材料的要求过高,在追求传动比大而体积小的同时,其传动结构大大的复杂化,以及在制造和安装过程中较困难,对于行星齿轮传动设计来说,不仅应该了解其优点,而且应该在设计中,充分发挥其优点,且把其缺点降低到最低的限度。从而才能设计出性能优良的行星齿轮传动装置,为我们赛车提供更加强大的动力保证。 Kisssoft软件为我们行星齿轮传动设计提供了一体化方案,从设...
从仿真到打样:PMOS栅极泄放电路设计全流程复盘与三个踩坑点总结
本文详细复盘了PMOS栅极泄放电路从仿真到打样的全流程设计,重点总结了三个关键踩坑点:三极管BE结过压击穿、静态功耗超标和栅极振荡现象。通过优化缓启动电路、改进保护设计和布局调整,最终实现18ms开通时间、190μs关断时间和8μA静态功耗的工业级性能指标,为类似电源开关设计提供实用参考。
如何向服务器上传文件
可以安装xftp软件,在传输协议那边有两个可以选择,一个是ftp,另一个是sftp协议,其中一个连接服务器不成功,就换一个模式,继续连接。
AppStore逆向分析:从网络抓包到自动化模拟的完整实践
在移动应用生态中,理解客户端与服务器之间的通信协议是进行自动化测试、数据分析和系统集成的关键技术基础。通过分析网络请求与响应,可以深入理解认证、会话管理和数据交换的原理,这对于构建稳定的自动化流程至关重要。其技术价值在于能够实现合法场景下的流程模拟,例如应用元数据监控、沙盒环境测试或内部工具开发。在实际应用场景中,开发者常需处理登录态维持、请求签名验证及风控策略应对等挑战。本文聚焦于AppStore这一封闭生态,详细拆解了其登录、查询等核心环节的通信机制,并探讨了使用Python结合抓包工具进行安全逆向分析
QT创建线程-基于QThread的简单封装
基于QThread类的线程类简单封装,便于反复执行线程逻辑代码与退出。
【ARM Trace32(劳特巴赫) 高级篇 20 -- SNOOPer 使用介绍】
在 Lauterbach TRACE32 调试系统中,Snooper是一种特殊的监视工具,它能够在不中断处理器执行的情况下监视和记录特定内存地址的数据变化。这对于系统级调试、性能分析、数据流监视以及实时系统的问题追踪特别有用,尤其是在无法使用中断的情况下。当你设置了一个或多个Snooper时,TRACE32 硬件将不断地监视指定的内存地址,一旦发生了读写操作,就会将相关信息记录下来。这样你就可以看到某个地址的数据是什么时候以及如何被修改的,而不会影响目标系统的运行。
20 Embedding 与向量检索:语义为什么能变成距离
Embedding 是 RAG 语义检索的数学基础。本文用工程视角讲清文本如何变成向量,为什么语义相近会表现为距离相近,Top-K 检索如何工作,以及在模型选择、同模型约束、精确匹配和召回评估上的常见坑。
文件上传本地服务器
文件上传的本质就是将文件通过IO流复制到服务器。文件上传是先上传到临时目录,然后再从临时目录复制到磁盘,目的是防止用户在上传途中网路中断、刷新页面导致文件上传失败,从而磁盘中产生大量垃圾文件和正常文件混在一起,所以只有文件上传成功后,才会从临时文件复制到磁盘,之后系统会自动删除临时文件。
自顶向下与自底向上编程思想的对比
一、核心定义与本质差异自顶向下编程思想如同绘制一幅完整的地图,从整体轮廓逐步细化到局部细节。其本质是从系统的整体目标出发,通过逐层分解将复杂问题简化为可实现的子问题,强调先定义 “做什么”,再考虑 “如何做”。自底向上编程思想则类似于搭建积木,从基础组件开始逐步构建复杂系统。其本质是从现有资源和基础功能出发,通过组合和扩展简单组件来实现复杂功能,强调先解决 “如何做” 的细节,再整合为 “做什么” 的整体。二、设计起点与逻辑流程对比设计起点:以系统的整体目标和业务需求为起点。例如设计一个电商平台,首先明确
利用WebClient类向服务器上载文件(转孟子的)
利用WebClient类向服务器上载文件(转孟子的) 今天看了TERRYLEE老大的一篇写上传的.里面有个WEBCLIENT我就上网查了一下,找到孟子大人的一篇文章.感觉不错,就转了过来.大家一起学习下..NET 提供了许多上载文件的方法,在Windows Form应用程序中,我们可以使用WebClient类来实现。WebClient类也有两个方法可以上载,UploadFile和...
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
TMS_WebGMaps_1.9.8.0_Full_Source
TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

1017



被折叠的 条评论
为什么被折叠?



