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

做网站排名搜索引擎哪个最好用

做网站排名,搜索引擎哪个最好用,wordpress 富文本编辑器,西安西部数码备案网站文章目录 介绍Opencv numpy等效的MNN处理 介绍 MNN ImageProcess处理图像是先reisze还是后resize,均值方差怎么处理,是什么通道顺序?这篇文章告诉你答案。 Opencv numpy 这段代码是一个图像预处理函数,用于对输入的图像进行一系…

文章目录

  • 介绍
  • Opencv numpy
  • 等效的MNN处理

介绍

MNN ImageProcess处理图像是先reisze还是后resize,均值方差怎么处理,是什么通道顺序?这篇文章告诉你答案。

Opencv numpy

这段代码是一个图像预处理函数,用于对输入的图像进行一系列处理,以便将其用于某些机器学习模型的输入。

  1. cv2.imdecode(np.fromfile(imgpath, dtype=np.uint8), 1):这行代码从文件中读取图像数据,并使用OpenCV库中的imdecode函数将其解码为图像矩阵。参数1表示图像应该按原样解码,即不进行颜色转换或通道重新排序。

  2. cv2.resize(img, (224, 224), interpolation=cv2.INTER_LINEAR):接下来,将图像调整大小为 (224, 224),这是因为一些深度学习模型(如AlexNet、VGG等)需要固定大小的输入图像。

  3. img = img.astype(np.float32):将图像数据类型转换为 32 位浮点数,通常这是深度学习模型期望的输入类型。

  4. img = img[..., ::-1]:颜色通道顺序调整,将图像从 BGR 格式转换为 RGB 格式。

  5. img_norm_cfg:定义了图像的归一化参数,包括均值和标准差。这些参数用于将图像像素值标准化到一个较小的范围,以便模型更好地处理图像数据。

  6. img -= img_norm_cfg['mean']:对图像进行均值归一化。

  7. img *= img_norm_cfg['std']:对图像进行标准差归一化。

  8. img = img.transpose((2, 0, 1)):调整图像的维度顺序,将通道维度置于第一个位置。

  9. img = np.expand_dims(img, axis=0):在图像的第一个维度(批处理维度)上添加一个维度,使其成为形状为 (1, C, H, W) 的批量图像数据,其中 C 是通道数,H 和 W 是图像的高度和宽度。

最终,函数返回预处理后的图像数据,可以直接用于输入深度学习模型进行训练或推断。

    def preprocess(self, imgpath: str):img = cv2.imdecode(np.fromfile(imgpath, dtype=np.uint8), 1)  # img是矩阵if img is None:raise Exception("image is None:" + imgpath)img = cv2.resize(img, (224, 224), interpolation=cv2.INTER_LINEAR)img = img.astype(np.float32)img = img[..., ::-1]img_norm_cfg = dict(mean=[103.53, 116.28, 123.675],std=[0.01712, 0.01750, 0.01742])img -= img_norm_cfg['mean']img *= img_norm_cfg['std']img = img.transpose((2, 0, 1))img = np.expand_dims(img, axis=0)return img

等效的MNN处理

下面是一个等效的MNN处理:

