无法将模型拟合到训练数据。为什么某些类别的训练集的准确性不能增加(损失不会减少)?

时间:2019-07-27 11:11:26

标签: keras conv-neural-network loss

我已经在Keras中为55个二进制类别训练了一个模型。该模型无法拟合训练数据。在训练过程中,大多数类别的准确性都提高了(损失减少了),但是对于某些类别,训练的准确性没有超过%55和%60。

据我所知,至少所有Train_acc都应接近%100(但不一定Best_val_acc),因此我可以说该网络是经过训练和过拟合的(我知道我们需要避免过度拟合)。但是,这种结果表明网络无法学习我的训练数据。编码时我做错什么了吗?我在这篇文章的结尾附上我的网络摘要。

我把部分结果供您审核。顺便说一句,我看了一下数据集的注释,发现与Age31-45Age17-30相比,AgeLess16Age46-60的样本最多。

Accuracy and Loss for Femal_FineTuned_AllLayers:
Train_acc: %96.35855110561212,  Train_loss: 0.10732883015214066
Best_val_acc: %93.82214298728499,   Val_loss: 0.174280562132292
**********
**********
Accuracy and Loss for AgeLess16_FineTuned_AllLayers:
Train_acc: %99.17721500686592,  Train_loss: 0.05093206035518569
Best_val_acc: %99.2638396430493,    Val_loss: 0.04364626104115246
**********
**********
Accuracy and Loss for Age17-30_FineTuned_AllLayers:
Train_acc: %59.80718333591055,  Train_loss: 0.6711170782595829
Best_val_acc: %60.8303891317162,    Val_loss: 0.6664492566186773
**********
**********
Accuracy and Loss for Age31-45_FineTuned_AllLayers:
Train_acc: %55.24286194234288,  Train_loss: 0.6829969891255696
Best_val_acc: %56.93757418889741,   Val_loss: 0.6803399343723684
**********
**********
Accuracy and Loss for Age46-60_FineTuned_AllLayers:
Train_acc: %96.42478600210185,  Train_loss: 0.1544494673218781
Best_val_acc: %96.95524095576279,   Val_loss: 0.13411041373305804
**********
**********
Accuracy and Loss for BodyFat_FineTuned_AllLayers:
Train_acc: %86.43950484528554,  Train_loss: 0.39786816761884614
Best_val_acc: %87.1849227551858,    Val_loss: 0.3838976073145726
**********
**********
Accuracy and Loss for BodyNormal_FineTuned_AllLayers:
Train_acc: %77.93935805949562,  Train_loss: 0.5303131385909517
Best_val_acc: %77.9151941672652,    Val_loss: 0.528312525914892
**********
**********
Accuracy and Loss for BodyThin_FineTuned_AllLayers:
Train_acc: %92.5551949922639,   Train_loss: 0.2664116882610258
Best_val_acc: %92.64428666118178,   Val_loss: 0.2637324569959663
**********
**********
Accuracy and Loss for Customer_FineTuned_AllLayers:
Train_acc: %95.77274004045148,  Train_loss: 0.15548874558041995
Best_val_acc: %96.18963424392808,   Val_loss: 0.14634984320751418
**********
**********
Accuracy and Loss for Employee_FineTuned_AllLayers:
Train_acc: %96.50132414397682,  Train_loss: 0.1296264658043803
Best_val_acc: %96.8138981448186,    Val_loss: 0.12327752215623224
**********
**********
Accuracy and Loss for hs-BaldHead_FineTuned_AllLayers:
Train_acc: %99.40241376529696,  Train_loss: 0.03519799720703804
Best_val_acc: %99.5229680876569,    Val_loss: 0.02903259372079769
**********
**********
Accuracy and Loss for hs-LongHair_FineTuned_AllLayers:
Train_acc: %90.63732630326743,  Train_loss: 0.2004715618580678
Best_val_acc: %90.86572360795856,   Val_loss: 0.20626683917924438
**********
**********
Accuracy and Loss for hs-BlackHair_FineTuned_AllLayers:
Train_acc: %93.31027304104997,  Train_loss: 0.22499078004035636
Best_val_acc: %93.75147156426145,   Val_loss: 0.22317562431965826
**********
**********

