91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 14.38MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2023-06-15
  • 語言: 其他
  • 標簽: CNN+SVM??

資源簡介

傳統的卷積神經網絡是利用全連接層進行分類,svm對于小樣本數據具有較強的分類效果,利用SVM代替卷積神經網絡中的全連接層,可以提高網絡識別精度

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-
“““
Created?on?Sat?Oct?19?21:39:21?2019

@author:?華陽
“““
import?random
import?tensorflow?as?tf
import?numpy?as?np
from?libsvm.python.svmutil?import?*

train_data?=?np.load(“train_data.npy“)
train_label?=?np.load(“train_label.npy“)
test_data?=?np.load(“test_data.npy“)
test_label?=?np.load(“test_label.npy“)

train_data?=?train_data.reshape(15006400)
test_data?=?test_data.reshape(3006400)


sess?=?tf.InteractiveSession()
def?weight_variable(shape):
????initial?=?tf.truncated_normal(shape?stddev?=?0.05)??#截斷的正態分布,標準差stddev
????return?tf.Variable(initial)
#?偏置參數初始化
def?bias_variable(shape):
????initial?=?tf.constant(0.1?shape?=?shape)
????return?tf.Variable(initial)?
#?定義卷積層
def?conv2d(x?W):
????#?stride的四個參數:[batch?height?width?channels]?[batch_size?image_rows?image_cols?number_of_colors]
????#?height?width就是圖像的高度和寬度,batch和channels在卷積層中通常設為1
????return?tf.nn.conv2d(x?W?strides?=?[1?1?1?1]?padding?=?‘SAME‘)?
def?max_pool_2x2(x):
????return?tf.nn.max_pool(x?ksize?=?[1?2?2?1]?strides?=?[1?2?2?1]?padding?=?‘SAME‘)

xs?=?tf.placeholder(tf.float32?[None?6400])
ys?=?tf.placeholder(tf.float32?[None?2])
keep_prob?=?tf.placeholder(tf.float32)

x_image?=?tf.reshape(xs?[-1?80?80?1])#??-1?28?28?1

#print(x_image.shape)

#?卷積層一

#?patch為5*5,in_size為1,即圖像的厚度,如果是彩色,則為3,32是out_size,輸出的大小-》32個卷積和(濾波器)

W_conv1?=?weight_variable([9?9?1?32])
b_conv1?=?bias_variable([32])
#?ReLU操作,輸出大小為28*28*32

h_conv1?=?tf.nn.relu(conv2d(x_image?W_conv1)?+?b_conv1)
#?Pooling操作,輸出大小為14*14*32
h_pool1?=?max_pool_2x2(h_conv1)


#?卷積層二

#?patch為5*5,in_size為32,即圖像的厚度,64是out_size,輸出的大小

W_conv2?=?weight_variable([9?9?32?64])
b_conv2?=?bias_variable([64])
#?ReLU操作,輸出大小為14*14*64
h_conv2?=?tf.nn.relu(conv2d(h_pool1?W_conv2)?+?b_conv2)
#?Pooling操作,輸出大小為7*7*64
h_pool2?=?max_pool_2x2(h_conv2)

?

#?全連接層一
W_fc1?=?weight_variable([20?*?20?*?64?640])
b_fc1?=?bias_variable([640])
#?輸入數據變換
h_pool2_flat?=?tf.reshape(h_pool2?[-1?20?*?20?*?64])??#整形成m*n列n為7*7*64
#?進行全連接操作
h_fc1?=?tf.nn.relu(tf.matmul(h_pool2_flat?W_fc1)?+?b_fc1)??#?tf.matmul
#?防止過擬合,dropout
h_fc1_drop?=?tf.nn.dropout(h_fc1?keep_prob)


#?全連接層二
W_fc2?=?weight_variable([640?2])
b_fc2?=?bias_variable([2])

prediction?=?tf.nn.softmax(tf.matmul(h_fc1_drop?W_fc2)?+?b_fc2)
#?計算loss
cross_entropy?=?tf.reduce_mean(-tf.reduce_sum(ys?*?tf.log(tf.clip_by_value(prediction1e-81.0))))
#?神經網絡訓練
train_step?=?tf.train.AdamOptimizer(0.0001).minimize(cross_entropy)?#0.0001

#?定義Session
sess?=?tf.Session()

init?=?tf.global_variables_initializer()
#?執行初始化
sess.run(init)

for?i?in?range(500):
????
????????#?跑3000輪迭代,每次隨機從訓練樣本中抽出50個進行訓練
????batch?=?([]?[])
????p?=?random.sample(range(1500)?50)
????for?k?in?p:
????????batch[0].append(train_data[k])
????????batch[1].append(train_label[k])
????????
????sess.run(train_step?feed_dict={xs:?batch[0]?ys:?batch[1]?keep_prob:?0.6})

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????4595??2019-11-08?10:45??基于CNN+SVM的貓狗識別\CNN_SVM.py
?????文件????76800128??2019-10-22?10:41??基于CNN+SVM的貓狗識別\train_data.npy
?????文件???????12128??2019-10-22?10:41??基于CNN+SVM的貓狗識別\train_label.npy
?????文件?????3840128??2019-10-23?12:29??基于CNN+SVM的貓狗識別\x_temp.npy
?????文件??????768128??2019-10-23?12:29??基于CNN+SVM的貓狗識別\x_temp2.npy
?????文件?????????163??2019-11-08?10:50??基于CNN+SVM的貓狗識別\說明.txt
?????目錄???????????0??2020-10-12?16:31??基于CNN+SVM的貓狗識別\

評論

共有 條評論

相關資源