我是人工智能和Python的新手,所以我一直在尝试使用U-net创建一个可以识别和分割裂缝的人工智能。我的结果如下:
Epoch 5/25
20/20 [==============================] - 42s 2s/step - loss: -12.7775 - accuracy: 0.0591 - dice_coef: 1.3771 - iou: 2.9680 - val_loss: 0.9940 - val_accuracy: 0.4198 - val_dice_coef: 0.9033 - val_iou: 0.9226
奇怪的是,随着每个历元的出现,损失和精度都在不断降低,而骰子系数和IOU却在不断增加。
Epochs results
我将分享我的尝试:
培训图片:
Mask for example
Main Image
下面的代码显示了我如何阅读和处理图像=
#Xtrain=主图像的大小调整为128x128
#Ytrain=遮罩图像变为灰色,调整大小为128x128,并获得新的通道1
def readimg(name_image, list_images):
path_image = os.path.join('crack_dataset/img', name_image)
if os.path.exists(path_image):
image = cv2.imread(path_image)
image = cv2.resize(image,(128,128))
Xtrain.append(image)
def leimg_mask(name_image, list_images):
path_image = os.path.join('crack_dataset/labelcol', nome_imagem)
if os.path.exists(path_image):
image = cv2.imread(path_image, cv2.IMREAD_GRAYSCALE)
image = cv2.resize(image,(128,128))
mask_array = image[:, :, np.newaxis]
Ytrain.append(mask_array)
然后,Xtrain和Ytrain转向NumPyndarray。Xtrain被规范化了
Xtrain = np.array(Xtrain)
Ytrain = np.array(Ytrain)
Xtrain = Xtrain / 255.0
创建图像数据生成器。用于训练的Datagen和用于测试的Datagen_test
datagen = ImageDataGenerator(
rotation_range=15,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.2,
zoom_range=0.2,
brightness_range=[0.7, 1.3],
fill_mode="nearest"
)
datagen_test = ImageDataGenerator()
X_train, X_test, y_train, y_test = train_test_split(Xtrain, Ytrain, test_size=0.2, random_state=42)
下面的型号
Model part 1
Model part 2
train_generator = datagen.flow(
X_train, y_train, batch_size=16, shuffle=True
)
val_generator = datagen_test.flow(
X_test, y_test, batch_size=16, shuffle=False
)
many_steps = len(train_generator)
history = model.fit(train_generator, steps_per_epoch=many_steps, epochs=25, validation_data=val_generator)
请帮助:(