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

做图的网站婚纱摄影东莞网站建设技术支持

做图的网站,婚纱摄影东莞网站建设技术支持,传奇广告查询网站,深圳最好的网站开发公司数据转换与加载项目列表前言标签转换RGB标签到类别标签映射RGB标签转换成类别标签数据数据加载随机裁剪数据加载项目列表 语义分割项目#xff08;一#xff09;——数据概况及预处理 语义分割项目#xff08;二#xff09;——标签转换与数据加载 语义分割项目#x… 数据转换与加载项目列表前言标签转换RGB标签到类别标签映射RGB标签转换成类别标签数据数据加载随机裁剪数据加载项目列表 语义分割项目一——数据概况及预处理 语义分割项目二——标签转换与数据加载 语义分割项目三——语义分割模型U-net和deeplavb3 前言 在前面的文章中我们介绍了数据集的概况以及预处理在训练之前除了数据预处理之外我们还需要对于标签进行处理因为标签是以RGB格式存放的我们需要把他们变换成常见的类别标签并且因为语义分割问题是针对像素的分类在数据量较大的情况下容易内存溢出OOM所以我们往往需要重写数据加载类针对大量数据进行加载。 标签转换 RGB标签到类别标签映射 我们知道RGB图像的数据点有三个通道每个通道取值范围为0−2550-2550−255 即0−2550−255,0−2550-255 0-255, 0-2550−2550−255,0−255那么我们可以考虑这样一个思路我们设置一个长度为2553255^32553的向量这样就可以容纳所有像素的取值范围。在之前的文章中我们定义了VOC_COLORMAP和VOC_CLASSES对应着像素形式的类别和文字形式的类别 VOC_COLORMAP [[226, 169, 41], [132, 41, 246], [110, 193, 228], [60, 16, 152], [254, 221, 58], [155, 155, 155]] VOC_CLASSES [Water, Land (unpaved area), Road, Building, Vegetation, Unlabeled]那么我们构造一个voc_colormap2label函数通过enumerate遍历VOC_COLORMAP获取索引与像素类别并赋值colormap2label def voc_colormap2label():colormap2label torch.zeros(256 ** 3, dtypetorch.long)for i, colormap in enumerate(VOC_COLORMAP):colormap2label[(colormap[0] * 256 colormap[1]) * 256 colormap[2]] ireturn colormap2labelRGB标签转换成类别标签数据 通过上面的函数我们可以获得RGB标签到类别标签的映射关系那么我们在构造一个函数传入RGB标签数据colormap和RGB标签向类别标签的映射colormap2label返回值是类别标签。 def voc_label_indices(colormap, colormap2label):colormap colormap.permute(1, 2, 0).numpy().astype(int32)idx ((colormap[:, :, 0] * 256 colormap[:, :, 1]) * 256 colormap[:, :, 2])return colormap2label[idx]数据加载 随机裁剪 由于输入图像的形状不能确定并且有时图像太大会影响训练速度或者影响内存所以我们需要对于图像和标签进行裁剪我们调用torchvision.transforms.RandomCrop.get_params可以获取随机裁剪的区域这一步的操作是为了使得数据和标签的区域匹配然后我们使用torchvision.transforms.functional.crop可以进行数据和标签同步裁剪。 def voc_rand_crop(feature, label, height, width):rect torchvision.transforms.RandomCrop.get_params(feature, (height, width))feature torchvision.transforms.functional.crop(feature, *rect)label torchvision.transforms.functional.crop(label, *rect)return feature, label数据加载 我们简单介绍一下数据加载类SemanticDataset 函数名用途__init__用于初始参数设置normalize_image将图像设置成0-1范围内并进行normalizepad_params获取图像padding参数pad_image根据pad参数padding图像__getitem__通过索引获取数据__len__获取数据长度 数据加载类的主要的思路是加载图像和标签对于图像进行规范化除以255以及normalize如果图像过大进行裁剪如果图像过小进行padding对于标签我们调用之前的函数从RGB标签转换成类别标签 class SemanticDataset(torch.utils.data.Dataset):def __init__(self, is_train, crop_size, data_dir):self.transform torchvision.transforms.Normalize(mean[0.4813, 0.4844, 0.4919], std[0.2467, 0.2478, 0.2542])self.crop_size crop_sizeself.data_dir data_dirself.is_train is_trainself.colormap2label voc_colormap2label()txt_fname os.path.join(data_dir, train.txt if self.is_train else test.txt)with open(txt_fname, r) as f:self.images f.read().split()def normalize_image(self, img):return self.transform(img.float() / 255)def pad_params(self, crop_h, crop_w, img_h, img_w):hight max(crop_h, img_h)width max(crop_w, img_w)y_s (hight - img_h) // 2x_s (width - img_w) // 2return hight, width, y_s, x_sdef pad_image(self, hight, width, y_s, x_s, feature):zeros torch.zeros((feature.shape[0], hight, width))zeros[:, y_s:y_s feature.shape[1], x_s:x_s feature.shape[2]] featurereturn zerosdef __getitem__(self, idx):mode torchvision.io.image.ImageReadMode.RGBfeature torchvision.io.read_image(os.path.join(self.data_dir, images, {:03d}.jpg.format(int(self.images[idx]))))label torchvision.io.read_image(os.path.join(self.data_dir, labels, {:03d}.png.format(int(self.images[idx]))), mode)c_h, c_w, f_h, f_w self.crop_size[0], self.crop_size[1], feature.shape[1], feature.shape[2]if f_h c_h or f_w c_w:higth, width, y_s, x_s self.pad_params(c_h, c_w, f_h, f_w)feature self.pad_image(higth, width, y_s, x_s, feature)label self.pad_image(higth, width, y_s, x_s, label)feature self.normalize_image(feature) feature, label voc_rand_crop(feature, label,*self.crop_size)label voc_label_indices(label, self.colormap2label)return (feature, label)def __len__(self):return len(self.images)使用torch.utils.data.DataLoader批量加载数据 def load_data_voc(batch_size, crop_size, data_dir ./dataset):train_iter torch.utils.data.DataLoader(SemanticDataset(True, crop_size, data_dir), batch_size, shuffleTrue, drop_lastTrue)test_iter torch.utils.data.DataLoader(SemanticDataset(False, crop_size, data_dir), batch_size, shuffleFalse, drop_lastTrue)return train_iter, test_iter
http://www.w-s-a.com/news/473938/

