deeplabv3+二:详细代码解读 data generator 数据生成器

2024-09-01 23:48

本文主要是介绍deeplabv3+二:详细代码解读 data generator 数据生成器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

3+支持三种数据库,voc2012,cityscapes,ade20k,

代码文件夹

-deeplab

    -datasets

         -data_generator.py

在开始之前,始终记住,网络模型的输入是非常简单的image,规格化到[-1,1]或[0,1],或者数据扩增(水平翻转,随机裁剪,明暗变化,模糊),以及一个实施了相同数据扩增的label(毕竟需要pixel对上),test的话只需要一个image。是非常简单的数据格式,也许程序员会为了存储的压缩量以及读取处理的速度(指的就是使用tf.example 与 tf.record)写复杂的代码,但是最终的结果始终都是很简单的。

觉得自己一定要先搞清楚tf.example 与tf.record:https://zhuanlan.zhihu.com/p/33223782

 

目录

数据库分析

代码重点类Dataset

1.方法_parse_function()

2. 方法_preprocess_image()

2.1 input_preprocess的preprocess_image_and_label方法介绍

3.方法 _get_all_files(self):

4.方法 get_one_shot_iterator(self)

Class TFRecordDataset

代码使用是在train.py里面:


代码:先放代码,你可以尝试自己看,看得懂就不用往下翻浪费时间了。

