首页 文章 精选 留言 我的

精选列表

搜索[图像理解],共10001篇文章
优秀的个人博客,低调大师

亚马逊AWS首席科学家:从图像理解到语音识别,我们是如何研究和量化机器学习的

亚马逊一直致力于寻求机器学习多域模型的解决方案,以及多领域的应用如何能够在云上进行计算。 在今日于北京召开的《麻省理工科技评论》新兴科技峰会EmTech China上,作为亚马逊旗下最赚钱云服务部门 AWS 的核心人物,亚马逊AWS首席科学家Animashree Anandkumar解读我们该如何研究和量化机器学习。 深度学习需要经过多层甚至数百层的处理过程,机器学习也会在不同的GPU,进行跨机器、跨设备处理,这就需要网络技术。 而多域模型能够帮助我们同时处理科学、工程,各种领域方面的应用。亚马逊就一直致力于寻求机器学习多域模型的解决方案,以及多领域的应用如何能够在云上进行计算。 那么亚马逊是如何运作当前的深度学习模式呢?以下为镁客网整理分享的Animashree Anandkumar现场演讲内容: 深度学习有很广泛的运用领域,我们有一些专门的项目会应用到不同的硬件基础设施中。Mxnet就是其中的一个深度学习引擎,这个项目首先由大学里的研究员开发,现在我们正在AWS开发这个引擎。 这个引擎的优点是显而易见的。它建立了一个网络,让编程过程、表述、特征描述、风格都非常灵活、方便,提高了程序员的效率。同时也提供了很好的语言支持,且前后端自动对接,提高了编程的效率。 这个网络有一些固定的数据,相互连接的层级会在输入和输出之间进行连接。在计算顺序方面,他们有一定的序列关系,我们制定了图表来自动进行平行的对比。它还实现了记忆进行自动化,这样在代码运算时也提高了效率。 我们也用多GPU的训练提升效率。一个机器上面会有多个GPU进行数据并行化,可以同时获得大量的数据。中央数据是来自于不同CPU等级上面的网络,数据不断地向下划分,进入各个GPU。 GPU需要进行处理时发现了相似的内容就会进行整合,也增加了我们的效率。GPU可以在Mxnet上面整合运算结果,这样成本也比较低。同时我们也提升了Mxnet的性能。增加了GPU以后,整个输入输出效率也会翻番。这是在AWS基建上运行的,包括B2X和B22X。 所有的服务里面, Mxent的效率最高,达到了91%,包括Resnet和Inception v3和Alexnet。这是有多个GPU的单一基体。在多基体上每一个机器都有16个GPU,组合到一起后,所有的数据经过网络就会影响效率。但我们的效率并没有降低很多,因为Mxnet的打造非常紧密,可以提升效率。所以我们可以进行这种分布式的多机器的训练。这 些现在也可以应用于一些情景的运行以及我们多GPU和CPU的框架之中。我们也希望可以提供这样的技术给我们的消费者,让他们知道我们分布式的训练有非常好的技术包裹,可以帮助我们进行网络压缩以及网络解压,提供好的技术服务。 所有的这些框架,都可以应用于我们的机器学习平台CHMaker。这是多机器学习的一个平台,所有的分布式深度学习框架都可以在这个平台上进行运行,比如说TensorFlow、Mxnet。我们的平台除MxNet之外可以支持所有的框架,我们希望可以给我们的用户更多灵活的选择。 除此之外,DeepLens也是我们最近发布的第一款深度学习的摄像头,可以提供很多的服务,比如语言、语句、计算机视觉等。使用者不需要培训自己的学习模型,完全可以使用我们的服务。我们整个系统都具有很多的解决方案。 原文发布时间: 2018-01-28 14:08 本文作者: 巫盼 本文来自云栖社区合作伙伴镁客网,了解相关信息可以关注镁客网。

优秀的个人博客,低调大师

Android 图像压缩

