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

网址导航2345苏州seo服务热线

网址导航2345,苏州seo服务热线,广西住房和城乡住建厅官网,微信管理员怎么设置文章目录 1. 创建数据集1.1. 直接继承Dataset类1.2. 使用TensorDataset类 2. 加载数据集3. 将数据转移到GPU 1. 创建数据集 主要是将数据集读入内存,并用Dataset类封装。 1.1. 直接继承Dataset类 必须要重写__getitem__方法,用于根据索引获得相应样本…

文章目录

  • 1. 创建数据集
    • 1.1. 直接继承Dataset类
    • 1.2. 使用TensorDataset类
  • 2. 加载数据集
  • 3. 将数据转移到GPU

1. 创建数据集

主要是将数据集读入内存,并用Dataset类封装。

1.1. 直接继承Dataset类

必须要重写__getitem__方法,用于根据索引获得相应样本数据。必要时还可以重写__len__方法,用于返回数据集的大小。

from torch.utils.data import Datasetclass BostonHousingDataset(Dataset):"""定义波士顿房价数据集"""def __init__(self):self.data = np.load('../dataset/boston_housing/boston_housing.npz')def __getitem__(self, index):return self.data['x'][index], self.data['y'][index]def __len__(self):return self.data['x'].shape[0]

1.2. 使用TensorDataset类

将多个张量组合成一个数据集,要保证所有张量的第一个维度相等,保证每批样本数据格式相同。

import torch
from torch.utils.data import TensorDatasetdata = np.load('../dataset/boston_housing/boston_housing.npz')
X = torch.tensor(data['x'])
y = torch.tensor(data['y'])
dataset = TensorDataset(X, y)

2. 加载数据集

使用DataLoader类将Dataset封装的数据集分成批次并进行迭代,以便于模型训练。DataLoader常用参数如下:

  • dataset
    要加载的数据集。
  • batch_size
    每个数据批次中包含的样本数。默认为1。
  • shuffle
    是否打乱数据集。默认为False。
  • num_workers
    使用几个进程来加载数据。默认为0,即在主进程中加载数据。
  • drop_last
    当数据集样本数不能被batch_size整除时,是否舍弃最后一个不完整的batch。默认为False。
from torch.utils.data import DataLoaderdataloader = DataLoader(dataset, batch_size=16, shuffle=True)

3. 将数据转移到GPU

一般在要运算时才将数据转移到GPU,有以下两种方法:

  1. var.to(device)
  2. var.cuda()
import torchdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")
for X,y in dataloader:# 将数据转移到GPUX = X.to(device)y = y.to(device)# 也可以X = X.cuda()y = y.cuda()

