日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(二)yolo3

發布時間:2024/9/21 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (二)yolo3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是YOLO V3的代碼,只有網絡模型的,嘿嘿嘿嘿嘿

1.darknet.py

import tensorflow as tf from tensorflow.keras import layers, Sequential from tensorflow.keras.initializers import RandomNormal from tensorflow.keras.regularizers import l1, l2def Conv_BN_Leaky(filters, ks, strides=(1,1)):lay = Sequential([layers.Conv2D(filters, ks, strides=strides, padding="same",kernel_initializer=tf.random_normal_initializer(stddev=0.02), kernel_regularizer=l2(5e-4), use_bias=False),layers.BatchNormalization(),layers.LeakyReLU(alpha=0.1)])return laydef resblock_body(inp, filters, blocks):# x = layers.ZeroPadding2D(((1,0), (1,0)))(inp)x = Conv_BN_Leaky(filters, (3, 3), strides=(2, 2))(inp)for i in range(blocks):y = Conv_BN_Leaky(filters//2, (1,1))(x) # 降維y = Conv_BN_Leaky(filters//2, (3, 3))(y) # 卷積y = Conv_BN_Leaky(filters, (1,1))(y) # 升維x = layers.add([x, y]) # 殘差相加return xdef darknet_body(x):# 1.先進行一次3x3卷積x = Conv_BN_Leaky(filters=32, ks=(3,3))(x)# 2.resblock_body x 1次x = resblock_body(inp=x, filters=64, blocks=1)# 3.resblock_body x 2次x = resblock_body(inp=x, filters=128, blocks=2)# 4.resblock_body x 8次x = resblock_body(inp=x, filters=256, blocks=8)feat1 = x# 5.resblock_body x 8次x = resblock_body(inp=x, filters=512, blocks=8)feat2 = x# 6.resblock_body x 4次x = resblock_body(inp=x, filters=1024, blocks=4)feat3 = xreturn feat1, feat2, feat3if __name__ == '__main__':from tensorflow.keras.layers import Inputinputs = Input(shape=(416, 416, 3))feat1, feat2, feat3 = darknet_body(inputs)print(feat3.shape)

2:? ?yolo.py

import tensorflow as tf from tensorflow.keras import Sequential,layers from darknet import *def make_five_conv(x, filters):x= Conv_BN_Leaky(filters, (1,1))(x)x= Conv_BN_Leaky(filters*2, (3,3))(x)x= Conv_BN_Leaky(filters, (1,1))(x)x= Conv_BN_Leaky(filters*2, (3,3))(x)x= Conv_BN_Leaky(filters, (1,1))(x)return xdef last_conv(x, out_filters):x = Conv_BN_Leaky(out_filters, (3,3))(x)y = layers.Conv2D(out_filters, (1, 1), padding="same", kernel_initializer=tf.random_normal_initializer(stddev=0.02), kernel_regularizer=l2(5e-4), use_bias=False)(x)return ydef YOLO_V3(inputs, nc):feat_big, feat_middle, feat_small = darknet_body(inputs)# 第一部分:feat_small = make_five_conv(feat_small, 512)print("feat small shape:", feat_small)out_small = last_conv(feat_small, nc*3)# 第二部分:feat_small = Conv_BN_Leaky(256, (1,1))(feat_small)up_middle = layers.UpSampling2D()(feat_small)middle_cat = layers.Concatenate()([up_middle, feat_middle])middle_set = make_five_conv(middle_cat, 256)out_middle = last_conv(middle_set, nc*3)# 第三部分:feat_middle = Conv_BN_Leaky(128, (1,1))(middle_set)up_big = layers.UpSampling2D()(feat_middle)big_cat = layers.Concatenate()([up_big, feat_big])big_set = make_five_conv(big_cat, 128)out_big = last_conv(big_set, nc*3)return out_small, out_middle, out_bigif __name__ == '__main__':from tensorflow.keras.layers import Inputinputs = Input(shape=(416, 416, 3))feat1, feat2, feat3 = YOLO_V3(inputs, nc=20)print(feat3.shape)

總結

以上是生活随笔為你收集整理的(二)yolo3的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。