我试图训练一个CNN,它将输出(x,y)坐标的面部特征,如左眼开始,左眼结束,左眼中心,右眼开始,右眼中心和右眼结束。根据coursera课程深度学习专业化,我需要为每个点获取0和1值(真或假),然后为每个点输出x和y坐标。如果值为0(False),我需要在训练期间忽略x和y的输出。在
我试图寻找一种方法来做这件事,但没找到。最后,我考虑将所有缺失的(我们没有特定特性的数据)x,y坐标设置为0,然后训练下面的网络。在
def get_model():
inputs = Input(shape=(96, 96, 1))
# a layer instance is callable on a tensor, and returns a tensor
x = Conv2D(16, kernel_size=5, padding='same', activation='relu')(inputs)
x = Conv2D(32, kernel_size=5, padding='valid', activation='relu')(x)
x = Dropout(0.25)(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Conv2D(64, kernel_size=5, padding='valid', activation='relu')(x)
x = Conv2D(128, kernel_size=5, padding='valid', activation='relu')(x)
x = Dropout(0.25)(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Conv2D(256, kernel_size=3, padding='valid', activation='relu')(x)
x = Dropout(0.25)(x)
x = MaxPooling2D(pool_size=(1, 1))(x)
x = Flatten()(x)
present = Dense(256)(x)
present = PReLU()(present)
present = Dense(15, activation="sigmoid", name="classification")(present)
position = Dense(256)(x)
position = PReLU()(position)
position = BatchNormalization()(position)
position = Dense(128)(position)
position = PReLU()(position)
position = BatchNormalization()(position)
position = Dense(64)(position)
position = PReLU()(position)
position = Dense(30, activation="relu", name="position")(position)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=[present, position])
model.compile(optimizer='adam',
loss={'classification':'binary_crossentropy','position':'mse'},
metrics=['accuracy'])
return model
虽然分类精度很好,但定位精度在1%以下。在
可以创建自定义损失,以便在坐标损失计算中忽略置信值低于阈值的点,但不忽略置信度损失计算:
相关问题 更多 >
编程相关推荐