第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CNN 能比預(yù)訓(xùn)練的 CNN 做得更好嗎?

CNN 能比預(yù)訓(xùn)練的 CNN 做得更好嗎?

臨摹微笑 2022-10-25 10:35:03
據(jù)我所知。預(yù)訓(xùn)練的 CNN 比 CNN 做得更好。我有一個包含 855 張圖像的數(shù)據(jù)集。我已經(jīng)應(yīng)用了 CNN 并獲得了 94% 的準確率。然后我應(yīng)用了預(yù)訓(xùn)練模型(VGG16、ResNet50、Inception_V3、MobileNet)也進行了微調(diào),但我仍然獲得了最高的 60%,其中兩個在分類方面做得非常糟糕。CNN 真的能比預(yù)訓(xùn)練模型做得更好,還是我的實現(xiàn)是錯誤的。我已將圖像轉(zhuǎn)換為 100 x 100 尺寸并遵循keras application的方式。然后是什么問題??樸素的 CNN 方法:def cnn_model():    size = (100,100,1)    num_cnn_layers =2    NUM_FILTERS = 32    KERNEL = (3, 3)    MAX_NEURONS = 120    model = Sequential()    for i in range(1, num_cnn_layers+1):        if i == 1:            model.add(Conv2D(NUM_FILTERS*i, KERNEL, input_shape=size,             activation='relu', padding='same'))        else:            model.add(Conv2D(NUM_FILTERS*i, KERNEL, activation='relu',             padding='same'))    model.add(MaxPooling2D(pool_size=(2,2)))    model.add(Flatten())    model.add(Dense(int(MAX_NEURONS), activation='relu'))    model.add(Dropout(0.25))    model.add(Dense(int(MAX_NEURONS/2), activation='relu'))    model.add(Dropout(0.4))    model.add(Dense(3, activation='softmax'))    model.compile(loss='categorical_crossentropy', optimizer='adam',     metrics=['accuracy'])    return modelVGG16 方法:def vgg():`  `vgg_model = keras.applications.vgg16.VGG16(weights='imagenet',include_top=False,input_shape = (100,100,3))    model = Sequential()    for layer in vgg_model.layers:        model.add(layer)    # Freeze the layers     for layer in model.layers:        layer.trainable = False    model.add(keras.layers.Flatten())    model.add(keras.layers.Dense(3, activation='softmax'))    model.compile(optimizer=keras.optimizers.Adam(lr=1e-5),              loss='categorical_crossentropy',              metrics=['accuracy'])    return model 
查看完整描述

3 回答

?
慕哥9229398

TA貢獻1877條經(jīng)驗 獲得超6個贊

在這兩種情況下,您所說的 CNN 都在談?wù)撏患?,這是一種神經(jīng)網(wǎng)絡(luò)模型。只是預(yù)訓(xùn)練的模型已經(jīng)在其他一些數(shù)據(jù)上進行了訓(xùn)練,而不是您正在處理并嘗試分類的數(shù)據(jù)集。


這里通常使用的稱為遷移學(xué)習(xí)。與其凍結(jié)所有層,不如嘗試讓最后幾層保持打開狀態(tài),以便可以使用您自己的數(shù)據(jù)重新訓(xùn)練它們,以便預(yù)訓(xùn)練的模型也可以編輯其權(quán)重和偏差以滿足您的需求。您嘗試分類的數(shù)據(jù)集可能與預(yù)訓(xùn)練模型無關(guān)。


這是我自己工作的一個例子,還有一些額外的代碼,但你可以用你自己的代碼讓它工作,邏輯保持不變


#You extract the layer which you want to manipulate, usually the last few.

last_layer = pre_trained_model.get_layer(name_of_layer)


# Flatten the output layer to 1 dimension

x = layers.Flatten()(last_output)

# Add a fully connected layer with 1,024 hidden units and ReLU activation

x = layers.Dense(1024,activation='relu')(x)

# Add a dropout rate of 0.2

x = layers.Dropout(0.2)(x)                  

# Add a final sigmoid layer for classification

x = layers.Dense(1,activation='sigmoid')(x)           


#Here we combine your newly added layers and the pre-trained model.

model = Model( pre_trained_model.input, x) 


model.compile(optimizer = RMSprop(lr=0.0001), 

              loss = 'binary_crossentropy', 

              metrics = ['accuracy'])


查看完整回答
反對 回復(fù) 2022-10-25
?
楊__羊羊

TA貢獻1943條經(jīng)驗 獲得超7個贊

#You extract the layer which you want to manipulate, usually the last few.

last_layer = pre_trained_model.get_layer(name_of_layer)


# Flatten the output layer to 1 dimension

x = layers.Flatten()(last_output)

# Add a fully connected layer with 1,024 hidden units and ReLU activation

x = layers.Dense(1024,activation='relu')(x)

# Add a dropout rate of 0.2

x = layers.Dropout(0.2)(x)                  

# Add a final sigmoid layer for classification

x = layers.Dense(1,activation='sigmoid')(x)           


#Here we combine your newly added layers and the pre-trained model.

model = Model( pre_trained_model.input, x) 


model.compile(optimizer = RMSprop(lr=0.0001), 

              loss = 'binary_crossentropy', 

              metrics = ['accuracy'])


查看完整回答
反對 回復(fù) 2022-10-25
?
慕的地10843

TA貢獻1785條經(jīng)驗 獲得超8個贊

除了@Ilknur Mustafa 提到的內(nèi)容之外,由于您的數(shù)據(jù)集可能與用于預(yù)訓(xùn)練的圖像不同,您可以嘗試重新訓(xùn)練預(yù)訓(xùn)練模型的最后幾層,而不是添加全新的層。下面的示例代碼除了輸出層之外沒有添加任何額外的可訓(xùn)練層。通過這種方式,您可以通過在現(xiàn)有權(quán)重上重新訓(xùn)練最后幾層來受益,而不是從頭開始訓(xùn)練。如果您沒有要訓(xùn)練的大型數(shù)據(jù)集,這可能會有所幫助。


# load model without classifier layers 

vgg = VGG16(include_top=False, input_shape=(100, 100, 3), weights='imagenet', pooling='avg')

# make only last 2 conv layers trainable 

for layer in vgg.layers[:-4]:

    layer.trainable = False

# add output layer  

out_layer = Dense(3, activation='softmax')(vgg.layers[-1].output)

model_pre_vgg = Model(vgg.input, out_layer)

# compile model 

opt = SGD(lr=1e-5) 

model_pre_vgg.compile(optimizer=opt, loss=keras.losses.categorical_crossentropy, metrics=['accuracy'])



查看完整回答
反對 回復(fù) 2022-10-25
  • 3 回答
  • 0 關(guān)注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號