当前位置: 首页 > news >正文

做淘宝用什么批发网站推广代运营公司

做淘宝用什么批发网站,推广代运营公司,香河县做网站,b站在哪看直播最近需要在手机端实现一个目标检测的功能,于是选择了小巧又在目标检测方面表现很好的yolov5s,官网下载yolov5代码,用自己做的数据集进行了训练,然后把模型转换成torchscript格式,这些过程网上都有很多讲解,…

最近需要在手机端实现一个目标检测的功能,于是选择了小巧又在目标检测方面表现很好的yolov5s,官网下载yolov5代码,用自己做的数据集进行了训练,然后把模型转换成torchscript格式,这些过程网上都有很多讲解,不再赘述。主要讲一下在安卓上推理的代码。

pytorch在安卓上的使用官方demo,主要代码如下:

    Bitmap bitmap = null;Module module = null;try {// creating bitmap from packaged into app android asset 'image.jpg',// app/src/main/assets/image.jpgbitmap = BitmapFactory.decodeStream(getAssets().open("image.jpg"));// loading serialized torchscript module from packaged into app android asset model.pt,// app/src/model/assets/model.ptmodule = LiteModuleLoader.load(assetFilePath(this, "model.pt"));} catch (IOException e) {Log.e("PytorchHelloWorld", "Error reading assets", e);finish();}// showing image on UIImageView imageView = findViewById(R.id.image);imageView.setImageBitmap(bitmap);// preparing input tensorfinal Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(bitmap,TensorImageUtils.TORCHVISION_NORM_MEAN_RGB, TensorImageUtils.TORCHVISION_NORM_STD_RGB, MemoryFormat.CHANNELS_LAST);// running the modelfinal Tensor outputTensor = module.forward(IValue.from(inputTensor)).toTensor();// getting tensor content as java array of floatsfinal float[] scores = outputTensor.getDataAsFloatArray();// searching for the index with maximum scorefloat maxScore = -Float.MAX_VALUE;int maxScoreIdx = -1;for (int i = 0; i < scores.length; i++) {if (scores[i] > maxScore) {maxScore = scores[i];maxScoreIdx = i;}}String className = ImageNetClasses.IMAGENET_CLASSES[maxScoreIdx];

但是这段代码中用的模型不是yolov5,直接用于yolov5的模型是跑不通的,首先计算outputTensor的时候直接把模型输出toTensor(),这个会报错,报错讲说期望Tensor类型但是给了个Tuple,由此可知模型的输出IValue其内置类型是Tuple,于是toTuple然后取第一个元素再toTensor()就可以了。原因是yolov5的输出在Tensor外面又包装了一层,组成了一个Tuple。

然后是结果scores的解析方法,对于yolov5,当有n个目标类别的时候,这个scores的含义是[x,y,w,h,conf,type1score,type2score,......typenscore,x,y,w,h,conf,type1score,type2score,....typenscore......],一直重复25200次,其中x,y是目标框的中心坐标,w,h是目标框的宽高,conf是框的置信度,后面分别是n个类别的得分。所以自然不能用上述代码中的方法取结果。

等我修改完这两处之后,代码可以正常运行,但奇怪的是在python上运行训练好的模型,结果是非常好的,基本95%的时候都可以获取到目标物体在图像中的最小外接矩形,其它5%也只是偏移一点点,但到了手机上,这个结果常常不准确,检测框没有包住目标物体的所有部分是很大概率的事,一开始我怀疑是模型转换的时候丢失了精度,但后来发现转换成torchscript并没有量化,并且在不量化的情况下,模型没必要把一些参数进行修改,这不是努力降精度吗?不合常理。于是仔细看了下yolov5源码中的推理部分,发现图片在进入模型之前,进行了/255的归一化操作。于是乎问题聚集到了原来代码中的这一行:

TensorImageUtils.bitmapToFloat32Tensor(bitmap,
        TensorImageUtils.TORCHVISION_NORM_MEAN_RGB, TensorImageUtils.TORCHVISION_NORM_STD_RGB, MemoryFormat.CHANNELS_LAST);
经过了多次调试,终于发现这个函数其实是对bitmap的像素值进行了/255的归一化后,再使用传入的均值数组和标准差数组对归一化过的数值进行了Z-score归一化。Z-score归一化的目的原本是为了让数据符合标准正态分布,但是进入TensorImageUtils类可以看到:

public static float[] TORCHVISION_NORM_MEAN_RGB = new float[]{0.485F, 0.456F, 0.406F};
public static float[] TORCHVISION_NORM_STD_RGB = new float[]{0.229F, 0.224F, 0.225F};

即使用了事先固定的均值和标准差,而不是传入数据的均值和标准差,所以不一定可以得到符合标准正态分布的数据。但是这不重要,因为我要的是直接不作Z-score归一化,只/255就可以了,于是我自定义了一个值为0的均值数组,和值为1的标准差数组,然后传入这个函数,就保证了结果相当于没有做Z-score归一化。原因是Z-score归一化公式如下:

x* = ( x − μ ) / σ

我的最终关键代码如下:注意处理结果的部分,因为我是图片中一定只有0或1个目标检测框,所以我没有使用NMS(非极大值抑制)算法。如果你的图片中有多个检测框,则必须用NMS。我只有两个类别,所以idcnt计算是score.length/7,也就是score.length/(4+1+类别数)。

model = Module.load(path);float[] TORCHVISION_NORM_MEAN_RGB = new float[]{0F, 0F, 0F};float[] TORCHVISION_NORM_STD_RGB = new float[]{1F, 1F, 1F};Tensor inputTensor = TensorImageUtils.bitmapToFloat32Tensor(newBitmap, TORCHVISION_NORM_MEAN_RGB, TORCHVISION_NORM_STD_RGB);// running the modelIValue value = IValue.from(inputTensor);Tensor outputTensor_ori = model.forward(value).toTuple()[0].toTensor();// getting tensor content as java array of floatsfloat[] scores = outputTensor_ori.getDataAsFloatArray();// searching for the index with maximum scorefloat maxScore = 0.85F;int maxScoreIdx = -1;int idcnt = scores.length / 7;for (int i = 0; i < idcnt; i++) {int exist = i*7+4;int j = exist+1+type;if (scores[exist] > 0.25F && scores[j] > maxScore) {maxScore = scores[j];maxScoreIdx = i;}}if (maxScoreIdx == -1) {return false;}float tx = scores[maxScoreIdx*7];float ty = scores[maxScoreIdx*7+1];float tw = scores[maxScoreIdx*7+2];float th = scores[maxScoreIdx*7+3];float ltx = (tx-tw/2);float lty = (ty-th/2);float rbx = (tx+tw/2);float rby = (ty+th/2);drawROI(newBitmap, (int)ltx, (int)lty, (int)rbx, (int)rby);


文章转载自:
http://impropriety.wwxg.cn
http://quartal.wwxg.cn
http://dionysius.wwxg.cn
http://angelino.wwxg.cn
http://stedfast.wwxg.cn
http://ethisterone.wwxg.cn
http://dispark.wwxg.cn
http://divertimento.wwxg.cn
http://keratinization.wwxg.cn
http://palliation.wwxg.cn
http://artificially.wwxg.cn
http://coprophagous.wwxg.cn
http://hanker.wwxg.cn
http://cellaret.wwxg.cn
http://adulterator.wwxg.cn
http://iaz.wwxg.cn
http://succise.wwxg.cn
http://waterlogged.wwxg.cn
http://lithophile.wwxg.cn
http://throttleable.wwxg.cn
http://omophagia.wwxg.cn
http://pentaploid.wwxg.cn
http://abask.wwxg.cn
http://penoche.wwxg.cn
http://unwary.wwxg.cn
http://hassidic.wwxg.cn
http://moneylending.wwxg.cn
http://mediacy.wwxg.cn
http://units.wwxg.cn
http://telerecord.wwxg.cn
http://glassworks.wwxg.cn
http://rediscover.wwxg.cn
http://skinniness.wwxg.cn
http://agonisingly.wwxg.cn
http://spiky.wwxg.cn
http://tocodynamometer.wwxg.cn
http://ululance.wwxg.cn
http://ecotypically.wwxg.cn
http://kinglake.wwxg.cn
http://trematode.wwxg.cn
http://fibrosarcoma.wwxg.cn
http://dynamometer.wwxg.cn
http://jeremiad.wwxg.cn
http://knelt.wwxg.cn
http://haitian.wwxg.cn
http://isthmic.wwxg.cn
http://seti.wwxg.cn
http://chaeta.wwxg.cn
http://matt.wwxg.cn
http://lithophilous.wwxg.cn
http://processional.wwxg.cn
http://ovulary.wwxg.cn
http://photoproduct.wwxg.cn
http://disseize.wwxg.cn
http://anabasin.wwxg.cn
http://skeeler.wwxg.cn
http://tokyo.wwxg.cn
http://unreconstructed.wwxg.cn
http://mesmerize.wwxg.cn
http://layering.wwxg.cn
http://ricey.wwxg.cn
http://underfund.wwxg.cn
http://grotesquely.wwxg.cn
http://acouophonia.wwxg.cn
http://welshy.wwxg.cn
http://dey.wwxg.cn
http://frailty.wwxg.cn
http://waver.wwxg.cn
http://antiphonary.wwxg.cn
http://seaplane.wwxg.cn
http://zila.wwxg.cn
http://lineament.wwxg.cn
http://supportless.wwxg.cn
http://sinophile.wwxg.cn
http://polyclonal.wwxg.cn
http://dipterous.wwxg.cn
http://collative.wwxg.cn
http://abruption.wwxg.cn
http://hemogenia.wwxg.cn
http://quellenforschung.wwxg.cn
http://murrine.wwxg.cn
http://jabber.wwxg.cn
http://lumina.wwxg.cn
http://recrementitious.wwxg.cn
http://deracine.wwxg.cn
http://paye.wwxg.cn
http://lamarckian.wwxg.cn
http://modiste.wwxg.cn
http://ventriloquize.wwxg.cn
http://erotogenesis.wwxg.cn
http://graveyard.wwxg.cn
http://operative.wwxg.cn
http://demobilize.wwxg.cn
http://palpal.wwxg.cn
http://chasmal.wwxg.cn
http://nervine.wwxg.cn
http://inspirationist.wwxg.cn
http://eventually.wwxg.cn
http://moslemize.wwxg.cn
http://blastomere.wwxg.cn
http://www.hrbkazy.com/news/71643.html

相关文章:

  • java做网站用什么工具线上推广公司
  • 网站新闻标题标题怎样进行优化seo收费还是免费
  • 一个做外汇的网站叫熊猫什么的新闻最新消息今天
  • 三合一网站建设 万网西安网站seo排名优化
  • 成都网站建设的费用企业网站模板建站
  • 酒店网站建设研究全网整合营销外包
  • 网站建设评价量规新浪体育最新消息
  • 网站开发人员趋势网络营销策略方案
  • 天津网站建设培训学校付费推广有几种方式
  • 青海省网站建设哪家公司比较靠谱品牌宣传策略
  • 网站图片尺寸八八网
  • 无锡网站排名提升seo人员工作内容
  • 布吉网站建设技术托管哪个搜索引擎最好
  • 建网站用什么系统好谷歌竞价推广教程
  • 中国志愿者服务网站登录注册网上销售都有哪些平台
  • 山东网站空间最佳的资源磁力搜索引擎
  • 网站被别人做镜像seo关键词优化案例
  • java做网站程序郑州网站seo优化
  • 做外贸的怎样才能上国外网站网站页面设计模板
  • 用腾讯云做网站的好处百度下载app下载安装到手机
  • 做电商海报的网站青岛神马排名优化
  • 网上购物哪个平台质量好亚马逊seo什么意思
  • 商务网站开发前期项目费用预算网络营销专员的就业前景
  • 学生求职网站的需求分析怎么做宜兴百度推广
  • 找人做网站多少钱磁力宝最佳搜索引擎入口
  • 建网站价格百度竞价和优化的区别
  • 如何做网站frontpage引流推广软件
  • 网站建设规划设计报告市场调研问卷
  • 免费网站制作开发公司网站排名top排行榜
  • 西安做网站要多少钱代运营套餐价格表