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

网站备案更名网络营销策划案范本

网站备案更名,网络营销策划案范本,网站官网认证怎么做,济南做网站价格YOLOv5 分类模型 OpenCV和PyTorch两者实现预处理的差异 flyfish PyTorch封装了PIL库 简单对比下两者的使用方法 import cv2 from PIL import Image import numpy as npfull_path_file_name"/media/a//ILSVRC2012_val_00001244.JPEG"#OpenCV读取图像默认是BGR顺序 …

YOLOv5 分类模型 OpenCV和PyTorch两者实现预处理的差异

flyfish

PyTorch封装了PIL库
简单对比下两者的使用方法

import cv2
from PIL import Image
import numpy as npfull_path_file_name="/media/a//ILSVRC2012_val_00001244.JPEG"#OpenCV读取图像默认是BGR顺序
cv_image=cv2.imread(full_path_file_name) #BGR
print(cv_image.shape)
cv_image=cv2.cvtColor(cv_image,cv2.COLOR_BGR2RGB)
#print("cv_image:",cv_image)#(400, 500, 3) HWC#PIL读取图像默认是RGB顺序
pil_image=Image.open(full_path_file_name)
print("pil_image:",pil_image)
numpy_image=np.array(pil_image)
print(numpy_image.shape)#(400, 500, 3) HWC BGR
#print("numpy_image:",numpy_image)

在这里插入图片描述

这样OpenCV和PIL返回的是相同的数据

如果是height > width的情况下,图像缩放大小是
( size × height width , size ) \left(\text{size} \times \frac{\text{height}}{\text{width}}, \text{size}\right) (size×widthheight,size)

https://github.com/pytorch/vision/
vision/torchvision/transforms/functional.py

产生的问题
PyTorch中使用transforms.Resizetransforms.Resize使用了双线性插值和抗锯齿antialiasing,与cv2.resize处理不同。所以会造成推理结果有差异

def resize(img: Tensor, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR,max_size: Optional[int] = None) -> Tensor:
The output image might be different depending on its type: when downsampling, the interpolation of PIL images
and tensors is slightly different, because PIL applies antialiasing. This may lead to significant differences
in the performance of a network. Therefore, it is preferable to train and serve a model with the same input
types.

对比下差异

from skimage.metrics import structural_similarity as ssim
from skimage.metrics import peak_signal_noise_ratio as psnr
from skimage.metrics import mean_squared_error as msetarget_size =224img_w = pil_image.width
img_h = pil_image.heightimage_width, image_height =0,0
if(img_h >= img_w):# hwimage_width, image_height =target_size, int(target_size * img_h / img_w)
else:image_width, image_height =int(target_size * img_w  / img_h),target_sizeprint(image_width, image_height)
pil_resize_img = pil_image.resize((image_width, image_height), Image.BILINEAR)#print("pil_resize_img:",np.array(pil_resize_img))pil_resize_img=np.array(pil_resize_img)cv_resize_img0 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_CUBIC)
#print("cv_resize_img:",cv_resize_img0)
cv_resize_img1 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_NEAREST)
cv_resize_img2 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_LINEAR)
cv_resize_img3 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_AREA)
cv_resize_img4 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_LANCZOS4)
cv_resize_img5 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_LINEAR_EXACT)
cv_resize_img6 = cv2.resize(cv_image, (image_width, image_height), interpolation=cv2.INTER_NEAREST_EXACT)print(mse(pil_resize_img,pil_resize_img))
print(mse(pil_resize_img,cv_resize_img0))
print(mse(pil_resize_img,cv_resize_img1))
print(mse(pil_resize_img,cv_resize_img2))
print(mse(pil_resize_img,cv_resize_img3))
print(mse(pil_resize_img,cv_resize_img4))
print(mse(pil_resize_img,cv_resize_img5))
print(mse(pil_resize_img,cv_resize_img6))

可以使用structural_similarity、peak_signal_noise_ratio 、mean_squared_error对比
这里使用mean_squared_error

0.0
30.721508290816328
103.37267219387755
13.030575042517007
2.272438350340136
36.33767538265306
13.034412202380953
51.2258237670068

PyTorch推荐做法是 Therefore, it is preferable to train and serve a model with the same input types.训练和部署使用相同的输入

http://www.khdw.cn/news/42915.html

相关文章:

  • 天津做网站优化哪家好中国国家人事人才培训网证书查询
  • 觉得自己做的网站土怎么办百度排名规则
  • 贵阳网站建设方舟网络山东东营网络seo
  • wordpress更换端口太原seo排名收费
  • 西宁做网站的好公司东营seo
  • 网页制作与网站建设宝典扫描版pdf新媒体营销案例分析
  • 宿迁房产信息网官网网站关键词排名seo
  • 做网站销售会遇到哪些问题优化营商环境存在问题及整改措施
  • 云服务器可以做两个网站关键词排名是什么意思
  • 为企业设计网络营销方案关键词优化案例
  • 做网站需要ui设计吗百度引擎搜索
  • 沈阳外贸网站建设游戏推广工作好做吗
  • 微信网站推广seo优化操作
  • 浦东做网站株洲网站设计
  • 网站里面的图片做桌面不清晰彼亿营销
  • 网站用户注册增加办法外国人b站
  • 什么是网站建设seo优化入门教程
  • 网站开发 在线报名招聘网络营销推广人员
  • 最好的品牌设计网站建设saas建站
  • 深圳网站制作建设企业营销策划书模板
  • 小程序开发公司简介范本沈阳seo关键词
  • 做网站开发学什么内容裂变营销五种模式十六种方法
  • 推荐个靠谱的网站四川刚刚发布的最新新闻
  • 高端网站建设设济南最新消息
  • 用php做网站难吗淘宝权重查询
  • 如何建设国外网站免费推广方式都有哪些
  • 购物网站项目开发什么叫seo优化
  • 共享互助医疗网站建设网络营销推广活动有哪些
  • 怎么做网站监控平台长尾关键词挖掘词工具
  • 山西住房城乡建设厅网站深圳百度推广seo公司