Accuracy and Loss for ub-Shirt_FineTuned_AllLayers:
Train_acc: %78.37650845195218,  Train_loss: 0.5004801768453149
Best_val_acc: %79.33451089441988,   Val_loss: 0.48233152837333465
**********
**********
Accuracy and Loss for ub-Sweater_FineTuned_AllLayers:
Train_acc: %92.05180968884198,  Train_loss: 0.2790391942859573
Best_val_acc: %92.72673661843626,   Val_loss: 0.25994354528588876
**********
**********
Accuracy and Loss for ub-Vest_FineTuned_AllLayers:
Train_acc: %95.41065580517817,  Train_loss: 0.17248446327815925
Best_val_acc: %95.83038808459808,   Val_loss: 0.16092383824025575
**********
**********
Accuracy and Loss for ub-TShirt_FineTuned_AllLayers:
Train_acc: %76.87224004278384,  Train_loss: 0.5403878908250168
Best_val_acc: %77.37338032893774,   Val_loss: 0.5337123219691682
**********
**********
Accuracy and Loss for ub-Cotton_FineTuned_AllLayers:
Train_acc: %88.4795401174074,   Train_loss: 0.35894714934109306
Best_val_acc: %89.44640678778133,   Val_loss: 0.3402983718524271
**********
**********
Accuracy and Loss for ub-Jacket_FineTuned_AllLayers:
Train_acc: %71.56020030159968,  Train_loss: 0.5912178378658572
Best_val_acc: %71.77856311342461,   Val_loss: 0.5866910439638423
**********
**********
Accuracy and Loss for ub-SuitUp_FineTuned_AllLayers:
Train_acc: %97.03414728176884,  Train_loss: 0.13934014985967874
Best_val_acc: %97.10836230093796,   Val_loss: 0.1311324757366969
**********
**********

部分代码:

input_shape= (500,500, 3)
learning_rate=0.01
Number_of_epochs_all_layers = 20
DROPOUT_PROB = 0.5
BATCH_SIZE = 10

output_layers[i] = KL.Dense(1, activation='sigmoid', name=Categories[i])(x)

model.compile(optimizer=optimizers.SGD(lr=learning_rate),
              loss='binary_crossentropy',
              loss_weights = [0.5, 0.25, 0.25, 0.25, 0.25, 0.333, 0.333, 0.333, 0.5, 0.5,
                              0.333, 0.333, 0.333, 0.5, 0.5, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
                              0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166, 0.166,
                              0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125,
                              0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.5],
              metrics=['accuracy'])

模型的一部分:

