我有一张图像列表作为训练数据,其中一张图像如下所示:
对于每个训练图像,我手动标记红色纤维并生成 看起来像这样的灰度图像:
现在我希望算法学习红色纤维标记过程 并为每张图像返回一个灰度图像:
def readImagesIntoNumpy(directory):
files = os.listdir(directory)
images = map(lambda file: io.imread(directory + file), files)
return np.array(images)
// xTrain.shape = (num_of_images, 256, 256, 4)
xTrain = readImagesIntoNumpy("./original/")
// yTrain.shape = (num_of_images, 256, 256, 1)
yTrain = np.expand_dims(readImagesIntoNumpy("./gray/"), axis = 3)
// constructing the neural network
s = Input((256, 256, 4))
o = Conv2D(32, (1, 1), activation = 'sigmoid')(s)
for i in range(20):
o = Conv2D(32, (1, 1), activation='elu')(o)
o = Conv2D(1, (1, 1), activation = 'sigmoid')(o)
model = Model(inputs = [s], outputs = [o])
model.compile(optimizer='adam', loss='binary_crossentropy')
// model.summary() has 21313 trainable parameters
// training the neural network:
model.fit(xTrain, yTrain, epochs = 50, callbacks=[checkpoint])
但是,如果我现在让模型预测训练数据上的灰度图像
yPredicted = model.predict(xTrain)
它仅返回全黑图像。
为什么?