# Copyright 2018 The TensorFlow Authors All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Wrapper for providing semantic segmentaion data.The SegmentationDataset class provides both images and annotations (semantic
segmentation and/or instance segmentation) for TensorFlow. Currently, we
support the following datasets:1. PASCAL VOC 2012 (http://host.robots.ox.ac.uk/pascal/VOC/voc2012/).PASCAL VOC 2012 semantic segmentation dataset annotates 20 foreground objects
(e.g., bike, person, and so on) and leaves all the other semantic classes as
one background class. The dataset contains 1464, 1449, and 1456 annotated
images for the training, validation and test respectively.2. Cityscapes dataset (https://www.cityscapes-dataset.com)The Cityscapes dataset contains 19 semantic labels (such as road, person, car,
and so on) for urban street scenes.3. ADE20K dataset (http://groups.csail.mit.edu/vision/datasets/ADE20K)The ADE20K dataset contains 150 semantic labels both urban street scenes and
indoor scenes.References:M. Everingham, S. M. A. Eslami, L. V. Gool, C. K. I. Williams, J. Winn,and A. Zisserman, The pascal visual object classes challenge a retrospective.IJCV, 2014.M. Cordts, M. Omran, S. Ramos, T. Rehfeld, M. Enzweiler, R. Benenson,U. Franke, S. Roth, and B. Schiele, "The cityscapes dataset for semantic urbanscene understanding," In Proc. of CVPR, 2016.B. Zhou, H. Zhao, X. Puig, S. Fidler, A. Barriuso, A. Torralba, "Scene Parsingthrough ADE20K dataset", In Proc. of CVPR, 2017.
"""import collections
import os
import tensorflow as tf
from deeplab import common
from deeplab import input_preprocess# Named tuple to describe the dataset properties.
DatasetDescriptor = collections.namedtuple('DatasetDescriptor',['splits_to_sizes',  # Splits of the dataset into training, val and test.'num_classes',  # Number of semantic classes, including the# background class (if exists). For example, there# are 20 foreground classes + 1 background class in# the PASCAL VOC 2012 dataset. Thus, we set# num_classes=21.'ignore_label',  # Ignore label value.])_CITYSCAPES_INFORMATION = DatasetDescriptor(splits_to_sizes={'train': 2975,'val': 500,},num_classes=19,ignore_label=255,
)_PASCAL_VOC_SEG_INFORMATION = DatasetDescriptor(splits_to_sizes={'train': 1464,'train_aug': 10582,'trainval': 2913,'val': 1449,},num_classes=21,ignore_label=255,
)_ADE20K_INFORMATION = DatasetDescriptor(splits_to_sizes={'train': 20210,  # num of samples in images/training'val': 2000,  # num of samples in images/validation},num_classes=151,ignore_label=0,
)_DATASETS_INFORMATION = {'cityscapes': _CITYSCAPES_INFORMATION,'pascal_voc_seg': _PASCAL_VOC_SEG_INFORMATION,'ade20k': _ADE20K_INFORMATION,
}# Default file pattern of TFRecord of TensorFlow Example.
_FILE_PATTERN = '%s-*'def get_cityscapes_dataset_name():return 'cityscapes'class Dataset(object):"""Represents input dataset for deeplab model."""def __init__(self,dataset_name,split_name,dataset_dir,batch_size,crop_size,min_resize_value=None,max_resize_value=None,resize_factor=None,min_scale_factor=1.,max_scale_factor=1.,scale_factor_step_size=0,model_variant=None,num_readers=1,is_training=False,should_shuffle=False,should_repeat=False):"""Initializes the dataset.Args:dataset_name: Dataset name.split_name: A train/val Split name.dataset_dir: The directory of the dataset sources.batch_size: Batch size.crop_size: The size used to crop the image and label.min_resize_value: Desired size of the smaller image side.max_resize_value: Maximum allowed size of the larger image side.resize_factor: Resized dimensions are multiple of factor plus one.min_scale_factor: Minimum scale factor value.max_scale_factor: Maximum scale factor value.scale_factor_step_size: The step size from min scale factor to max scalefactor. The input is randomly scaled based on the v

这篇关于deeplabv3+二:详细代码解读 data generator 数据生成器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1128397

相关文章

解读GC日志中的各项指标用法

《解读GC日志中的各项指标用法》:本文主要介绍GC日志中的各项指标用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、基础 GC 日志格式(以 G1 为例)1. Minor GC 日志2. Full GC 日志二、关键指标解析1. GC 类型与触发原因2. 堆

Java设计模式---迭代器模式(Iterator)解读

《Java设计模式---迭代器模式(Iterator)解读》:本文主要介绍Java设计模式---迭代器模式(Iterator),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录1、迭代器(Iterator)1.1、结构1.2、常用方法1.3、本质1、解耦集合与遍历逻辑2、统一

SpringBoot整合liteflow的详细过程

《SpringBoot整合liteflow的详细过程》:本文主要介绍SpringBoot整合liteflow的详细过程,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋...  liteflow 是什么? 能做什么?总之一句话:能帮你规范写代码逻辑 ,编排并解耦业务逻辑,代码

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

MyBatisPlus如何优化千万级数据的CRUD

《MyBatisPlus如何优化千万级数据的CRUD》最近负责的一个项目,数据库表量级破千万,每次执行CRUD都像走钢丝,稍有不慎就引起数据库报警,本文就结合这个项目的实战经验,聊聊MyBatisPl... 目录背景一、MyBATis Plus 简介二、千万级数据的挑战三、优化 CRUD 的关键策略1. 查

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

mysql中的数据目录用法及说明

《mysql中的数据目录用法及说明》:本文主要介绍mysql中的数据目录用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、版本3、数据目录4、总结1、背景安装mysql之后,在安装目录下会有一个data目录,我们创建的数据库、创建的表、插入的

MySQL之InnoDB存储页的独立表空间解读

《MySQL之InnoDB存储页的独立表空间解读》:本文主要介绍MySQL之InnoDB存储页的独立表空间,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、独立表空间【1】表空间大小【2】区【3】组【4】段【5】区的类型【6】XDES Entry区结构【

浏览器插件cursor实现自动注册、续杯的详细过程

《浏览器插件cursor实现自动注册、续杯的详细过程》Cursor简易注册助手脚本通过自动化邮箱填写和验证码获取流程,大大简化了Cursor的注册过程,它不仅提高了注册效率,还通过友好的用户界面和详细... 目录前言功能概述使用方法安装脚本使用流程邮箱输入页面验证码页面实战演示技术实现核心功能实现1. 随机