การกำหนดโครงข่ายประสาทเทียมด้วย Keras

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

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

การจำแนกตัวอักษรภาษามือ

ภาพนี้แสดงตัวอักษรภาษามือ A

ภาพนี้แสดงตัวอักษรภาษามือ B

ภาพนี้แสดงตัวอักษรภาษามือ C

ภาพนี้แสดงตัวอักษรภาษามือ D

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

Sequential API

ภาพแสดงโครงข่ายประสาทเทียมที่มี 16 โหนดในเลเยอร์ซ่อนแรก 8 โหนดในเลเยอร์ที่สอง และ 4 โหนดในเลเยอร์เอาต์พุต

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

Sequential API

  • เลเยอร์อินพุต
  • เลเยอร์ซ่อน
  • เลเยอร์เอาต์พุต
  • เรียงตามลำดับ
TensorFlow เบื้องต้นใน Python

การสร้างโมเดลแบบ Sequential

# Import tensorflow
from tensorflow import keras

# Define a sequential model
model = keras.Sequential()
# Define first hidden layer
model.add(keras.layers.Dense(16, activation='relu', input_shape=(28*28,)))
TensorFlow เบื้องต้นใน Python

การสร้างโมเดลแบบ Sequential

# Define second hidden layer
model.add(keras.layers.Dense(8, activation='relu'))
# Define output layer
model.add(keras.layers.Dense(4, activation='softmax'))
# Compile the model
model.compile('adam', loss='categorical_crossentropy')
# Summarize the model
print(model.summary())
TensorFlow เบื้องต้นใน Python

Functional API

ภาพแสดงโครงข่ายประสาทเทียมที่มีอินพุตสองชุด

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

การใช้งาน Functional API

# Import tensorflow
import tensorflow as tf

# Define model 1 input layer shape
model1_inputs = tf.keras.Input(shape=(28*28,))

# Define model 2 input layer shape
model2_inputs = tf.keras.Input(shape=(10,))
# Define layer 1 for model 1
model1_layer1 = tf.keras.layers.Dense(12, activation='relu')(model1_inputs)

# Define layer 2 for model 1
model1_layer2 = tf.keras.layers.Dense(4, activation='softmax')(model1_layer1)
TensorFlow เบื้องต้นใน Python

การใช้งาน Functional API

# Define layer 1 for model 2
model2_layer1 = tf.keras.layers.Dense(8, activation='relu')(model2_inputs)

# Define layer 2 for model 2
model2_layer2 = tf.keras.layers.Dense(4, activation='softmax')(model2_layer1)
# Merge model 1 and model 2
merged = tf.keras.layers.add([model1_layer2, model2_layer2])
# Define a functional model
model = tf.keras.Model(inputs=[model1_inputs, model2_inputs], outputs=merged)

# Compile the model
model.compile('adam', loss='categorical_crossentropy')
TensorFlow เบื้องต้นใน Python

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

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

Preparing Video For Download...