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

正能量网站入口不用下载网站开发涉及服务

正能量网站入口不用下载,网站开发涉及服务,做网站是否过时了,网页图片怎么打印出来YOLOv5 分类模型 数据集加载 3 自定义类别 flyfish YOLOv5 分类模型 数据集加载 1 样本处理 YOLOv5 分类模型 数据集加载 2 切片处理 YOLOv5 分类模型的预处理#xff08;1#xff09; Resize 和 CenterCrop YOLOv5 分类模型的预处理#xff08;2#xff09;ToTensor 和 …YOLOv5 分类模型 数据集加载 3 自定义类别 flyfish YOLOv5 分类模型 数据集加载 1 样本处理 YOLOv5 分类模型 数据集加载 2 切片处理 YOLOv5 分类模型的预处理1 Resize 和 CenterCrop YOLOv5 分类模型的预处理2ToTensor 和 Normalize YOLOv5 分类模型 Top 1和Top 5 指标说明 YOLOv5 分类模型 Top 1和Top 5 指标实现 之前的处理方式是类别名字是文件夹名字类别ID是按照文件夹名字的字母顺序 现在是类别名字是文件夹名字按照文件列表名字顺序 例如 classes_name[n02086240, n02087394, n02088364, n02089973, n02093754, n02096294, n02099601, n02105641, n02111889, n02115641]n02086240 类别ID是0 n02087394 类别ID是1 代码处理是 if classes_name is None or not classes_name:classes, class_to_idx self.find_classes(self.root)print(not classes_name)else:classes classes_nameclass_to_idx {cls_name: i for i, cls_name in enumerate(classes)}print(is classes_name)完整 import time from models.common import DetectMultiBackend import os import os.path from typing import Any, Callable, cast, Dict, List, Optional, Tuple, Union import cv2 import numpy as npimport torch from PIL import Image import torchvision.transforms as transformsimport sysclasses_name[n02086240, n02087394, n02088364, n02089973, n02093754, n02096294, n02099601, n02105641, n02111889, n02115641]class DatasetFolder:def __init__(self,root: str,) - None:self.root rootif classes_name is None or not classes_name:classes, class_to_idx self.find_classes(self.root)print(not classes_name)else:classes classes_nameclass_to_idx {cls_name: i for i, cls_name in enumerate(classes)}print(is classes_name)print(classes:,classes)print(class_to_idx:,class_to_idx)samples self.make_dataset(self.root, class_to_idx)self.classes classesself.class_to_idx class_to_idxself.samples samplesself.targets [s[1] for s in samples]staticmethoddef make_dataset(directory: str,class_to_idx: Optional[Dict[str, int]] None,) - List[Tuple[str, int]]:directory os.path.expanduser(directory)if class_to_idx is None:_, class_to_idx self.find_classes(directory)elif not class_to_idx:raise ValueError(class_to_index must have at least one entry to collect any samples.)instances []available_classes set()for target_class in sorted(class_to_idx.keys()):class_index class_to_idx[target_class]target_dir os.path.join(directory, target_class)if not os.path.isdir(target_dir):continuefor root, _, fnames in sorted(os.walk(target_dir, followlinksTrue)):for fname in sorted(fnames):path os.path.join(root, fname)if 1: # 验证:item path, class_indexinstances.append(item)if target_class not in available_classes:available_classes.add(target_class)empty_classes set(class_to_idx.keys()) - available_classesif empty_classes:msg fFound no valid file for the classes {, .join(sorted(empty_classes))}. return instancesdef find_classes(self, directory: str) - Tuple[List[str], Dict[str, int]]:classes sorted(entry.name for entry in os.scandir(directory) if entry.is_dir())if not classes:raise FileNotFoundError(fCouldnt find any class folder in {directory}.)class_to_idx {cls_name: i for i, cls_name in enumerate(classes)}return classes, class_to_idxdef __getitem__(self, index: int) - Tuple[Any, Any]:path, target self.samples[index]sample self.loader(path)return sample, targetdef __len__(self) - int:return len(self.samples)def loader(self, path):print(path:, path)#img cv2.imread(path) # BGR HWCimgImage.open(path).convert(RGB) # RGB HWCreturn imgdef time_sync():return time.time()#sys.exit() dataset DatasetFolder(root/media/a/flyfish/source/yolov5/datasets/imagewoof/val)#image, labeldataset[7]# weights /home/a/classes.pt device cpu model DetectMultiBackend(weights, devicedevice, dnnFalse, fp16False) model.eval() print(model.names) print(type(model.names))mean[0.485, 0.456, 0.406] std[0.229, 0.224, 0.225] def preprocess(images):#实现 PyTorch Resizetarget_size 224img_w images.widthimg_h images.heightif(img_h img_w):# hwresize_img images.resize((target_size, int(target_size * img_h / img_w)), Image.BILINEAR)else:resize_img images.resize((int(target_size * img_w / img_h),target_size), Image.BILINEAR)#实现 PyTorch CenterCropwidth resize_img.widthheight resize_img.heightcenter_x,center_y width//2,height//2left center_x - (target_size//2)top center_y- (target_size//2)right center_x target_size//2bottom center_ytarget_size//2cropped_img resize_img.crop((left, top, right, bottom))#实现 PyTorch ToTensor Normalizeimages np.asarray(cropped_img)print(preprocess:,images.shape)images images.astype(float32)images (images/255-mean)/stdimages images.transpose((2, 0, 1))# HWC to CHWprint(preprocess:,images.shape)images np.ascontiguousarray(images)imagestorch.from_numpy(images)#images images.unsqueeze(dim0).float()return imagespred, targets, loss, dt [], [], 0, [0.0, 0.0, 0.0] # current batch size 1 for i, (images, labels) in enumerate(dataset):print(i:, i)im preprocess(images)images im.unsqueeze(0).to(cpu).float()print(images.shape)t1 time_sync()images images.to(device, non_blockingTrue)t2 time_sync()# dt[0] t2 - t1y model(images)yy.numpy()#print(y:, y)t3 time_sync()# dt[1] t3 - t2#batch size 1 图像推理结果是二维的#y: [[ 4.0855 -1.1707 -1.4998 -0.935 -1.9979 -2.258 -1.4691 -1.0867 -1.9042 -0.99979]]tmp1y.argsort()[:,::-1][:, :5]#batch size 1 图像推理结果是一维的 就要处理下argsort的维度#y: [ 3.7441 -1.135 -1.1293 -0.9422 -1.6029 -2.0561 -1.025 -1.5842 -1.3952 -1.1824]#print(tmp1:, tmp1)pred.append(tmp1)#print(labels:, labels)targets.append(labels)#print(for pred:, pred) # list#print(for targets:, targets) # list# dt[2] time_sync() - t3pred, targets np.concatenate(pred), np.array(targets) print(pred:, pred) print(pred:, pred.shape) print(targets:, targets) print(targets:, targets.shape) correct ((targets[:, None] pred)).astype(np.float32) print(correct:, correct.shape) print(correct:, correct) acc np.stack((correct[:, 0], correct.max(1)), axis1) # (top1, top5) accuracy print(acc:, acc.shape) print(acc:, acc) top acc.mean(0) print(top1:, top[0]) print(top5:, top[1])
http://www.zqtcl.cn/news/967193/

