使用TensorFlow從頭開始實現(xiàn)這個架構(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)
模型圖的一個片段:
使用TensorFlow的MobileNet模型實現(xiàn):
import tensorflow as tf
# 導入所有必要的層
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è)備上運行。
當使用Keras(在TensorFlow上)這樣的框架時,這些網(wǎng)絡(luò)的實現(xiàn)非常簡單。

請輸入評論內(nèi)容...
請輸入評論/評論長度6~500個字
最新活動更多
推薦專題
-
10 大模型的盡頭是開源
- 1 特斯拉工人被故障機器人打成重傷,索賠3.6億
- 2 【行業(yè)深度研究】退居幕后四年后,張一鳴終于把算法公司變成AI公司?
- 3 人形機器人廠商,正在批量復(fù)刻宇樹G1
- 4 AI 時代,阿里云想當“安卓” ,那誰是“蘋果”?
- 5 華為公布昇騰芯片三年計劃,自研HBM曝光
- 6 硬剛英偉達!華為發(fā)布全球最強算力超節(jié)點和集群
- 7 機器人9月大事件|3家國產(chǎn)機器人沖刺IPO,行業(yè)交付與融資再創(chuàng)新高!
- 8 谷歌“香蕉”爆火啟示:國產(chǎn)垂類AI的危機還是轉(zhuǎn)機?
- 9 00后華裔女生靠兩部AI電影狂賺7.8億人民幣,AI正式進軍好萊塢
- 10 美光:AI Capex瘋投不止,終于要拉起存儲超級周期了?