訂閱
糾錯(cuò)
加入自媒體

使用TensorFlow從頭開始實(shí)現(xiàn)這個(gè)架構(gòu)

# 繪制模型

tf.keras.utils.plot_model(model, to_file='model.png', show_shapes=True, show_dtype=False,show_layer_names=True, rankdir='TB', expand_nested=False, dpi=96)

模型圖的一個(gè)片段:

使用TensorFlow的MobileNet模型實(shí)現(xiàn):

import tensorflow as tf

# 導(dǎo)入所有必要的層

from tensorflow.keras.layers import Input, DepthwiseConv2D

from tensorflow.keras.layers import Conv2D, BatchNormalization

from tensorflow.keras.layers import ReLU, AvgPool2D, Flatten, Dense

from tensorflow.keras import Model

# MobileNet block

def mobilnet_block (x, filters, strides):

x = DepthwiseConv2D(kernel_size = 3, strides = strides, padding = 'same')(x)

x = BatchNormalization()(x)

x = ReLU()(x)

x = Conv2D(filters = filters, kernel_size = 1, strides = 1)(x)

x = BatchNormalization()(x)

x = ReLU()(x)

return x

# 模型主干

input = Input(shape = (224,224,3))

x = Conv2D(filters = 32, kernel_size = 3, strides = 2, padding = 'same')(input)

x = BatchNormalization()(x)

x = ReLU()(x)

# 模型的主要部分

x = mobilnet_block(x, filters = 64, strides = 1)

x = mobilnet_block(x, filters = 128, strides = 2)

x = mobilnet_block(x, filters = 128, strides = 1)

x = mobilnet_block(x, filters = 256, strides = 2)

x = mobilnet_block(x, filters = 256, strides = 1)

x = mobilnet_block(x, filters = 512, strides = 2)

for _ in range (5):

x = mobilnet_block(x, filters = 512, strides = 1)

x = mobilnet_block(x, filters = 1024, strides = 2)

x = mobilnet_block(x, filters = 1024, strides = 1)

x = AvgPool2D (pool_size = 7, strides = 1, data_format='channels_first')(x)

output = Dense (units = 1000, activation = 'softmax')(x)

model = Model(inputs=input, outputs=output)

model.summary()

# 繪制模型

tf.keras.utils.plot_model(model, to_file='model.png', show_shapes=True, show_dtype=False,show_layer_names=True, rankdir='TB', expand_nested=False, dpi=96)

結(jié)論

MobileNet是最小的深度神經(jīng)網(wǎng)絡(luò)之一,它速度快、效率高,可以在沒有高端GPU的設(shè)備上運(yùn)行。

當(dāng)使用Keras(在TensorFlow上)這樣的框架時(shí),這些網(wǎng)絡(luò)的實(shí)現(xiàn)非常簡(jiǎn)單。

<上一頁  1  2  
聲明: 本文由入駐維科號(hào)的作者撰寫,觀點(diǎn)僅代表作者本人,不代表OFweek立場(chǎng)。如有侵權(quán)或其他問題,請(qǐng)聯(lián)系舉報(bào)。

發(fā)表評(píng)論

0條評(píng)論,0人參與

請(qǐng)輸入評(píng)論內(nèi)容...

請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字

您提交的評(píng)論過于頻繁,請(qǐng)輸入驗(yàn)證碼繼續(xù)

  • 看不清,點(diǎn)擊換一張  刷新

暫無評(píng)論

暫無評(píng)論

人工智能 獵頭職位 更多
掃碼關(guān)注公眾號(hào)
OFweek人工智能網(wǎng)
獲取更多精彩內(nèi)容
文章糾錯(cuò)
x
*文字標(biāo)題:
*糾錯(cuò)內(nèi)容:
聯(lián)系郵箱:
*驗(yàn) 證 碼:

粵公網(wǎng)安備 44030502002758號(hào)