Dense layers

TensorFlow เบื้องต้นใน Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

โมเดล linear regression

แผนภาพแสดงโมเดล regression ที่มี 2 ฟีเจอร์ ได้แก่ สถานภาพสมรสและอายุ โดยมีเป้าหมายเป็นสถานะการผิดนัดชำระของผู้ถือบัตรเครดิต

TensorFlow เบื้องต้นใน Python

โครงข่ายประสาทเทียมคืออะไร?

แผนภาพแสดงโครงข่ายประสาทเทียมที่มี 2 ฟีเจอร์เป็น input ได้แก่ สถานภาพสมรสและอายุ โดยมีเป้าหมายเป็นสถานะการผิดนัดชำระของผู้ถือบัตรเครดิต

TensorFlow เบื้องต้นใน Python

โครงข่ายประสาทเทียมคืออะไร?

ภาพแสดงโครงข่ายประสาทเทียมที่ซับซ้อนขึ้น ประกอบด้วย 10 ฟีเจอร์ input, dense hidden layer 3 ชั้น และ output layer

  • Dense layer จะนำน้ำหนักไปคูณกับทุก node ของเลเยอร์ก่อนหน้า
TensorFlow เบื้องต้นใน Python

Dense layer อย่างง่าย

import tensorflow as tf
# Define inputs (features)
inputs = tf.constant([[1, 35]])
# Define weights
weights = tf.Variable([[-0.05], [-0.01]])
# Define the bias
bias = tf.Variable([0.5])
TensorFlow เบื้องต้นใน Python

Dense layer อย่างง่าย

# Multiply inputs (features) by the weights
product = tf.matmul(inputs, weights)
# Define dense layer
dense = tf.keras.activations.sigmoid(product+bias)

แผนภาพแสดง dense layer ที่รับ input node 2 node และให้ output 1 node

TensorFlow เบื้องต้นใน Python

การกำหนดโมเดลแบบครบถ้วน

import tensorflow as tf
# Define input (features) layer
inputs = tf.constant(data, tf.float32)
# Define first dense layer
dense1 = tf.keras.layers.Dense(10, activation='sigmoid')(inputs)
TensorFlow เบื้องต้นใน Python

การกำหนดโมเดลแบบครบถ้วน

# Define second dense layer
dense2 = tf.keras.layers.Dense(5, activation='sigmoid')(dense1)
# Define output (predictions) layer
outputs =  tf.keras.layers.Dense(1, activation='sigmoid')(dense2)

แผนภาพแสดง dense layer ที่รับ input node 2 node และให้ output 1 node

TensorFlow เบื้องต้นใน Python

แนวทางระดับสูงเทียบกับระดับต่ำ

  • แนวทางระดับสูง (High-level)
    • การดำเนินการผ่าน High-level API
dense = keras.layers.Dense(10,\
 activation='sigmoid')
  • แนวทางระดับต่ำ (Low-level)
    • การดำเนินการเชิงพีชคณิตเชิงเส้น
prod = matmul(inputs, weights)
dense = keras.activations.sigmoid(prod)
TensorFlow เบื้องต้นใน Python

มาฝึกกันเถอะ!

TensorFlow เบื้องต้นใน Python

Preparing Video For Download...