這篇文章主要講解了keras如何實(shí)現(xiàn)densenet和Xception的模型融合,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
成都創(chuàng)新互聯(lián)專(zhuān)注于網(wǎng)站建設(shè)|網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋成都白烏魚(yú)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷(xiāo)售的產(chǎn)品,結(jié)合品牌形象的塑造,量身開(kāi)發(fā)品質(zhì)網(wǎng)站。我正在參加天池上的一個(gè)競(jìng)賽,剛開(kāi)始用的是DenseNet121但是效果沒(méi)有達(dá)到預(yù)期,因此開(kāi)始嘗試使用模型融合,將Desenet和Xception融合起來(lái)共同提取特征。
代碼如下:
def Multimodel(cnn_weights_path=None,all_weights_path=None,class_num=5,cnn_no_vary=False): ''' 獲取densent121,xinception并聯(lián)的網(wǎng)絡(luò) 此處的cnn_weights_path是個(gè)列表是densenet和xception的卷積部分的權(quán)值 ''' input_layer=Input(shape=(224,224,3)) dense=DenseNet121(include_top=False,weights=None,input_shape=(224,224,3)) xception=Xception(include_top=False,weights=None,input_shape=(224,224,3)) #res=ResNet50(include_top=False,weights=None,input_shape=(224,224,3)) if cnn_no_vary: for i,layer in enumerate(dense.layers): dense.layers[i].trainable=False for i,layer in enumerate(xception.layers): xception.layers[i].trainable=False #for i,layer in enumerate(res.layers): # res.layers[i].trainable=False if cnn_weights_path!=None: dense.load_weights(cnn_weights_path[0]) xception.load_weights(cnn_weights_path[1]) #res.load_weights(cnn_weights_path[2]) dense=dense(input_layer) xception=xception(input_layer) #對(duì)dense_121和xception進(jìn)行全局大池化 top1_model=GlobalMaxPooling2D(data_format='channels_last')(dense) top2_model=GlobalMaxPooling2D(data_format='channels_last')(xception) #top3_model=GlobalMaxPool2D(input_shape=res.output_shape)(res.outputs[0]) print(top1_model.shape,top2_model.shape) #把top1_model和top2_model連接起來(lái) t=keras.layers.Concatenate(axis=1)([top1_model,top2_model]) #第一個(gè)全連接層 top_model=Dense(units=512,activation="relu")(t) top_model=Dropout(rate=0.5)(top_model) top_model=Dense(units=class_num,activation="softmax")(top_model) model=Model(inputs=input_layer,outputs=top_model) #加載全部的參數(shù) if all_weights_path: model.load_weights(all_weights_path) return model
本文題目:keras如何實(shí)現(xiàn)densenet和Xception的模型融合-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://muchs.cn/article38/dgeppp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、小程序開(kāi)發(fā)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、微信小程序、企業(yè)建站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容