资源简介
图像语义分割 FCN方法,使用tensorflow库,解压使用即可
代码片段和文件信息
# coding=utf-8
“““
Code ideas from https://github.com/Newmu/dcgan and tensorflow mnist dataset reader
“““
import numpy as np
import scipy.misc as misc
class BatchDatset:
files = []
images = []
annotations = []
image_options = {}
batch_offset = 0
epochs_completed = 0
def __init__(self records_list image_options={}):
“““
Intialize a generic file reader with batching for list of files
:param records_list: list of file records to read -
sample record: {‘image‘: f ‘annotation‘: annotation_file ‘filename‘: filename}
:param image_options: A dictionary of options for modifying the output image
Available options:
resize = True/ False
resize_size = #size of output image - does bilinear resize
color=True/False
“““
print(“Initializing Batch Dataset Reader...“)
print(image_options)
self.files = records_list # 文件列表
self.image_options = image_options # 图片操作方式 resize 224
self._read_images()
def _read_images(self):
self.__channels = True
# 扫描files字典中所有image 图片全路径
# 根据文件全路径读取图像,并将其扩充为RGB格式
self.images = np.array([self._transform(filename[‘image‘]) for filename in self.files])
self.__channels = False
# 扫描files字典中所有annotation 图片全路径
# 根据文件全路径读取图像,并将其扩充为三通道格式
self.annotations = np.array(
[np.expand_dims(self._transform(filename[‘annotation‘]) axis=3) for filename in self.files])
print (self.images.shape)
print (self.annotations.shape)
def _transform(self filename):
# 读取文件图片
image = misc.imread(filename)
if self.__channels and len(image.shape) < 3: # make sure images are of shape(hw3)
# 将图片三个通道设置为一样的图片
image = np.array([image for i in range(3)])
if self.image_options.get(“resize“ False) and self.image_options[“resize“]:
resize_size = int(self.image_options[“resize_size“])
# 使用最近邻插值法resize图片
resize_image = misc.imresize(image
[resize_size resize_size] interp=‘nearest‘)
else:
resize_image = image
return np.array(resize_image) # 返回已经resize的图片
def get_records(self):
“““
返回图片和标签全路径
:return:
“““
return self.images self.annotations
def reset_batch_offset(self offset=0):
“““
剩下的batch
:param offset:
:return:
“““
self.batch_offset = offset
def next_batch(self batch_size):
# 当前第几个batch
start = self.batch_offset
# 读取下一个batch 所有offset偏移量+batch_size
self.batch_offset += batch_size
# iamges存储所有图片信息 images.shape(len h w)
if self.batch_offset > self.images.shape[0]: # 如果下一个batch的偏移量超过了图片总数 说明完成了一个epoch
# Finished epoch
self.epochs_completed += 1 # epochs完成总数+1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-24 12:22 FCN-TensorFlow-master\
文件 4475 2018-04-24 12:22 FCN-TensorFlow-master\BatchDatsetReader.py
文件 4146 2018-04-24 12:22 FCN-TensorFlow-master\BatchDatsetReader.pyc
文件 14126 2018-04-24 12:22 FCN-TensorFlow-master\FCN.py
文件 1074 2018-04-24 12:22 FCN-TensorFlow-master\LICENSE
文件 4887 2018-04-24 12:22 FCN-TensorFlow-master\README.md
文件 9700 2018-04-24 12:22 FCN-TensorFlow-master\TensorflowUtils.py
文件 12341 2018-04-24 12:22 FCN-TensorFlow-master\TensorflowUtils.pyc
目录 0 2018-04-24 12:22 FCN-TensorFlow-master\images\
文件 113332 2018-04-24 12:22 FCN-TensorFlow-master\images\Image_Cmaped.ipynb
文件 20876 2018-04-24 12:22 FCN-TensorFlow-master\images\conv_1_1_gradient.png
文件 16359 2018-04-24 12:22 FCN-TensorFlow-master\images\conv_4_1_gradient.png
文件 16447 2018-04-24 12:22 FCN-TensorFlow-master\images\conv_4_2_gradient.png
文件 16355 2018-04-24 12:22 FCN-TensorFlow-master\images\conv_4_3_gradient.png
文件 1928 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_0.png
文件 2214 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_1.png
文件 3875 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_2.png
文件 3628 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_3.png
文件 3490 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_4.png
文件 1439 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_5.png
文件 3062 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_6.png
文件 4309 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_7.png
文件 3027 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_8.png
文件 9716 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c0.png
文件 10398 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c1.png
文件 15633 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c2.png
文件 13852 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c3.png
文件 14244 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c4.png
文件 8791 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c5.png
文件 12713 2018-04-24 12:22 FCN-TensorFlow-master\images\gt_c6.png
文件 81929 2018-04-24 12:22 FCN-TensorFlow-master\images\inp_0.png
............此处省略78个文件信息
评论
共有 条评论