相关文章:

  • 域名和网站一样吗自己开发小程序要多少钱
  • 咨询公司网站源码手机优化软件哪个好用
  • 行业网站模板小型影视网站源码
  • 湖北网站建站系统哪家好微信小程序怎么注销账号
  • 温州网站推广公司沈阳网站建设服务电话
  • 2019年的阜南县建设修路网站洛阳哪里有做网站的
  • 家里电脑可以做网站服务器吗佛山网络公司哪家最好
  • 做网站属于无形资产还是费用网站制作二维码
  • ps为什么做不了视频网站最近做网站开发有前途没
  • 平面设计师参考网站做网站建设推广好做吗
  • 网站被别的域名绑定泰安做网站网络公司
  • 建设部网站业绩如何录入免费素材图片下载
  • 佛山美容网站建设如何有效的推广宣传
  • 网站全屏轮播怎么做nginx 代理 wordpress
  • 海淀公司网站搭建二级目录怎么做网站
  • 石家庄定制网站建设凡科建站做的网站收录慢吗
  • 海口企业自助建站品牌建设三年行动方案
  • 网站建设流程平台域名分析网站
  • 旅游类网站如何做推广随机网站生成器
  • 竖导航网站做网站被坑
  • 散文古诗网站建设目标做公司网站要钱吗
  • 营销网站建设规划小浪底水利枢纽建设管理局网站
  • 建站的目的网站的月度流量统计报告怎么做
  • 网站备案添加域名拼多多代运营公司十大排名
  • 网站访客qq获取系统 报价客户管理系统入口
  • 院网站建设情况报告怎么在虚拟主机上建网站
  • 厦门网站建设系统鞍山百度网站怎么制作
  • html5建设网站app开发公司不退款该怎么投诉
  • 南昌网站建设公务手工制作代加工接单网
  • 排名好的手机网站建设你知道吗 网站