บทนำ
TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต มีเทคนิคเพิ่มประสิทธิภาพ ใช้ NumPy และเทนเซอร์ รองรับ Deep Neural Networks สเกลได้ดี ใช้ GPU computation จัดการทรัพยากรอัตโนมัติ มีไลบรารี ML มากมาย เอกสารดี
การติดตั้ง
pip install tensorflow
คุณสมบัติ Tensor
- Rank - มิติของเทนเซอร์
- Type - ชนิดข้อมูลองค์ประกอบ
- Shape - ขนาดแถวและคอลัมน์
Hello World ของ TensorFlow
รันบน Jupyter Notebook ติดตั้งด้วย pip install tensorflow
ตัวอย่าง: สร้าง Constant Tensor
import tensorflow as tf
hello = tf.constant("hello there")
print(hello)
print(hello.numpy())
ผลลัพธ์
tf.Tensor(b'hello there', shape=(), dtype=string) b'hello there'
คำอธิบาย
- นำเข้า TensorFlow และตั้งชื่อย่อ tf
- สร้างค่าคงที่ (constant) ด้วย
tf.constantเก็บในตัวแปร - พิมพ์ tensor object (แสดง shape, dtype)
- ใช้
.numpy()แปลงเป็น NumPy array เพื่อดูค่าจริง