Sequential Model เกี่ยวข้องเมื่อมี Stack ของ Layers แบบเรียบง่าย ใน Stack นี้ ทุก Layer มี Input Tensor เพียงหนึ่งและ Output Tensor เพียงหนึ่ง มันไม่เหมาะสมเมื่อ Model มี Multiple Inputs หรือ Multiple Outputs ไม่เหมาะสมเมื่อ Layers ต้องการ Share ไม่เหมาะสมเมื่อ Layer มี Multiple Inputs หรือ Multiple Outputs ไม่เหมาะสมเมื่อต้องการ Non-linear Architecture
Tensorflow เป็นเฟรมเวิร์ก Machine Learning ที่ Google มอบให้ เป็นเฟรมเวิร์ก Open Source ที่ใช้ร่วมกับ Python เพื่อนำอัลกอริทึม Deep Learning Applications และอื่นๆ ไปใช้งาน ใช้ทั้งในการวิจัยและการผลิต มีเทคนิค Optimization ที่ช่วยทำการดำเนินการทางคณิตศาสตร์ที่ซับซ้อนได้อย่างรวดเร็ว เนื่องจากมันใช้ NumPy และ Multi-dimensional Arrays Arrays หลายมิตินี้ cònเรียกว่า 'Tensors'
Keras ถูกพัฒนาขึ้นเป็นส่วนหนึ่งของการวิจัยโครงการ ONEIROS (Open ended Neuro-Electronic Intelligent Robot Operating System) Keras เป็น Deep Learning API ที่เขียนด้วย Python เป็น High-level API ที่有产品化 Interface ช่วยแก้ปัญหา Machine Learning ได้อย่าง有ประสิทธิภาพ มันรันบน Tensorflow Framework ถูกสร้างขึ้นเพื่อช่วยให้ทดลองได้อย่างรวดเร็ว มีความสามารถในการ Scale สูง และมีความสามารถ Cross-platform หมายความว่า Keras รันบน TPU หรือ Cluster ของ GPUs ได้ โมเดล Keras ยังสามารถ Export ไปรันบน Web Browser หรือ Mobile Phone ได้อีกด้วย
Keras อยู่ภายในแพ็กเกจ Tensorflow แล้ว สามารถเข้าถึงได้ด้วยโค้ดด้านล่าง
import tensorflow from tensorflow import keras
เราใช้ Google Colaboratory รันโค้ดด้านล่าง Google Colab ช่วยรัน Python Code บนเบราว์เซอร์ ต้องการการตั้งค่าศูนย์ และเข้าถึง GPU ฟรี Colaboratory สร้างบน Jupyter Notebook
มาดูตัวอย่างการกำหนด Sequential Model ด้วย Tensorflow รวมถึง Keras
ตัวอย่าง
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
print("A sequential model is being defined, that has three layers")
model = keras.Sequential(
[
layers.Dense(2, activation="relu", name="layer_1"),
layers.Dense(3, activation="relu", name="layer_2"),
layers.Dense(4, name="layer_3"),
]
)
print("The model is being called on test data")
x = tf.ones((2, 2))
y = model(x)
Code credit - https://www.tensorflow.org/guide/keras/sequential_model
ผลลัพธ์

A sequenital model is being defined, that has three layers The model is being called on test data The layers are [, , ]
คำอธิบาย
Import แพ็กเกจที่จำเป็นและตั้ง Alias
สร้าง Sequential Model ด้วยเมธอด 'sequential' ใน Keras
Model นี้ถูกเรียกใช้กับ Test Data
รายละเอียดเกี่ยวกับ Layers ของ Model แสดงบน Console