这篇论文在实现上有三个问题:
1.下采样和上采样上使用了没有边界补充的卷积,这导致了需要进行分割卷积层才能够在前层和后面的层进行拼接操作时需要裁剪前面的层。
2.当输入图像不能够被16整除时会出现左边是单数而上采样后是双数的图像大小。
3.由于每次卷积导致了大小的变化,输入的图片大小和输出的图片大小不一致。
所以实现时进行如下操作:
1.使用边界补充的卷积
2.对图像进行预处理,将图像裁剪为16整除的大小
import keras
from keras.layers.normalization import BatchNormalization
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import *
from keras.optimizers import Adam
from keras.utils import np_utils
from keras.datasets import mnist
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
import numpy as np
import os
import glob
from keras import backend as K
import os
#os.environ["CUDA_VISIBLE_DEVICES"] = "0"
import numpy as np
from keras.models import *
from keras.layers import Input, merge, Conv2D, MaxPooling2D, UpSampling2D, Dropout, Cropping2D
from keras.optimizers import *
from keras.callbacks import ModelCheckpoint, LearningRateScheduler
from keras import backend as keras
from data import *
npy_path="/media/chenli/F1/medical/SegCaps/data/train"
img_type="tif"
data_path="/media/chenli/F1/medical/SegCaps/data/train/img/"
label_path="/media/chenli/F1/medical/SegCaps/data/train/masks/"
out_rows=512
out_cols=512
def create_train_data():
i = 0
print('-' * 30)
print('Creating training images...')
print('-' * 30)
imgdatas = np.ndarray(
(133, 1,out_rows, out_cols), dtype=np.uint8)
imglabels = np.ndarray(
(133, 1,out_rows, out_cols), dtype=np.uint8)
for k in range(1,133):
label = load_img(label_path + "%d.png" % (k), grayscale=True)
label = img_to_array(label)
imglabels[i] = label[:,:,:]
img = load_img(