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

手表网站起名营销型企业网站建设步骤

手表网站起名,营销型企业网站建设步骤,网站后台 用什么编写,石家庄微网站建设collate_fn 函数用于处理数据加载器(DataLoader)中的一批数据。在PyTorch中使用 DataLoader 时,通过设置collate_fn,我们可以决定如何将多个样本数据整合到一起成为一个 batch。在某些情况下,该函数需要由用户自定义以满足特定需求。 import …

collate_fn 函数用于处理数据加载器(DataLoader)中的一批数据。在PyTorch中使用 DataLoader 时,通过设置collate_fn,我们可以决定如何将多个样本数据整合到一起成为一个 batch。在某些情况下,该函数需要由用户自定义以满足特定需求。

import torch
from torch.utils.data import Dataset, DataLoader
import numpy as npclass MyDataset(Dataset):def __init__(self, imgs, labels):self.imgs = imgsself.labels = labelsdef __len__(self):return len(self.imgs)def __getitem__(self, idx):img = self.imgs[idx]out_img = img.astype(np.float32)out_img = out_img.transpose(2, 0, 1) #[3, 300, 150]h,w,c  -->>  c,h,wout_label = self.labels[idx] #[4, 5] or [2, 5]return out_img, out_label#if batchsize=3
#batch is list, [3]
#batch0 tuple2  (np[3, 300, 150], np[4, 5])
#batch1 tuple2  (np[3, 300, 150], np[2, 5])
#batch2 tuple2  (np[3, 300, 150], np[4, 5])
def my_collate_fn(batch):"""Custom collate fn for dealing with batches of images that have a differentnumber of associated object annotations (bounding boxes).Arguments:batch: (tuple) A tuple of tensor images and lists of annotationsReturn:A tuple containing:1) (tensor) batch of images stacked on their 0 dim2) (list of tensors) annotations for a given image are stacked on0 dim"""targets = []imgs = []for sample in batch:imgs.append(torch.FloatTensor(sample[0]))targets.append(torch.FloatTensor(sample[1]))imgs_out = torch.stack(imgs, 0) #[3, 3, 300, 150]return imgs_out, targetsimg_data = []
label_data = []nums = 34
H=300
W=150
for _ in range(nums):random_img = np.random.randint(low=0, high=255, size=(H, W, 3))nums_target = np.random.randint(low=0, high=10)random_xyxy_label = np.random.random((nums_target, 5))img_data.append(random_img)label_data.append(random_xyxy_label)dataset = MyDataset(img_data, label_data)
dataloader = DataLoader(dataset, batch_size=3, collate_fn=my_collate_fn)for cnt, (img, label) in enumerate(dataloader):print("==>>", cnt, ",  img shape=", img.shape)for i in range(len(label)):print("label shape=", label[i].shape)

打印如下:

==>> 0 ,  img shape= torch.Size([3, 3, 300, 150])
label shape= torch.Size([8, 5])
label shape= torch.Size([2, 5])
label shape= torch.Size([5, 5])
==>> 1 ,  img shape= torch.Size([3, 3, 300, 150])
label shape= torch.Size([3, 5])
label shape= torch.Size([8, 5])
label shape= torch.Size([5, 5])
==>> 2 ,  img shape= torch.Size([3, 3, 300, 150])
label shape= torch.Size([7, 5])
label shape= torch.Size([1, 5])
label shape= torch.Size([8, 5])
http://www.hkea.cn/news/17385/

相关文章:

  • 网站建设有没有十大搜索引擎网站
  • 电子商务实网站的建设课件网站的优化策略方案
  • 喀什网站建设公司营销网络的建设
  • 药店网站模板营销软件代理推广
  • 站长工具seo综合查询columbu cat新闻今天的最新新闻
  • 网站托管哪家公司好常见的网络营销模式
  • 注册公司是在哪里办理seo建站工具
  • 做收集信息的网站域名seo查询
  • 云南省建设执业注册管理中心网站怎么优化自己网站的关键词
  • 怎么做北京赛车网站软文范文大全1000字
  • 专业医院网站建设18款免费软件app下载
  • 上海集酷网站网站建设黄页视频
  • 专用主机方式建设网站媒介星软文平台
  • 两学一做考试网站seo咨询价格找推推蛙
  • 如何修改wordpress后台绑定的域名seo网站推广与优化方案
  • 温州seo优化公司seo最新教程
  • 百度山西网站建设和百度推广世界十大网站排名
  • 网站建设服务器可以租吗seo关键词优化软件合作
  • 西宁手机网站微站建设常德seo公司
  • 河北省住房和城乡建设厅官方网站凡科建站
  • php语言 电商网站建设网店营销
  • 网站备案全国合作拍照点 腾讯云互动营销案例
  • 重庆祥云平台做网站长沙网络公司营销推广
  • 河南网站建设推广运营广告联盟推广
  • 机械加工网上接单平台有哪些啊?搜索引擎优化趋势
  • 看到一个电商网站帮做淘宝seo每日
  • 怎么做网站教程 用的工具bt搜索引擎最好用的
  • 家居定制类网站建设seo是搜索引擎营销吗
  • 做游戏制作 网站黑马培训价目表
  • 网络规划方案计划书电脑清理优化大师