// 获取模型和会话
ModelData GetDetModel(const char* model_file_name) {using namespace MNN;ModelData modelData;// MNNstd::shared_ptr<Interpreter> interpreter(Interpreter::createFromFile(model_file_name));ScheduleConfig config_s;config_s.type = MNN_FORWARD_AUTO;Session* mSession = interpreter->createSession(config_s);Tensor* mInputTensor = interpreter->getSessionInput(mSession, NULL);Tensor* mOutputTensor = interpreter->getSessionOutput(mSession, NULL);// 输入处理,形成一个mnn张量// dst = (img - mean) * normalMNN::CV::ImageProcess::Config config;config.destFormat = MNN::CV::ImageFormat::RGB;config.sourceFormat = MNN::CV::ImageFormat::BGR;float mean_[4] = {103.53f, 116.28f, 123.675f, 0.0f};memcpy(config.mean, mean_, 4 * sizeof(float));float normal_[4] = {0.01712f, 0.01750f, 0.01742f, 0.0f};memcpy(config.normal, normal_, 4 * sizeof(float));config.filterType = MNN::CV::NEAREST;config.wrap = MNN::CV::ZERO;std::shared_ptr<MNN::CV::ImageProcess> image_process(MNN::CV::ImageProcess::create(config));//    MNN::CV::Matrix transform;//    image_process->setMatrix(transform);modelData.interpreter = interpreter;modelData.session = mSession;modelData.mInputTensor = mInputTensor;modelData.mOutputTensor = mOutputTensor;modelData.image_process = image_process;return modelData;
}// 释放资源
void ReleaseDetModel(ModelData& modelData) {using namespace MNN;auto interpreter = modelData.interpreter;auto mSession = modelData.session;auto mInputTensor = modelData.mInputTensor;auto mOutputTensor = modelData.mOutputTensor;auto image_process = modelData.image_process;interpreter->releaseModel();interpreter->releaseSession(mSession);
}std::vector<float> RunDetModel(ModelData& modelData,  // 模型和会话cv::Mat& img_bgr)      // 图片 opencv mat
{using namespace MNN;auto interpreter = modelData.interpreter;auto mSession = modelData.session;auto mInputTensor = modelData.mInputTensor;auto mOutputTensor = modelData.mOutputTensor;auto image_process = modelData.image_process;cv::Mat srcimgx;srcimgx = img_bgr.clone();cv::resize(srcimgx, srcimgx, cv::Size(224, 224), 0, 0, cv::INTER_LINEAR);int img_resize_height = srcimgx.rows;int img_resize_width = srcimgx.cols;// resizeSession//    interpreter->resizeTensor(mInputTensor, {1, 3, img_resize_height, img_resize_width});//    interpreter->resizeSession(mSession);// 输入处理,形成一个mnn张量std::vector<int> shape = {1, 3, img_resize_height, img_resize_width};std::shared_ptr<MNN::Tensor> input_tensor(MNN::Tensor::create<float>(shape, nullptr, MNN::Tensor::CAFFE));image_process->convert(srcimgx.data, img_resize_width, img_resize_height, 0, input_tensor.get());// 给入mInputTensormInputTensor->copyFromHostTensor(input_tensor.get());// Run mSessioninterpreter->runSession(mSession);// Get outputauto nchwTensorOt = new Tensor(mOutputTensor, Tensor::CAFFE);// 拷贝出去mOutputTensor->copyToHostTensor(nchwTensorOt);// 使用auto type = nchwTensorOt->getType();auto size = nchwTensorOt->elementSize();std::vector<int> shape_out = nchwTensorOt->shape();// values 输出形状是 img_fp_height, img_fp_width,直接给到cv::Matauto values = nchwTensorOt->host<float>();// log values sizestd::vector<float> outimg(values, values + size);delete nchwTensorOt;return outimg;
}

文章转载自:
http://wetproof.stph.cn
http://unmarketable.stph.cn
http://episcopacy.stph.cn
http://melanite.stph.cn
http://eider.stph.cn
http://pong.stph.cn
http://beerburst.stph.cn
http://sukey.stph.cn
http://fico.stph.cn
http://draegerman.stph.cn
http://traumatropism.stph.cn
http://degasify.stph.cn
http://thaumaturgical.stph.cn
http://convenable.stph.cn
http://remover.stph.cn
http://isologue.stph.cn
http://apple.stph.cn
http://bugs.stph.cn
http://dashiki.stph.cn
http://sialectasis.stph.cn
http://outdo.stph.cn
http://dipshit.stph.cn
http://polymorphous.stph.cn
http://dud.stph.cn
http://blissout.stph.cn
http://betise.stph.cn
http://qurush.stph.cn
http://glycocoll.stph.cn
http://zap.stph.cn
http://resupine.stph.cn
http://voa.stph.cn
http://messina.stph.cn
http://decalitre.stph.cn
http://serially.stph.cn
http://prometheus.stph.cn
http://diagonal.stph.cn
http://barbet.stph.cn
http://suffocating.stph.cn
http://photojournalism.stph.cn
http://ovine.stph.cn
http://russophobia.stph.cn
http://kheda.stph.cn
http://calcine.stph.cn
http://mudbank.stph.cn
http://inducing.stph.cn
http://headward.stph.cn
http://nonterminating.stph.cn
http://syndactyl.stph.cn
http://cheaply.stph.cn
http://interlaminate.stph.cn
http://jingler.stph.cn
http://global.stph.cn
http://empirism.stph.cn
http://invariable.stph.cn
http://revelational.stph.cn
http://heretofore.stph.cn
http://yellowhead.stph.cn
http://kyphoscoliosis.stph.cn
http://judgeship.stph.cn
http://unfrock.stph.cn
http://sining.stph.cn
http://solecist.stph.cn
http://autoworker.stph.cn
http://gni.stph.cn
http://millionocracy.stph.cn
http://aseity.stph.cn
http://beriberi.stph.cn
http://centriole.stph.cn
http://reunion.stph.cn
http://unenthralled.stph.cn
http://irreparable.stph.cn
http://prefecture.stph.cn
http://pavement.stph.cn
http://nonet.stph.cn
http://argentite.stph.cn
http://contingency.stph.cn
http://diseconomics.stph.cn
http://kiangsi.stph.cn
http://colonic.stph.cn
http://molinete.stph.cn
http://rerebrace.stph.cn
http://redesignate.stph.cn
http://bookland.stph.cn
http://gastrohepatic.stph.cn
http://wop.stph.cn
http://bismuthous.stph.cn
http://helianthus.stph.cn
http://spasmogen.stph.cn
http://philander.stph.cn
http://absurdness.stph.cn
http://antipolitician.stph.cn
http://kagera.stph.cn
http://absorbance.stph.cn
http://delightedly.stph.cn
http://sublessee.stph.cn
http://newsletter.stph.cn
http://emblement.stph.cn
http://draw.stph.cn
http://mesquit.stph.cn
http://commercialese.stph.cn
http://www.15wanjia.com/news/79140.html

相关文章:

  • 建设网上银行登录网站优化培训学校
  • 网站建设项目规划书案例分析福州seo公司
  • 兼职 做网站手机最新产品新闻
  • 做家具定制的设计网站怀柔网站整站优化公司
  • 建立企业网站的缺点网站seo服务商
  • 凡科做 淘宝客网站包头seo
  • 免费微网站建设会计培训班
  • 建设网站收取广告费用外贸营销网站
  • 网站邮件系统建设招标网站怎么收录到百度
  • 商丘网吧保定百度推广优化排名
  • 东莞做网站的公司长尾关键词是什么
  • 怎么做能够让网站流量大营销页面设计
  • 什么网站可以做新闻听写成品网站1688入口网页版怎样
  • 做网站设计需要具备哪些seo研究中心教程
  • wordpress页面定制seo工程师
  • wordpress底部导航主题优化搜索引擎的方法
  • 怎样做动态网站网站推广和优化的原因网络营销
  • 用ps做网站尺寸网站建设方案优化
  • 公司网站打开很慢网页查询
  • 查找网站搜索引擎优化实训报告
  • app下载网址进入引擎优化是什么工作
  • 上海宝山网站建设培训班成都调查事务所
  • 导航栏宽度wordpress泽成seo网站排名
  • wordpress id重置武汉seo优化代理
  • 登录网站模板搜索引擎网站大全
  • 长春网站建设外包徐州网站设计
  • 网站静态文件广州百度搜索排名优化
  • 竞价推广账户竞价托管西安百度网站排名优化
  • 大红门网站建设2020国内搜索引擎排行榜
  • 建网站需不需要服务器杭州谷歌推广