JIT*_*IRK 4 machine-learning deep-learning conv-neural-network keras tensorflow
我正在使用 Tensorflow-gpu 后端在 Keras 中训练模型。任务是检测卫星图像中的建筑物。损失正在下降(这是好事),但方向是负的,并且准确性正在下降。但好的方面是,模型的预测正在改进。我担心的是为什么损失是负数。此外,为什么模型在改进而准确性却在下降?
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import MaxPool2D as MaxPooling2D
from tensorflow.keras.layers import UpSampling2D
from tensorflow.keras.layers import concatenate
from tensorflow.keras.layers import Input
from tensorflow.keras import Model
from tensorflow.keras.optimizers import RMSprop
# LAYERS
inputs = Input(shape=(300, 300, 3))
# 300
down0 = Conv2D(32, (3, 3), padding='same')(inputs)
down0 = BatchNormalization()(down0)
down0 = Activation('relu')(down0)
down0 = Conv2D(32, (3, 3), padding='same')(down0)
down0 = BatchNormalization()(down0)
down0 = Activation('relu')(down0)
down0_pool = MaxPooling2D((2, 2), strides=(2, 2))(down0)
# 150
down1 = Conv2D(64, (3, 3), padding='same')(down0_pool)
down1 = BatchNormalization()(down1)
down1 = Activation('relu')(down1)
down1 = Conv2D(64, (3, 3), padding='same')(down1)
down1 = BatchNormalization()(down1)
down1 = Activation('relu')(down1)
down1_pool = MaxPooling2D((2, 2), strides=(2, 2))(down1)
# 75
center = Conv2D(1024, (3, 3), padding='same')(down1_pool)
center = BatchNormalization()(center)
center = Activation('relu')(center)
center = Conv2D(1024, (3, 3), padding='same')(center)
center = BatchNormalization()(center)
center = Activation('relu')(center)
# center
up1 = UpSampling2D((2, 2))(center)
up1 = concatenate([down1, up1], axis=3)
up1 = Conv2D(64, (3, 3), padding='same')(up1)
up1 = BatchNormalization()(up1)
up1 = Activation('relu')(up1)
up1 = Conv2D(64, (3, 3), padding='same')(up1)
up1 = BatchNormalization()(up1)
up1 = Activation('relu')(up1)
up1 = Conv2D(64, (3, 3), padding='same')(up1)
up1 = BatchNormalization()(up1)
up1 = Activation('relu')(up1)
# 150
up0 = UpSampling2D((2, 2))(up1)
up0 = concatenate([down0, up0], axis=3)
up0 = Conv2D(32, (3, 3), padding='same')(up0)
up0 = BatchNormalization()(up0)
up0 = Activation('relu')(up0)
up0 = Conv2D(32, (3, 3), padding='same')(up0)
up0 = BatchNormalization()(up0)
up0 = Activation('relu')(up0)
up0 = Conv2D(32, (3, 3), padding='same')(up0)
up0 = BatchNormalization()(up0)
up0 = Activation('relu')(up0)
# 300x300x3
classify = Conv2D(1, (1, 1), activation='sigmoid')(up0)
# 300x300x1
model = Model(inputs=inputs, outputs=classify)
model.compile(optimizer=RMSprop(lr=0.0001),
loss='binary_crossentropy',
metrics=[dice_coeff, 'accuracy'])
history = model.fit(sample_input, sample_target, batch_size=4, epochs=5)
OUTPUT:
Epoch 6/10
500/500 [==============================] - 76s 153ms/step - loss: -293.6920 -
dice_coeff: 1.8607 - acc: 0.2653
Epoch 7/10
500/500 [==============================] - 75s 150ms/step - loss: -309.2504 -
dice_coeff: 1.8730 - acc: 0.2618
Epoch 8/10
500/500 [==============================] - 75s 150ms/step - loss: -324.4123 -
dice_coeff: 1.8810 - acc: 0.2659
Epoch 9/10
136/500 [=======>......................] - ETA: 55s - loss: -329.0757 - dice_coeff: 1.8940 - acc: 0.2757
Run Code Online (Sandbox Code Playgroud)
哪里有问题?(留下 dice_coeff 这是自定义损失)
您的输出未针对二元分类进行标准化。(数据也可能没有标准化)。
如果加载图像,它可能是 0 到 255,甚至是 0 到 65355。
您应该标准化y_train(除以y_train.max())并'sigmoid'在模型末尾使用激活函数。
| 归档时间: |
|
| 查看次数: |
5413 次 |
| 最近记录: |