TensorFlow เป็นเฟรมเวิร์กการเรียนรู้ของเครื่องที่ Google จัดให้ เป็นเฟรมเวิร์กโอเพนซอร์สที่ใช้ร่วมกับ Python เพื่อนำอัลกอริทึม การเรียนรู้เชิงลึก และอื่นๆ มาใช้งาน ใช้ทั้งในงานวิจัยและการผลิต
มีเทคนิคการเพิ่มประสิทธิภาพช่วยดำเนินการทางคณิตศาสตร์ที่ซับซ้อนได้อย่างรวดเร็ว
แพ็กเกจ 'tensorflow' สามารถติดตั้งบน Windows ได้ด้วยคำสั่งด้านล่าง:
pip install tensorflow
Tensor คือโครงสร้างข้อมูลที่ใช้ใน TensorFlow ช่วยเชื่อมต่อขอบในแผนภาพกระแสข้อมูล (Data flow graph) Tensor คืออาร์เรย์หลายมิติหรือรายการ
Keras ถูกพัฒนาขึ้นเป็นส่วนหนึ่งของโครงการวิจัย ONEIROS (Open ended Neuro-Electronic Intelligent Robot Operating System) Keras เป็น API การเรียนรู้เชิงลึก ที่เขียนด้วย Python เป็น API ระดับสูงที่มีอินเทอร์เฟซที่มีประสิทธิภาพช่วยแก้ปัญหาการเรียนรู้ของเครื่อง
มีความสามารถในการขยายตัวสูง และรองรับ cross-platform หมายความว่า Keras รันบน TPU หรือ叢集ของ GPUs ได้ โมเดล Keras ยังสามารถส่งออกเพื่อรันบนเว็บเบราว์เซอร์หรือโทรศัพท์มือถือได้อีกด้วย
Keras อยู่ภายในแพ็กเกจ TensorFlow แล้ว สามารถเข้าถึงได้ด้วยโค้ดด้านล่าง:
import tensorflow from tensorflow import keras
เราใช้ Google Colaboratory เพื่อรันโค้ดด้านล่าง Google Colab ช่วยให้รันโค้ด Python ผ่านเบราว์เซอร์ ไม่ต้องตั้งค่า และเข้าถึง GPU ฟรี Colaboratory สร้างขึ้นบน Jupyter Notebook
โค้ดมีดังนี้:
ตัวอย่าง
checkpoint_path = "training_2/cp-{epoch:04d}.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
batch_size = 32
print("Callback being created to save the model's weight after every 4 epoch")
cp_callback = tf.keras.callbacks.ModelCheckpoint(
filepath=checkpoint_path,
verbose=1,
save_weights_only=True,
save_freq=4*batch_size)
print("A new model instance is created")
model = create_model()
print("The weights are saved using 'checkpoint_path'")
model.save_weights(checkpoint_path.format(epoch=0))
Code credit - https://www.tensorflow.org/tutorials/keras/save_and_load
ผลลัพธ์
Callback being created to save the model's weight after every 4 epoch A new model instance is created The weight are saved using 'checkpoint_path'
คำอธิบาย
Callback มีตัวเลือกมากมาย เช่น การตั้งชื่อ checkpoint ให้เป็นเอกลักษณ์ การปรับความถี่ของ checkpointing ฯลฯ
โมเดลใหม่ถูกฝึก
โมเดลใหม่นี้ถูกบันทึกด้วยชื่อเฉพาะสำหรับแต่ละ checkpoint หลังจากทุก 4 epochs