准确性不会随着时代而改变

时间:2019-04-21 00:04:12

标签: tensorflow machine-learning keras deep-learning

我在Keras建立了一个squeezenet模型。使用标准化的自定义数据集。验证准确度似乎在各个时期都没有提高,训练准确度也没有提高。这是我的代码

我尝试在第二层之后添加maxpooling。输入图像为50x50。

我也尝试使用SGD。将学习率更改为1e-5和1e-4。如github中建议的那样,添加了更多的卷积层。似乎没有什么改变验证准确性。

def build_squeezenet(input_shape):

    input_layer = Input(shape = input_shape)

    out = Conv2D(96, kernel_size =(3, 3), activation='relu')(input_layer)
    out = MaxPooling2D(pool_size=2, strides=None, padding='valid')(out)
    # no mxpooling done since small images 
    out = fire_module(out,squeeze =16 , expansion =64)
    out = fire_module(out,squeeze = 16 , expansion=64)

    out = fire_module(out,squeeze= 32,expansion = 128)
    out = fire_module(out,squeeze= 32,expansion = 128)

    out = fire_module(out , squeeze = 48 ,expansion=192)
    out = fire_module(out,squeeze = 48 , expansion = 192)

    out = fire_module(out,squeeze = 64 , expansion = 256)
    out = fire_module(out,squeeze = 64 , expansion = 256)

    out = Dropout(0.2)(out)

    out = Conv2D(128,kernel_size=(1,1),padding='valid',activation='relu')(out)
    out = Conv2D(2,kernel_size=(1,1),padding='valid',activation='relu')(out)

    out = GlobalAveragePooling2D()(out)
    out = Dense(2, activation="softmax")(out)

    model = Model(input_layer, out, name='squeezenet')
    return model 


def fire_module(input_layer, squeeze =16 , expansion =32):

# a definition for fire module et.al https://github.com/rcmalli/keras-squeezenet/

    fire_sq = Conv2D(squeeze,1,1,activation='relu')(input_layer)
    fire_exp1 = Conv2D(expansion ,kernel_size=(1,1),activation='relu',padding='valid')(fire_sq)
    fire_exp2 = Conv2D(expansion ,kernel_size=(3,3),activation='relu',padding='same')(fire_sq)
    out = concatenate([fire_exp1,fire_exp2], axis=3)

    return out


Model training commands 

model_dw = build_squeezenet(input_shape= (50,50,1))

model_dw.compile(optimizer=Adam(lr=1e-3), loss='categorical_crossentropy',metrics=['accuracy'])

model_dw.fit(x=train_images, 
            y=train_labels, 
            batch_size=25,
            epochs=10, 
            verbose=1,  
            validation_split=0.2,
            validation_data=(val_images,val_labels), 
            shuffle=True)

0 个答案:

没有答案