android 比较靠谱的选择图片以及拍照,保存图片

轻量级的android原生图片选择拍照第三方库 轻量级的android原生图片选择拍照第三方库 很容易使用,并且支持图片压缩多图片选择 立即下载
  1. import android.app.Activity;  
  2. import android.content.ActivityNotFoundException;  
  3. import android.content.Intent;  
  4. import android.os.Bundle;  
  5. import android.provider.MediaStore;  
  6. import android.view.MotionEvent;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.widget.Button;  
  10. import android.widget.LinearLayout;  
  11. import android.widget.Toast;  
  12.   
  13. public class SelectPicPopupWindow extends Activity implements OnClickListener {  
  14.   
  15.     private Button btn_take_photo, btn_pick_photo, btn_cancel;  
  16.     private LinearLayout layout;  
  17.     private Intent intent;  
  18.   
  19.     @Override  
  20.     protected void onCreate(Bundle savedInstanceState) {  
  21.         super.onCreate(savedInstanceState);  
  22.         setContentView(R.layout.alert_dialog);  
  23.         intent = getIntent();  
  24.         btn_take_photo = (Button) this.findViewById(R.id.btn_take_photo);  
  25.         btn_pick_photo = (Button) this.findViewById(R.id.btn_pick_photo);  
  26.         btn_cancel = (Button) this.findViewById(R.id.btn_cancel);  
  27.   
  28.         layout = (LinearLayout) findViewById(R.id.pop_layout);  
  29.   
  30.         // 添加选择窗口范围监听可以优先获取触点,即不再执行onTouchEvent()函数,点击其他地方时执行onTouchEvent()函数销毁Activity  
  31.         layout.setOnClickListener(new OnClickListener() {  
  32.   
  33.             public void onClick(View v) {  
  34.                 // TODO Auto-generated method stub  
  35.                 Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",  
  36.                         Toast.LENGTH_SHORT).show();  
  37.             }  
  38.         });  
  39.         // 添加按钮监听  
  40.         btn_cancel.setOnClickListener(this);  
  41.         btn_pick_photo.setOnClickListener(this);  
  42.         btn_take_photo.setOnClickListener(this);  
  43.     }  
  44.   
  45.     // 实现onTouchEvent触屏函数但点击屏幕时销毁本Activity  
  46.     @Override  
  47.     public boolean onTouchEvent(MotionEvent event) {  
  48.         finish();  
  49.         return true;  
  50.     }  
  51.   
  52.     @Override  
  53.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  54.         if (resultCode != RESULT_OK) {  
  55.             return;  
  56.         }  
  57.         //选择完或者拍完照后会在这里处理,然后我们继续使用setResult返回Intent以便可以传递数据和调用  
  58.         if (data.getExtras() != null)  
  59.             intent.putExtras(data.getExtras());  
  60.         if (data.getData()!= null)  
  61.             intent.setData(data.getData());  
  62.         setResult(1, intent);  
  63.         finish();  
  64.   
  65.     }  
  66.   
  67.     public void onClick(View v) {  
  68.         switch (v.getId()) {  
  69.         case R.id.btn_take_photo:  
  70.             try {  
  71.                 //拍照我们用Action为MediaStore.ACTION_IMAGE_CAPTURE,  
  72.                 //有些人使用其他的Action但我发现在有些机子中会出问题,所以优先选择这个  
  73.                 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  74.                 intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);  
  75.                 startActivityForResult(intent, 1);  
  76.             } catch (Exception e) {  
  77.                 e.printStackTrace();  
  78.             }  
  79.             break;  
  80.         case R.id.btn_pick_photo:  
  81.             try {  
  82.                 //选择照片的时候也一样,我们用Action为Intent.ACTION_GET_CONTENT,  
  83.                 //有些人使用其他的Action但我发现在有些机子中会出问题,所以优先选择这个  
  84.                 Intent intent = new Intent();  
  85.                 intent.setType("image/*");  
  86.                 intent.setAction(Intent.ACTION_GET_CONTENT);  
  87.                 startActivityForResult(intent, 2);  
  88.             } catch (ActivityNotFoundException e) {  
  89.   
  90.             }  
  91.             break;  
  92.         case R.id.btn_cancel:  
  93.             finish();  
  94.             break;  
  95.         default:  
  96.             break;  
  97.         }  
  98.   
  99.     }  
  100.   
  101. }  
   

 

