iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 18
0
AI & Machine Learning

tensorflow python系列 第 18

DAY18 建立layer函數

前言:

後面幾天我們將使用上篇文章說明的Mnist資料集,來進行手寫數字的辨識,再開始前先說明一下layer函數,因為之後的類神經網路會使用此方法。

程式開始:

def layer(out_dim,in_dim,inputs,activation=None):
        W = tf.Variable(tf.random_normal([in_dim,out_dim]))
        b = tf.Variable(tf.random_normal([1,out_dim]))
        XWb =tf.matmul(inputs,W) + b
        if activation is None:
            outputs = XWb
        else:
            outputs = activation(XWb)
        return outputs

說明:

out_dim:輸出的神經元數

in_dim:輸入的神經元數

inputs:輸入的二維陣列

activation:激勵函數

W:權重(此處使用常態分佈亂數)

b:偏差(此處使用常態分佈亂數)

運算式:XWb=(inputs*W)+b

結語:

這個layer函數,再後面幾天的手寫數字辨識時會使用到,所以先在這邊介紹。


上一篇
DAY17 Mnist資料集
下一篇
DAY19 手寫數字辨識(1)
系列文
tensorflow python30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言