_________________
    Layer (type)                    Output Shape         Param #     Connected to                     
    ==================================================================================================
    input_1 (InputLayer)            (None, 500, 500, 3)  0                                            
    __________________________________________________________________________________________________
    bn4f_branch2b (BatchNorm)       (None, 32, 32, 256)  1024        res4f_branch2b[0][0]             
    __________________________________________________________________________________________________
    activation_27 (Activation)      (None, 32, 32, 256)  0           bn4f_branch2b[0][0]              
    __________________________________________________________________________________________________
    res4f_branch2c (Conv2D)         (None, 32, 32, 1024) 263168      activation_27[0][0]              
    __________________________________________________________________________________________________
    bn4f_branch2c (BatchNorm)       (None, 32, 32, 1024) 4096        res4f_branch2c[0][0]             
    __________________________________________________________________________________________________
    input_2 (InputLayer)            (None, 32, 32, 3)    0                                            
    __________________________________________________________________________________________________
    add_13 (Add)                    (None, 32, 32, 1024) 0           bn4f_branch2c[0][0]              
                                                                     res4e_out[0][0]                  
    __________________________________________________________________________________________________
    dense_1 (Dense)                 (None, 32, 32, 1024) 4096        input_2[0][0]                    
    __________________________________________________________________________________________________
    res4f_out (Activation)          (None, 32, 32, 1024) 0           add_13[0][0]                     
    __________________________________________________________________________________________________
    dropout_1 (Dropout)             (None, 32, 32, 1024) 0           dense_1[0][0]                    
    __________________________________________________________________________________________________
    multiply_1 (Multiply)           (None, 32, 32, 1024) 0           res4f_out[0][0]                  
                                                                     dropout_1[0][0]                  
    __________________________________________________________________________________________________
    global_average_pooling2d_1 (Glo (None, 1024)         0           multiply_1[0][0]                 
    __________________________________________________________________________________________________
    dense_2 (Dense)                 (None, 256)          262400      global_average_pooling2d_1[0][0] 
    __________________________________________________________________________________________________
    dropout_2 (Dropout)             (None, 256)          0           dense_2[0][0]                    
    __________________________________________________________________________________________________
    dense_3 (Dense)                 (None, 256)          65792       dropout_2[0][0]                  
    __________________________________________________________________________________________________
    dropout_3 (Dropout)             (None, 256)          0           dense_3[0][0]                    
    __________________________________________________________________________________________________
    dense_4 (Dense)                 (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_12 (Dense)                (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_6 (Dense)                 (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_8 (Dense)                 (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_10 (Dense)                (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_14 (Dense)                (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dense_16 (Dense)                (None, 128)          32896       dropout_3[0][0]                  
    __________________________________________________________________________________________________
    dropout_4 (Dropout)             (None, 128)          0           dense_4[0][0]                    
    __________________________________________________________________________________________________
    dropout_12 (Dropout)            (None, 128)          0           dense_12[0][0]                   
    __________________________________________________________________________________________________
    dropout_6 (Dropout)             (None, 128)          0           dense_6[0][0]                    
    __________________________________________________________________________________________________
    dropout_8 (Dropout)             (None, 128)          0           dense_8[0][0]                    
    __________________________________________________________________________________________________
    dropout_10 (Dropout)            (None, 128)          0           dense_10[0][0]                   
    __________________________________________________________________________________________________
    dropout_14 (Dropout)            (None, 128)          0           dense_14[0][0]                   
    __________________________________________________________________________________________________
    dropout_16 (Dropout)            (None, 128)          0           dense_16[0][0]                   
    __________________________________________________________________________________________________
    dense_5 (Dense)                 (None, 64)           8256        dropout_4[0][0]                  
    __________________________________________________________________________________________________
    dense_13 (Dense)                (None, 64)           8256        dropout_12[0][0]                 
    __________________________________________________________________________________________________
    dense_7 (Dense)                 (None, 64)           8256        dropout_6[0][0]                  
    __________________________________________________________________________________________________
    dense_9 (Dense)                 (None, 64)           8256        dropout_8[0][0]                  
    __________________________________________________________________________________________________
    dense_11 (Dense)                (None, 64)           8256        dropout_10[0][0]                 
    __________________________________________________________________________________________________
    dense_15 (Dense)                (None, 64)           8256        dropout_14[0][0]                 
    __________________________________________________________________________________________________
    dense_17 (Dense)                (None, 64)           8256        dropout_16[0][0]                 
    __________________________________________________________________________________________________
    dropout_5 (Dropout)             (None, 64)           0           dense_5[0][0]                    
    __________________________________________________________________________________________________
    dropout_13 (Dropout)            (None, 64)           0           dense_13[0][0]                   
    __________________________________________________________________________________________________
    dropout_7 (Dropout)             (None, 64)           0           dense_7[0][0]                    
    __________________________________________________________________________________________________
    dropout_9 (Dropout)             (None, 64)           0           dense_9[0][0]                    
    __________________________________________________________________________________________________
    dropout_11 (Dropout)            (None, 64)           0           dense_11[0][0]                   
    __________________________________________________________________________________________________
    dropout_15 (Dropout)            (None, 64)           0           dense_15[0][0]                   
    __________________________________________________________________________________________________
    dropout_17 (Dropout)            (None, 64)           0           dense_17[0][0]                   
    __________________________________________________________________________________________________
    Femal (Dense)                   (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    AgeLess16 (Dense)               (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    Age17-30 (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    Age31-45 (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    Age46-60 (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    BodyFat (Dense)                 (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    BodyNormal (Dense)              (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    BodyThin (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    Customer (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    Employee (Dense)                (None, 1)            65          dropout_13[0][0]                 
    __________________________________________________________________________________________________
    hs-BaldHead (Dense)             (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    hs-LongHair (Dense)             (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    hs-BlackHair (Dense)            (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    hs-Hat (Dense)                  (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    hs-Glasses (Dense)              (None, 1)            65          dropout_5[0][0]                  
    __________________________________________________________________________________________________
    ub-Shirt (Dense)                (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Sweater (Dense)              (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Vest (Dense)                 (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-TShirt (Dense)               (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Cotton (Dense)               (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Jacket (Dense)               (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-SuitUp (Dense)               (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Tight (Dense)                (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-ShortSleeve (Dense)          (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    ub-Others (Dense)               (None, 1)            65          dropout_7[0][0]                  
    __________________________________________________________________________________________________
    lb-LongTrousers (Dense)         (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    lb-Skirt (Dense)                (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    lb-ShortSkirt (Dense)           (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    lb-Dress (Dense)                (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    lb-Jeans (Dense)                (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    lb-TightTrousers (Dense)        (None, 1)            65          dropout_9[0][0]                  
    __________________________________________________________________________________________________
    shoes-Leather (Dense)           (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    shoes-Sports (Dense)            (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    shoes-Boots (Dense)             (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    shoes-Cloth (Dense)             (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    shoes-Casual (Dense)            (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    shoes-Other (Dense)             (None, 1)            65          dropout_11[0][0]                 
    __________________________________________________________________________________________________
    attachment-Backpack (Dense)     (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-ShoulderBag (Dense)  (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-HandBag (Dense)      (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-Box (Dense)          (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-PlasticBag (Dense)   (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-PaperBag (Dense)     (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-HandTrunk (Dense)    (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    attachment-Other (Dense)        (None, 1)            65          dropout_15[0][0]                 
    __________________________________________________________________________________________________
    action-Calling (Dense)          (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Talking (Dense)          (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Gathering (Dense)        (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Holding (Dense)          (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Pushing (Dense)          (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Pulling (Dense)          (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-CarryingByArm (Dense)    (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-CarryingByHand (Dense)   (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    action-Other (Dense)            (None, 1)            65          dropout_17[0][0]                 
    __________________________________________________________________________________________________
    Male (Dense)                    (None, 1)            65          dropout_5[0][0] 

0 个答案:

没有答案