第二:显示照片界面:

 

Java代码  收藏代码
  1. import android.app.Activity;  
  2. import android.content.Intent;  
  3. import android.graphics.Bitmap;  
  4. import android.net.Uri;  
  5. import android.os.Bundle;  
  6. import android.provider.MediaStore;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.widget.ImageView;  
  10.   
  11. public class MainActivity extends Activity {  
  12.     private ImageView photo;  
  13.   
  14.     @Override  
  15.     public void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.activity_main);  
  18.         photo = (ImageView) this.findViewById(R.id.text);  
  19.         // 把文字控件添加监听,点击弹出自定义窗口  
  20.         photo.setOnClickListener(new OnClickListener() {  
  21.             public void onClick(View v) {  
  22.                 //使用startActivityForResult启动SelectPicPopupWindow当返回到此Activity的时候就会调用onActivityResult函数  
  23.                 startActivityForResult(new Intent(MainActivity.this,  
  24.                         SelectPicPopupWindow.class), 1);  
  25.             }  
  26.         });  
  27.     }  
  28.   
  29.     @Override  
  30.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  31.   
  32.         switch (resultCode) {  
  33.         case 1:  
  34.             if (data != null) {  
  35.                 //取得返回的Uri,基本上选择照片的时候返回的是以Uri形式,但是在拍照中有得机子呢Uri是空的,所以要特别注意  
  36.                 Uri mImageCaptureUri = data.getData();  
  37.                 //返回的Uri不为空时,那么图片信息数据都会在Uri中获得。如果为空,那么我们就进行下面的方式获取  
  38.                 if (mImageCaptureUri != null) {  
  39.                     Bitmap image;  
  40.                     try {  
  41.                         //这个方法是根据Uri获取Bitmap图片的静态方法  
  42.                         image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageCaptureUri);  
  43.                         if (image != null) {  
  44.                             photo.setImageBitmap(image);  
  45.                         }  
  46.                     } catch (Exception e) {  
  47.                         e.printStackTrace();  
  48.                     }  
  49.                 } else {  
  50.                     Bundle extras = data.getExtras();  
  51.                     if (extras != null) {  
  52.                         //这里是有些拍照后的图片是直接存放到Bundle中的所以我们可以从这里面获取Bitmap图片  
  53.                         Bitmap image = extras.getParcelable("data");  
  54.                         if (image != null) {  
  55.                             photo.setImageBitmap(image);  
  56.                         }  
  57.                     }  
  58.                 }  
  59.   
  60.             }  
  61.             break;  
  62.         default:  
  63.             break;  
  64.   
  65.         }  
  66.     }  
  67.   
  68. }  
 

 

第三:如果需要保存图片到SD卡或者上传图片可以用下面代码:

 

Java代码  收藏代码
  1. public static String savePicToSdcard(Bitmap bitmap, String path,  
  2.             String fileName) {  
  3.         String filePath = "";  
  4.         if (bitmap == null) {  
  5.             return filePath;  
  6.         } else {  
  7.   
  8.             filePath=path+ fileName;  
  9.             File destFile = new File(filePath);  
  10.             OutputStream os = null;  
  11.             try {  
  12.                 os = new FileOutputStream(destFile);  
  13.                 bitmap.compress(CompressFormat.JPEG, 100, os);  
  14.                 os.flush();  
  15.                 os.close();  
  16.             } catch (IOException e) {  
  17.                 filePath = "";  
  18.             }  
  19.         }  
  20.         return filePath;  
  21.     }  
   

上传图片的话我们可以获取bitmap的流然后上传,如上面方式获取,如要上传,上传代码自己实现,这个比较简单。

运行效果图:


android仿微信选择多张图片 android仿微信上传图片的效果,要源码的可自行下载,大家有什么需要实现的效果都可以在反馈中留言,有时间我会更新上去,大家一起研究,共同进步! 立即下载

