资源简介

完整工程案例:深度学习Tensorflow 图像语义分割(Image Segmentation)DeepLab基于ResNet101模型(tensorflow1.1以上、python3.5及以上)

资源截图

代码片段和文件信息

from __future__ import print_function
import argparse
import tensorflow as tf
import numpy as np
from deeplab_resnet import DeepLabResNetModel ImageReader

IMG_MEAN = np.array((104.00698793 116.66876762 122.67891434) dtype=np.float32)

DATA_DIRECTORY = ‘./dataset‘
DATA_LIST_PATH = ‘./dataset/val.txt‘
IGNORE_LABEL = 255
NUM_CLASSES = 21
NUM_STEPS = 1449 # Number of images in the validation set.
RESTORE_FROM = ‘./ini_model/deeplab_resnet.ckpt‘


def get_arguments():
    “““解析控制台参数.
    
    Returns:参数列表
    “““
    parser = argparse.ArgumentParser(description=“DeepLab Network“)
    parser.add_argument(“--data-dir“ type=str default=DATA_DIRECTORY
                        help=“Path to the directory containing the PASCAL VOC dataset.“)
    parser.add_argument(“--data-list“ type=str default=DATA_LIST_PATH
                        help=“Path to the file listing the images in the dataset.“)
    parser.add_argument(“--ignore-label“ type=int default=IGNORE_LABEL
                        help=“The index of the label to ignore during the training.“)
    parser.add_argument(“--num-classes“ type=int default=NUM_CLASSES
                        help=“Number of classes to predict (including background).“)
    parser.add_argument(“--num-steps“ type=int default=NUM_STEPS
                        help=“Number of images in the validation set.“)
    parser.add_argument(“--restore-from“ type=str default=RESTORE_FROM
                        help=“Where restore model parameters from.“)
    return parser.parse_args()


def load(saver sess ckpt_path):
    ‘‘‘加载已训练的权重参数.
    
    Args:
      saver: TensorFlow Saver 存储器对象.
      sess: TensorFlow session.
      ckpt_path: checkpoint权重参数文件路径.
    ‘‘‘ 
    saver.restore(sess ckpt_path)
    print(“Restored model parameters from {}“.format(ckpt_path))


def main():
    “““主函数:模型构建和evaluate.“““
    args = get_arguments()
    
    # 构建队列协调器queue coordinator
    coord = tf.train.Coordinator()
    
    # 加载读取器reader.
    with tf.name_scope(“create_inputs“):
        reader = ImageReader(
            args.data_dir
            args.data_list
            None # 无输入尺寸设置.
            False # 无随机尺寸变换.
            False # 无镜像变换.
            args.ignore_label
            IMG_MEAN
            coord)
        image label = reader.image reader.label
    # 添加Batch维度.
    image_batch label_batch = tf.expand_dims(image dim=0) tf.expand_dims(label dim=0) 

    # 构建DeepLab-ResNet-101网络
    net = DeepLabResNetModel({‘data‘: image_batch} is_training=False num_classes=args.num_classes)

    # 设定要预加载的网络权重参数
    restore_var = tf.global_variables()
    
    # 执行预测.
    raw_output = net.layers[‘fc1_voc12‘]
    raw_output = tf.image.resize_bilinear(raw_output tf.shape(image_batch)[1:3 ])
    raw_output = tf.argmax(raw_output dimension=3)
    pred = tf.expand_dims(raw_output dim=3) # Create 4-d tensor.
    
    # 计算mIoU
    pred = tf.reshape(pred [-1 ])
    gt = tf.reshape(label_batch [-1 ])
    weights = tf.cast(tf

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        455  2018-02-20 15:44  DeepLab-ResNet-101\.idea\C6_DeepLab_TF.iml

     文件        562  2018-02-20 16:30  DeepLab-ResNet-101\.idea\inspectionProfiles\Project_Default.xml

     文件        301  2018-02-20 16:30  DeepLab-ResNet-101\.idea\misc.xml

     文件        278  2018-02-20 15:44  DeepLab-ResNet-101\.idea\modules.xml

     文件      19898  2018-02-20 16:31  DeepLab-ResNet-101\.idea\workspace.xml

     文件         56  2017-06-07 00:01  DeepLab-ResNet-101\.spyproject\codestyle.ini

     文件         58  2017-06-07 00:01  DeepLab-ResNet-101\.spyproject\encoding.ini

     文件         85  2017-06-07 00:01  DeepLab-ResNet-101\.spyproject\vcs.ini

     文件        425  2017-06-07 00:01  DeepLab-ResNet-101\.spyproject\workspace.ini

     文件        414  2018-02-20 23:59  DeepLab-ResNet-101\dataset\dataset下载说明.txt

     文件     698411  2017-06-07 00:01  DeepLab-ResNet-101\dataset\train.txt

     文件      95633  2017-06-07 00:01  DeepLab-ResNet-101\dataset\val.txt

     文件       7490  2018-02-20 15:45  DeepLab-ResNet-101\deeplab_resnet\image_reader.py

     文件      30632  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\model.py

     文件      12322  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\network.py

     文件       3320  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\utils.py

     文件        169  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__init__.py

     文件       6632  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__pycache__\image_reader.cpython-35.pyc

     文件       6169  2018-02-20 15:50  DeepLab-ResNet-101\deeplab_resnet\__pycache__\image_reader.cpython-36.pyc

     文件      14724  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__pycache__\model.cpython-35.pyc

     文件      11219  2018-02-20 15:50  DeepLab-ResNet-101\deeplab_resnet\__pycache__\model.cpython-36.pyc

     文件      10135  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__pycache__\network.cpython-35.pyc

     文件       9357  2018-02-20 15:50  DeepLab-ResNet-101\deeplab_resnet\__pycache__\network.cpython-36.pyc

     文件       3396  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__pycache__\utils.cpython-35.pyc

     文件       3235  2018-02-20 15:50  DeepLab-ResNet-101\deeplab_resnet\__pycache__\utils.cpython-36.pyc

     文件        395  2017-06-07 00:01  DeepLab-ResNet-101\deeplab_resnet\__pycache__\__init__.cpython-35.pyc

     文件        405  2018-02-20 15:50  DeepLab-ResNet-101\deeplab_resnet\__pycache__\__init__.cpython-36.pyc

     文件       4382  2018-02-20 16:08  DeepLab-ResNet-101\evaluate.py

     文件       3214  2018-02-20 16:03  DeepLab-ResNet-101\inference.py

     文件         93  2018-02-21 00:10  DeepLab-ResNet-101\ini_model\pretrained模型下载.txt

............此处省略15个文件信息

评论

共有 条评论