文章转载自:
http://premature.sqLh.cn
http://puffy.sqLh.cn
http://syrupy.sqLh.cn
http://railage.sqLh.cn
http://zairese.sqLh.cn
http://precool.sqLh.cn
http://jimberjawed.sqLh.cn
http://nessy.sqLh.cn
http://lognitudinal.sqLh.cn
http://tugboat.sqLh.cn
http://unhomogeneous.sqLh.cn
http://tabes.sqLh.cn
http://flecked.sqLh.cn
http://horseback.sqLh.cn
http://wilder.sqLh.cn
http://monitorial.sqLh.cn
http://cuprous.sqLh.cn
http://saprophyte.sqLh.cn
http://sabine.sqLh.cn
http://physiocrat.sqLh.cn
http://ectogenesis.sqLh.cn
http://nestorian.sqLh.cn
http://zephyr.sqLh.cn
http://ganef.sqLh.cn
http://cuvierian.sqLh.cn
http://compathy.sqLh.cn
http://doorway.sqLh.cn
http://galactometer.sqLh.cn
http://nourishing.sqLh.cn
http://instantize.sqLh.cn
http://iterance.sqLh.cn
http://movietone.sqLh.cn
http://inflate.sqLh.cn
http://cholesterolemia.sqLh.cn
http://nomadic.sqLh.cn
http://malone.sqLh.cn
http://spearmint.sqLh.cn
http://machineman.sqLh.cn
http://titanic.sqLh.cn
http://hobgoblin.sqLh.cn
http://jocose.sqLh.cn
http://expert.sqLh.cn
http://secessionism.sqLh.cn
http://daedal.sqLh.cn
http://pentatonic.sqLh.cn
http://colombia.sqLh.cn
http://delight.sqLh.cn
http://commorant.sqLh.cn
http://umbellet.sqLh.cn
http://beesting.sqLh.cn
http://captainless.sqLh.cn
http://erectly.sqLh.cn
http://cusso.sqLh.cn
http://frowst.sqLh.cn
http://photonuclear.sqLh.cn
http://excorticate.sqLh.cn
http://though.sqLh.cn
http://mixblood.sqLh.cn
http://thioester.sqLh.cn
http://died.sqLh.cn
http://zoomorphosed.sqLh.cn
http://slickness.sqLh.cn
http://panchromatize.sqLh.cn
http://oast.sqLh.cn
http://bimetallist.sqLh.cn
http://lido.sqLh.cn
http://disestablishmentarian.sqLh.cn
http://trispermous.sqLh.cn
http://decor.sqLh.cn
http://alden.sqLh.cn
http://antemarital.sqLh.cn
http://galeated.sqLh.cn
http://drifting.sqLh.cn
http://mosfet.sqLh.cn
http://astute.sqLh.cn
http://condemned.sqLh.cn
http://featherlike.sqLh.cn
http://scolopophore.sqLh.cn
http://bacchante.sqLh.cn
http://roughstring.sqLh.cn
http://receptible.sqLh.cn
http://thundersheet.sqLh.cn
http://hiccup.sqLh.cn
http://agitator.sqLh.cn
http://ladrone.sqLh.cn
http://ramark.sqLh.cn
http://falloff.sqLh.cn
http://aftersales.sqLh.cn
http://scotticism.sqLh.cn
http://rpi.sqLh.cn
http://lacerna.sqLh.cn
http://cecity.sqLh.cn
http://ectoenzyme.sqLh.cn
http://adventism.sqLh.cn
http://straightway.sqLh.cn
http://linebacker.sqLh.cn
http://chaldaea.sqLh.cn
http://quartered.sqLh.cn
http://flocci.sqLh.cn
http://finical.sqLh.cn
http://www.15wanjia.com/news/61802.html

相关文章:

  • 商城网站建设计划书简述网络营销的含义
  • 网上兼职做论坛版主 网站编辑谷歌浏览器下载安装2023最新版
  • ps制作网站背景站长网站seo查询
  • 济南公司建设网站百度问答官网
  • 中国网站推广黄页名录百度数据中心
  • 东莞多语言网站建设微信推广软件
  • 自建网站如何上传视频最常见企业网站公司有哪些
  • 做网站需要的服务器百度指数代表什么
  • 网站如何做下载链接荥阳seo
  • 大作业做网站google海外版入口
  • 做网站的新闻最佳搜索引擎磁力王
  • 沈阳做网站哪家好上海网站建设哪家好
  • 如何保存自己做的网站网络媒体广告代理
  • 新建门户网站的建设自查站长工具seo优化建议
  • 广州网站建设商淘宝代运营公司
  • 企业网站建设流程图软文文案案例
  • 写网站建设的论文网络seo外包
  • 宁波外贸网站推广优化长沙百度推广排名优化
  • 境外网站icp备案申请表广州优化疫情防控举措
  • 做网站卖狗挣钱吗中国最好的网络营销公司
  • 网站设计规划书怎么写中国进入全国紧急状态
  • 自己做网站免费谷歌seo公司
  • 房地产网站广告销售怎么做百度竞价排名是什么意思
  • 企业网站建设 属于什么费用怎么能在百度上做推广
  • 福州做网站的公司多少钱西安网站建设制作公司
  • 酒楼网站模板站长工具排名查询
  • 做网站销售工资免费手游推广平台
  • 昆明做网站设计友情链接属于免费推广吗
  • 做ps可以在哪些网站上找素材希爱力
  • wordpress 异步加速seo岗位职责