相关推荐

不错的android原生图片选择及拍照第三方库

不错的android原生图片选择及拍照第三方库 能够适配多个android系统

实现仿微信拍照和选取相片(转自网络)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34132768的博客 216

仿IOS弹出相机相册框--可进入相机相册仿朋友圈功能的demo

仿IOS弹出相机相册框--可进入相机相册仿朋友圈功能的demo [注意:本资源来自网络,如有侵权,请联系我删除,谢谢。]

Android简单实现仿微信选择图片以及拍照(PhotoPicker)

实现仿微信的图片选择,预览以及拍照,属性可以设置显示照相机以及预览时是否显示删除按钮等,功能齐全并且可以根据存储照片的路径进行修改等 Gradle配置 dependencies { compile 'me.iwf.photopicker:PhotoPicker:0.9.5@aar' compile 'com.android.support:appcompat-v7...

Android小飞の博客 6090

Android从相册选择图片和调用系统摄像头拍照

Android从相册选择图片和调用系统摄像头拍照

Android 拍照选择图片并上传功能的实现思路(包含权限动态获取)

作为一个Android新手,想实现手机拍照并上传的功能,经过查找资料,已实现此功能。在此记录备忘。老鸟请忽略。 一、实现思路: 1.Android手机客户端,拍照(或选择图片),然后上传到服务器。 2.服务器端接收手机端上传上来的图片。 二、实现步骤: 1.按惯例,先放效果图: 项目结构: 2.activity_main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_wid

Android实现仿微信朋友圈发布动态(拍照、图库选择、照片压缩、显示、保存、缩略图、点击缩略图删除对应文件等)附源码

原创作品,转载请注明出处: 最近项目需求中要用到类似微信朋友圈发布动态选择图片的UI效果,研究了一下,特来分享成果,多的不说来看代码。 Activity类 package com.whfp.circle_of_friends; import java.io.File; import java.io.FileNotFoundException; import java.io.IOEx

8729

魔百和CM211-1刷Armbian全流程:从安卓盒子到Linux服务器的完美变身

本文详细介绍了如何将魔百和CM211-1机顶盒刷入Armbian系统,实现从安卓盒子到Linux服务器的完美变身。涵盖硬件兼容性验证、固件选择、刷机流程、系统优化及常见问题解决,特别适合技术爱好者低成本搭建家庭NAS或开发环境。

weixin_30329623的博客 239

Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等

仿照微信,朋友圈分享图片功能 。可以进行图片的多张选择,拍照添加图片,以及进行图片的预览,预览时可以进行缩放,并且可以删除选中状态的图片 。很不错的源码,大家有需要可以下载看看 。 微信 微信 微信 微信 下载地址 :微信上传图片源码 很多网友不知道怎么获取图片路径,这里贴出来: String path = Bimp.tem...

weixin_34087301的博客 1423

告别密码!用VScode+SSH一键连接树莓派,再也不用每次输密码了

本文详细介绍了如何通过VScode和SSH密钥实现树莓派的免密连接,告别繁琐的密码输入。从开发环境准备、SSH密钥生成与配置,到VScode远程连接优化和常见问题排查,提供了一套完整的解决方案,帮助开发者提升工作效率。

weixin_28831341的博客 172

【Codesys】-扫描添加失败,手动添加第三方模块,真·DC模式的高速计数模块

欧姆龙耦合器(NX-ECC201)和高速计数模块(NX-EC0132)单独使用。扫描设备添加到Codesys中,会报错,无法自动添加。记录一下,以防忘记。高速的计数保证了位置的准确性,位置准确就能保证裁切的精度,一切的基础就在这儿了,奈何目前只有欧姆龙和倍福能做到这样的波形。

qq_35316470的博客 1389

android 比较靠谱的选择图片以及拍照,保存图片

  在开发项目中用到这个功能,之前就按照学过的拍照和选择照片的功能,所以也没在意就写了上去,可是最后发现在有些机子里面获取到的数据时空的,所以会导致程序崩溃的情况出现,网上找了很多例子大多都是一样的,还是有问题,后来就查看跟踪了拍照后返回的数据写了下面的代码相对大多数机子是可行的,经测试还是比较靠谱的,包括拍照后图片翻转了90度问题都没问题。直接看代码: 第一:拍照选择界面:   im...

xiao12593a的专栏 176

Coze HTTP请求节点实战:5分钟搞定天气API对接(含动态参数技巧)

本文通过一个天气预报API对接的实战案例,详细讲解了如何在Coze平台使用HTTP请求节点实现外部数据交互。文章重点演示了动态参数传递、JSON响应解析与错误处理等核心技巧,帮助开发者在5分钟内快速构建稳定可靠的智能体外部服务调用能力。

weixin_29233333的博客 676

Android 拍照、选择图片并裁剪

版权声明:本文为博主原创文章,未经博主允许不得转载。 目录(?)[+] 一 实现效果二 uCrop项目应用三 实现思路四 选择框实现 XML布局代码编写 五使用选择框 初始化选择框设置选择框监听 六拍照并保存图片七相册选择图片八使用Crop裁剪图片 八使用Crop裁剪图片 XML布局 九裁剪样式十PictureSelectFragment使用十一下载传送门

阳光灿烂的日子的博客 1239

逆向CarPlay协议时,除了USB主从切换,你还需要注意这3个关键点

本文深入探讨逆向CarPlay协议时的3个关键点,包括MFi协议背景、多通道协同工作机制和协议分析工具的高级过滤技巧。特别解析了USB主从切换后的复杂交互过程,帮助安全研究员和逆向工程师更好地理解CarPlay协议的核心机制与潜在安全研究切入点。

weixin_29164497的博客 382

时序基础模型Timer-S1:十亿参数如何革新时间序列预测

时间序列预测是数据分析与机器学习中的核心任务,旨在基于历史数据预测未来趋势。其原理在于捕捉数据中的趋势、周期性和季节性等时序依赖关系。这项技术的价值在于赋能业务决策,广泛应用于金融风控、能源管理、物联网监控和供应链优化等关键场景。传统方法依赖针对特定任务的专用模型,面临泛化能力弱和开发成本高的挑战。本文聚焦的时序基础模型,通过在海量跨领域数据上进行预训练,学习时序通用模式,并结合十亿级参数带来的强大容量,实现了性能的显著突破。这种范式转变,使得模型能够像“全科医生”一样,通过少量数据微调即可快速适应新任务,

weixin_29164843的博客 269

android 选择图片以及拍照,保存图片

在开发项目中用到这个功能,之前就按照学过的拍照和选择照片的功能,所以也没在意就写了上去,可是最后发现在有些机子里面获取到的数据时空的,所以会导致程序崩溃的情况出现,网上找了很多例子大多都是一样的,还是有问题,后来就查看跟踪了拍照后返回的数据写了下面的代码相对大多数机子是可行的,经测试还是比较靠谱的,包括拍照后图片翻转了90度问题都没问题。直接看代码: 第一:拍照选择界面: Java代码

三江的博客 490

fanuc机器人I/O分配

FANUC机器人在和其他外部设备进行通讯时,需要对信号进行配置。 在机器人处于UOP自动分配状态时,系统会自动检索已配对设备,并分配相应的机架号。 当我们需要手动对信号进行分配时,可参考以下机架号进行配置。 不同的通讯协议对应的机架号不同,外部通讯协议常用的机架号参考下表: 序号 机架号 通讯类型 1 0 Process I/O 2 1-15

haier123888的博客 1万+

Android调取拍照和获取拍照后的照片

需要调取照相机拍照,但是又不想用第三方,自己去写的时候,却发现有很多坑。比如:1、拍完照后,如何获取照片?2、照片获取不到是什么原因?@ContentView(R.layout.activity_main) public class MainActivity extends BaseActivity { Uri saveUri; @Override protecte...

Ade-rui的博客 4837

泛微OA集成阿里云短信(E9保姆教程)

泛微OA集成阿里云短信(E9保姆教程)

技术分享 515

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

上一篇: jquery遍历json数组方法
下一篇: Android作为客户端,PC作为服务端:实现网络通信
WhtBk
博客等级 码龄11年 12粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值