资源简介
发表SegNet网络的论文为:Badrinarayanan V, Kendall A, Cipolla R.SegNet: A Deep Convolutional Encoder-Decoder Architecture for SceneSegmentation[J]. IEEE Transactions on Pattern Analysis & MachineIntelligence, 2017, PP(99):1-1。
来源于美国加州大学伯克利分校的这项工作为语义分割引入了端到端的全卷积网络,在构建的网络结构中,重新利用ImageNet的预训练网络用于语义分割,并使用了反卷积层进行上采样并且引入跳跃连接来改善上采样粗糙的像素定位。
代码片段和文件信息
from __future__ import print_function
from keras.preprocessing.image import ImageDataGenerator
import numpy as np
import os
import glob
import skimage.io as io
import skimage.transform as trans
Sky = [128128128]
Building = [12800]
Pole = [192192128]
Road = [12864128]
Pavement = [6040222]
Tree = [1281280]
SignSymbol = [192128128]
Fence = [6464128]
Car = [640128]
Pedestrian = [64640]
Bicyclist = [0128192]
Unlabelled = [000]
COLOR_DICT = np.array([Sky Building Pole Road Pavement
Tree SignSymbol Fence Car Pedestrian Bicyclist Unlabelled])
def adjustData(imgmaskflag_multi_classnum_class):
if(flag_multi_class):
img = img / 255
mask = mask[:::0] if(len(mask.shape) == 4) else mask[::0]
new_mask = np.zeros(mask.shape + (num_class))
for i in range(num_class):
#for one pixel in the image find the class in mask and convert it into one-hot vector
#index = np.where(mask == i)
#index_mask = (index[0]index[1]index[2]np.zeros(len(index[0])dtype = np.int64) + i) if (len(mask.shape) == 4) else (index[0]index[1]np.zeros(len(index[0])dtype = np.int64) + i)
#new_mask[index_mask] = 1
new_mask[mask == ii] = 1
new_mask = np.reshape(new_mask(new_mask.shape[0]new_mask.shape[1]*new_mask.shape[2]new_mask.shape[3])) if flag_multi_class else np.reshape(new_mask(new_mask.shape[0]*new_mask.shape[1]new_mask.shape[2]))
mask = new_mask
elif(np.max(img) > 1):
img = img / 255
mask = mask /255
mask[mask > 0.5] = 1
mask[mask <= 0.5] = 0
return (imgmask)
def trainGenerator(batch_sizetrain_pathimage_foldermask_folderaug_dictimage_color_mode = “grayscale“
mask_color_mode = “grayscale“image_save_prefix = “image“mask_save_prefix = “mask“
flag_multi_class = Falsenum_class = 2save_to_dir = Nonetarget_size = (256256)seed = 1):
‘‘‘
can generate image and mask at the same time
use the same seed for image_datagen and mask_datagen to ensure the transformation for image and mask is the same
if you want to visualize the results of generator set save_to_dir = “your path“
‘‘‘
image_datagen = ImageDataGenerator(**aug_dict)
mask_datagen = ImageDataGenerator(**aug_dict)
image_generator = image_datagen.flow_from_directory(
train_path
classes = [image_folder]
class_mode = None
color_mode = image_color_mode
target_size = target_size
batch_size = batch_size
save_to_dir = save_to_dir
save_prefix = image_save_prefix
seed = seed)
mask_generator = mask_datagen.flow_from_directory(
train_path
classes = [mask_folder]
class_mode = None
color_mode = mask_color_mode
target_size = target_size
batch_size = batch_size
save_to_dir = save_to_dir
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-22 02:37 unet-master\
文件 2552 2018-06-22 02:37 unet-master\README.md
文件 5076 2018-06-22 02:37 unet-master\data.py
目录 0 2018-06-22 02:37 unet-master\data\
目录 0 2018-06-22 02:37 unet-master\data\membrane\
文件 7871660 2018-06-22 02:37 unet-master\data\membrane\test-volume.tif
目录 0 2018-06-22 02:37 unet-master\data\membrane\test\
文件 214932 2018-06-22 02:37 unet-master\data\membrane\test\0.png
文件 48695 2018-06-22 02:37 unet-master\data\membrane\test\0_predict.png
文件 213325 2018-06-22 02:37 unet-master\data\membrane\test\1.png
文件 216258 2018-06-22 02:37 unet-master\data\membrane\test\10.png
文件 58705 2018-06-22 02:37 unet-master\data\membrane\test\10_predict.png
文件 212360 2018-06-22 02:37 unet-master\data\membrane\test\11.png
文件 59910 2018-06-22 02:37 unet-master\data\membrane\test\11_predict.png
文件 218424 2018-06-22 02:37 unet-master\data\membrane\test\12.png
文件 58785 2018-06-22 02:37 unet-master\data\membrane\test\12_predict.png
文件 216843 2018-06-22 02:37 unet-master\data\membrane\test\13.png
文件 56863 2018-06-22 02:37 unet-master\data\membrane\test\13_predict.png
文件 215779 2018-06-22 02:37 unet-master\data\membrane\test\14.png
文件 55807 2018-06-22 02:37 unet-master\data\membrane\test\14_predict.png
文件 213389 2018-06-22 02:37 unet-master\data\membrane\test\15.png
文件 55776 2018-06-22 02:37 unet-master\data\membrane\test\15_predict.png
文件 210724 2018-06-22 02:37 unet-master\data\membrane\test\16.png
文件 57146 2018-06-22 02:37 unet-master\data\membrane\test\16_predict.png
文件 210481 2018-06-22 02:37 unet-master\data\membrane\test\17.png
文件 58158 2018-06-22 02:37 unet-master\data\membrane\test\17_predict.png
文件 210865 2018-06-22 02:37 unet-master\data\membrane\test\18.png
文件 62315 2018-06-22 02:37 unet-master\data\membrane\test\18_predict.png
文件 209276 2018-06-22 02:37 unet-master\data\membrane\test\19.png
文件 54740 2018-06-22 02:37 unet-master\data\membrane\test\19_predict.png
文件 54547 2018-06-22 02:37 unet-master\data\membrane\test\1_predict.png
............此处省略230个文件信息
评论
共有 条评论