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

杭州哪家网站建设公司好点中国航天科工集团有限公司

杭州哪家网站建设公司好点,中国航天科工集团有限公司,网站备案导致网站被k,免费建立网页文章目录 介绍Opencv numpy等效的MNN处理 介绍 MNN ImageProcess处理图像是先reisze还是后resize#xff0c;均值方差怎么处理#xff0c;是什么通道顺序#xff1f;这篇文章告诉你答案。 Opencv numpy 这段代码是一个图像预处理函数#xff0c;用于对输入的图像进行一系… 文章目录 介绍Opencv numpy等效的MNN处理 介绍 MNN ImageProcess处理图像是先reisze还是后resize均值方差怎么处理是什么通道顺序这篇文章告诉你答案。 Opencv numpy 这段代码是一个图像预处理函数用于对输入的图像进行一系列处理以便将其用于某些机器学习模型的输入。 cv2.imdecode(np.fromfile(imgpath, dtypenp.uint8), 1)这行代码从文件中读取图像数据并使用OpenCV库中的imdecode函数将其解码为图像矩阵。参数1表示图像应该按原样解码即不进行颜色转换或通道重新排序。 cv2.resize(img, (224, 224), interpolationcv2.INTER_LINEAR)接下来将图像调整大小为 (224, 224)这是因为一些深度学习模型如AlexNet、VGG等需要固定大小的输入图像。 img img.astype(np.float32)将图像数据类型转换为 32 位浮点数通常这是深度学习模型期望的输入类型。 img img[..., ::-1]颜色通道顺序调整将图像从 BGR 格式转换为 RGB 格式。 img_norm_cfg定义了图像的归一化参数包括均值和标准差。这些参数用于将图像像素值标准化到一个较小的范围以便模型更好地处理图像数据。 img - img_norm_cfg[mean]对图像进行均值归一化。 img * img_norm_cfg[std]对图像进行标准差归一化。 img img.transpose((2, 0, 1))调整图像的维度顺序将通道维度置于第一个位置。 img np.expand_dims(img, axis0)在图像的第一个维度批处理维度上添加一个维度使其成为形状为 (1, C, H, W) 的批量图像数据其中 C 是通道数H 和 W 是图像的高度和宽度。 最终函数返回预处理后的图像数据可以直接用于输入深度学习模型进行训练或推断。 def preprocess(self, imgpath: str):img cv2.imdecode(np.fromfile(imgpath, dtypenp.uint8), 1) # img是矩阵if img is None:raise Exception(image is None: imgpath)img cv2.resize(img, (224, 224), interpolationcv2.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, axis0)return img等效的MNN处理 下面是一个等效的MNN处理 // 获取模型和会话 ModelData GetDetModel(const char* model_file_name) {using namespace MNN;ModelData modelData;// MNNstd::shared_ptrInterpreter 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_ptrMNN::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::vectorfloat 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::vectorint shape {1, 3, img_resize_height, img_resize_width};std::shared_ptrMNN::Tensor input_tensor(MNN::Tensor::createfloat(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::vectorint shape_out nchwTensorOt-shape();// values 输出形状是 img_fp_height, img_fp_width直接给到cv::Matauto values nchwTensorOt-hostfloat();// log values sizestd::vectorfloat outimg(values, values size);delete nchwTensorOt;return outimg; }
http://www.hkea.cn/news/14497847/

相关文章:

  • 泉州个人建站模板营口建网站
  • 舟山网站建设seo九九建站-网站建设 网站推广 seo优化 seo培训
  • 深圳视频网站开发做进化树的在线网站
  • 重庆seo网站推广工具南宁做网站公司必荐云尚网络
  • 网站设计的基本步骤和方法百度怎么创建网站
  • 网站制作 中企动力公司暗网网站建设
  • 网站平台建设属于什么采购厦门专业的网站建设
  • 免费网站建设模版云盘亚马逊aws永久免费服务69
  • 给酒吧做网站建立网站要多少钱一年
  • 做网站功能模块开展建设文明网站活动方案
  • 设计一个网站的步骤市通建设工程质量监督局网站
  • 商城类网站建设+数据库网站建设语言都有什么软件
  • 做网站费用分几块apache搭建wordpress
  • 二手交易网站开发可参考文献大网站
  • 6免费网站建站wordpress模班之家
  • 广州个人网站备案要多久哈尔滨到牡丹江
  • 百度权重怎么看广州seo报价
  • 以营销型网站为主要营销方式的案例山东网站营销
  • 网站建设对于学校的重要性个人网站做跳转怎么弄
  • 安徽智能网站建设推荐北京软装设计公司有哪些
  • 买微单的网站建设wordpress 页面 跳转
  • 青岛网站设计推广小程序制作平台排行榜前十名
  • 西部数据网站备案流程外贸公司开办流程
  • 网站怎么换域名国外注册公司流程及费用
  • 网络科技有限公司网站建设泗洪网站
  • 怎样做建网站做淘客网站建站工具
  • 网站建设主要工作内容企业网站建设基本标准
  • 徐州网站定制网站如何做微信推广
  • 网站源码平台三亚市住房和城乡建设厅网站
  • 建设公共资源交易中心网站代理加盟微信网站建设