相关文章:

  • 大连金州新区规划建设局网站金坛市建设局网站
  • 有哪些做排球比赛视频网站wordpress 教师工作坊
  • 深圳好点的网站建设公司互联网企业信息服务平台
  • 下载空间大的网站建设哈尔滨网站制作软件
  • 南城网站仿做无锡网站制作哪家价格便宜
  • c做的网站营销策划课程
  • 免费网站404免费进入重庆的公需科目在哪个网站做
  • 网站空间租用费用网站建设公司怎么宣传
  • 镇江网站建设优化案例分析dw2018网页制作步骤图文
  • 网站开发一个多少钱为什么前端都不用dw
  • 网站降权的原因北京中小企业网站建设公司
  • 个人域名能做网站吗wordpress
  • 手机网站设计只找亿企邦工业设计公司简介
  • 腾讯云主机做网站免费网站怎么做啊
  • 网站建设推广销售话术广州网页定制多少钱
  • 备案号是哪个网站项目管理pmp
  • 做网站需要哪些硬件软件网站视频链接怎么做的
  • 电子商务网站建设试题二wordpress主页显示浏览数
  • 网站快照没了广州企业电话大全
  • 网站项目开发收费标准网站开发app开发主营业务
  • 怎么到国外网站去接模具订单做互联网建设企业网站
  • 深圳品牌网站建设公司排名洪雅网站建设
  • nodejs 做网站wordpress主题绕过激活码
  • 平湖模板网站建设公司网页美工培训
  • 顺德网站建设市场建设工程交易中心网站
  • 深圳企业网站怎么做浪琴手表网站建设图
  • 2018网站外链怎么做济南 网站设计公司
  • 承德百度网站建设郑州网站seo优化公司
  • 四川建站模板网站公司分类信息网站制作
  • 网站开发前后端有wordpress模板安装教程视频教程