Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้ TensorFlow สร้าง Convolutional Network 1 มิติ ด้วย Python


TensorFlow เฟรมเวิร์ก ML จาก Google Open Source ใช้กับ Python อัลกอริทึม Deep Learning งานวิจัยและ Production มีเทคนิคเพิ่มประสิทธิภาพคำนวณ ใช้ NumPy และ Multi-dimensional Arrays (Tensors) รองรับ Deep Neural Networks สเกลได้ดี มี Dataset ยอดนิยม ใช้ GPU Computation จัดการ Resource อัตโนมัติ มี Library ML มากมาย รองรับเอกสารดี รัน โมเดล Deep Neural Network ฝึกและสร้าง Application ทำนายลักษณะข้อมูลได้

ติดตั้ง tensorflow บน Windows:

pip install tensorflow

Tensor โครงสร้างข้อมูลใน TensorFlow (Data Flow Graph) เป็นอาร์เรย์หลายมิติ/ลิสต์

ใช้ Google Colab รันโค้ด (Python บนเบราว์เซอร์ ฟรี GPU บน Jupyter Notebook)

ตัวอย่างโค้ด

print("Defining the function to build a one dimensional convolutional network")
def create_model(vocab_size, num_labels):
    model = tf.keras.Sequential([
        layers.Embedding(vocab_size, 64, mask_zero=True),
        layers.Conv1D(64, 5, padding="valid", activation="relu", strides=2),
        layers.GlobalMaxPooling1D(),
        layers.Dense(num_labels)
    ])
    return model

Credit: TensorFlow Tutorials

ผลลัพธ์

Defining the function to build a one dimensional convolutional network

คำอธิบาย

  • ใช้ Int Vectorized Model สร้าง 1D CNN

  • สร้างด้วย Sequential API