Android中图片是以Bitmap形式存在的,Bitmap所占内存直接影响应用所占内存大小,Bitmap所占内存大小计算公式: 图片长度 * 图片宽度 * 一个像素点占用的字节数 Bitmap压缩颜色格式: 图1.png 质量压缩 Bitmap bitmap = BitmapFactory.decodeFile(path); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int quality = 80; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); byte[] bytes = baos.toByteArray(); bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); 图片的大小没有变化,因为质量有压缩不会减少图片的像素,它是在保持像素的前提下改变图图片的位深及透明度,来达到压缩图片的目的。注: 当compress方法中第一个参数为Bitmap.CompressFormat.PNG时,quality没有作用,因为png图片时无损的,不能进行压缩。 采样率压缩 BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeFile(path, options); 设置inSampleSize的值为2时,宽和高都变为原来的1/2。 注:当设置options.inJustDecodeBounds = true时,BitmapFactory解码图片时会返回空的Bitmap对象,但是也可以返回Bitmap的宽、高以及MimeType。 缩放法压缩(Martix) Matrix matrix = new Matrix(); matrix.setScale(0.5f, 0.5f); Bitmap bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 其中,bitmap的宽高分别缩小了一半,图片大小压缩成1/4。 RGB_565 BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; Bitmap bitmap = BitmapFactory.decodeFile(path, options); 图片大小直接缩小了一半,宽高没有变。注意:由于ARGB_4444的画质惨不忍睹,一般假如对图片没有透明度要求的话,可以改成RGB_565,相比ARGB_8888将节省一半的内存开销。 createScaledBitmap Bitmap bitmap = BitmapFactory.decodeFile(path); bitmap = Bitmap.createScaledBitmap(bitmap, 150, 150, true); 这里将图片压缩成用户所期望的宽高。 系统压缩工具类 从Android 2.2开始系统新增了一个缩略图ThumbnailUtils类,位于framework包下的android.media.ThumbnailUtils位置,可以帮助我们从mediaprovider中获取系统中的视频或图片文件的缩略图,该类提供了三种静态方法可以直接调用获取。 1、extractThumbnail (source, width, height): /** * 创建一个指定大小的缩略图 * @param source 源文件(Bitmap类型) * @param width 压缩成的宽度 * @param height 压缩成的高度 */ ThumbnailUtils.extractThumbnail(source, width, height); 2、extractThumbnail(source, width, height, options): /** * 创建一个指定大小居中的缩略图 * @param source 源文件(Bitmap类型) * @param width 输出缩略图的宽度 * @param height 输出缩略图的高度 * @param options 如果options定义为OPTIONS_RECYCLE_INPUT,则回收@param source这个资源文件 * (除非缩略图等于@param source) * */ ThumbnailUtils.extractThumbnail(source, width, height, options); 3、createVideoThumbnail(filePath, kind): /** * 创建一张视频的缩略图 * 如果视频已损坏或者格式不支持可能返回null * @param filePath 视频文件路径 如:/sdcard/android.3gp * @param kind kind可以为MINI_KIND或MICRO_KIND * */ ThumbnailUtils.createVideoThumbnail(filePath, kind); 压缩工具类 public class CompressUtils { /** * 按质量压缩 * @param bitmap * @return */ public static Bitmap compressImage(Bitmap bitmap){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); //质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); int options = 100; //循环判断如果压缩后图片是否大于100kb,大于继续压缩 while ( baos.toByteArray().length / 1024>100) { //清空baos baos.reset(); bitmap.compress(Bitmap.CompressFormat.JPEG, options, baos); options -= 10;//每次都减少10 } //把压缩后的数据baos存放到ByteArrayInputStream中 ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); //把ByteArrayInputStream数据生成图片 Bitmap newBitmap = BitmapFactory.decodeStream(isBm, null, null); return newBitmap; } /** * 按图片尺寸压缩 参数为路径 * @param imgPath 图片路径 * @param pixelW 目标图片宽度 * @param pixelH 目标图片高度 * @return */ public static Bitmap compressImageFromPath(String imgPath, int pixelW, int pixelH) { BitmapFactory.Options options = new BitmapFactory.Options(); // 开始读入图片,此时把options.inJustDecodeBounds 设回true,即只读边不读内容 options.inJustDecodeBounds = true; options.inPreferredConfig = Bitmap.Config.RGB_565; BitmapFactory.decodeFile(imgPath,options); options.inJustDecodeBounds = false; options.inSampleSize = computeSampleSize(options , pixelH > pixelW ? pixelH : pixelW ,pixelW * pixelH ); Bitmap bitmap = BitmapFactory.decodeFile(imgPath, options); return bitmap; } /** * 按图片尺寸压缩 参数是bitmap * @param bitmap * @param pixelW * @param pixelH * @return */ public static Bitmap compressImageFromBitmap(Bitmap bitmap, int pixelW, int pixelH) { ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); if( os.toByteArray().length / 1024>1024) {//判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出 os.reset(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50, os);//这里压缩50%,把压缩后的数据存放到baos中 } ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inPreferredConfig = Bitmap.Config.RGB_565; BitmapFactory.decodeStream(is, null, options); options.inJustDecodeBounds = false; options.inSampleSize = computeSampleSize(options , pixelH > pixelW ? pixelH : pixelW ,pixelW * pixelH ); is = new ByteArrayInputStream(os.toByteArray()); Bitmap newBitmap = BitmapFactory.decodeStream(is, null, options); return newBitmap; } /** * 对图片进行缩放指定大小 * @param bitmap * @param width * @param height * @return */ public static Bitmap scaleTo(Bitmap bitmap, int width, int height){ int originalWidth = bitmap.getWidth(); int originalHeight = bitmap.getHeight(); float xScale = (float)width / originalWidth; float yScale = (float)height / originalHeight; Matrix matrix = new Matrix(); matrix.setScale(xScale,yScale); return Bitmap.createBitmap(bitmap, 0, 0, originalWidth, originalHeight, matrix, true); } /** * 以最省内存的方式读取本地资源的图片 * @param context * @param resId * @return */ public static Bitmap readBitmap(Context context, int resId) { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; // 获取资源图片 InputStream is = context.getResources().openRawResource(resId); return BitmapFactory.decodeStream(is, null, opt); } /** * android源码提供给我们的动态计算出图片的inSampleSize方法 * @param options * @param minSideLength * @param maxNumOfPixels * @return */ public static int computeSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { int initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels); int roundedSize; if (initialSize <= 8) { roundedSize = 1; while (roundedSize < initialSize) { roundedSize <<= 1; } } else { roundedSize = (initialSize + 7) / 8 * 8; } return roundedSize; } private static int computeInitialSampleSize(BitmapFactory.Options options,int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 :(int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { return lowerBound; } if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } } } 有效的处理Bitmap OOM方法 public class BitmapActivity extends Activity { public ImageView imageView = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bitmap_activity); imageView = (ImageView) findViewById(R.id.imageView1); ImageAsyncTask task = new ImageAsyncTask(imageView,50,50); task.execute("http://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=http%3A%2F%2Fimg1.pconline.com.cn%2Fpiclib%2F200904%2F28%2Fbatch%2F1%2F32910%2F12408824046039mk21hbi75.jpg&thumburl=http%3A%2F%2Fimg2.imgtn.bdimg.com%2Fit%2Fu%3D3414739956%2C4196877666%26fm%3D21%26gp%3D0.jpg"); } /** * 计算出压缩比 * @param options * @param reqWith * @param reqHeight * @return */ public int calculateInSampleSize(BitmapFactory.Options options,int reqWidth,int reqHeight) { //通过参数options来获取真实图片的宽、高 int width = options.outWidth; int height = options.outHeight; int inSampleSize = 1;//初始值是没有压缩的 if(width > reqWidth || height > reqHeight) { //计算出原始宽与现有宽,原始高与现有高的比率 int widthRatio = Math.round((float)width/(float)reqWidth); int heightRatio = Math.round((float)height/(float)reqHeight); //选出两个比率中的较小值,这样的话能够保证图片显示完全 inSampleSize = widthRatio < heightRatio ? widthRatio:heightRatio; } System.out.println("压缩比: "+inSampleSize); return inSampleSize; } /** * 将InputStream转换为Byte数组 * @param in * @return */ public static byte[] inputStreamToByteArray(InputStream in) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; try { while((len = in.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } } catch (IOException e) { e.printStackTrace(); }finally{ try { in.close(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return outputStream.toByteArray(); } class ImageAsyncTask extends AsyncTask<String, Void, Bitmap> { public ImageView iv; public int reqWidth; public int reqHeight; public ImageAsyncTask(ImageView imageView,int reqWidth,int reqHeight) { this.iv = imageView; this.reqWidth = reqWidth; this.reqHeight = reqHeight; } @Override protected Bitmap doInBackground(String... params) { URL url; HttpURLConnection connection = null; InputStream in = null; Bitmap beforeBitmap = null; Bitmap afterBitmap = null; try { url = new URL(params[0]); connection = (HttpURLConnection) url.openConnection(); in = connection.getInputStream(); BitmapFactory.Options options = new BitmapFactory.Options(); //设置BitmapFactory.Options的inJustDecodeBounds属性为true表示禁止为bitmap分配内存 options.inJustDecodeBounds = true; byte[] data = inputStreamToByteArray(in); beforeBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);//这次调用的目的是获取到原始图片的宽、高,但是这次操作是没有写内存操作的 options.inSampleSize = calculateInSampleSize(options,reqWidth, reqHeight); //设置这次加载图片需要加载到内存中 options.inJustDecodeBounds = false; afterBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); float afterSize = (float)(afterBitmap.getRowBytes()*afterBitmap.getHeight()); System.out.println("压缩之后的图片大小: "+(float)afterSize/1024+"KB"); } catch (Exception e) { System.out.println(e.toString()); } return afterBitmap; } @Override protected void onPostExecute(Bitmap result) { if(result != null) imageView.setImageBitmap(result); } } } Github图片压

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册