บทนำ
TensorFlow เฟรมเวิร์ก ML จาก Google โค้ดเปิด ใช้กับ Python ใช้ในงานวิจัยและการผลิต
การติดตั้ง
pip install tensorflow
ชุดข้อมูล Fashion MNIST
ภาพเสื้อผ้า 70,000+ ภาพ Grayscale 10 หมวดหมู่ 28x28 pixels
ตัวอย่าง: โหลดข้อมูลและแสดงข้อมูลสถิติ
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
print("TensorFlow version:")
print(tf.__version__)
print("กำลังโหลดชุดข้อมูล")
fashion_mnist = tf.keras.datasets.fashion_mnist
print("แบ่งข้อมูล Train/Test")
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
print("มิติข้อมูลฝึก:")
print(train_images.shape)
print("จำนวนแถวข้อมูลฝึก:")
print(len(train_labels))
print("ป้ายกำกับข้อมูลฝึก:")
print(train_labels)
print("มิติข้อมูลทดสอบ:")
print(test_images.shape)
print("จำนวนแถวข้อมูลทดสอบ:")
print(len(test_labels))
ที่มาโค้ด: TensorFlow Classification Tutorial
ผลลัพธ์
TensorFlow version: 2.4.0 กำลังโหลดชุดข้อมูล แบ่งข้อมูล Train/Test Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz ... Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz ... Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz ... Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz ... มิติข้อมูลฝึก: (60000, 28, 28) จำนวนแถวข้อมูลฝึก: 60000 ป้ายกำกับข้อมูลฝึก: [9 0 0 ... 3 0 5] มิติข้อมูลทดสอบ: (10000, 28, 28) จำนวนแถวข้อมูลทดสอบ: 10000
คำอธิบาย
- นำเข้าแพ็กเกจที่จำเป็น
- ตรวจสอบเวอร์ชัน TensorFlow
- โหลด Fashion MNIST จาก tf.keras.datasets
- แบ่งข้อมูล Train/Test: 60,000 ตัวอย่างฝึก, 10,000 ตัวอย่างทดสอบ
- เป็นปัญหา Classification: ภาพแต่ละภาพมีป้ายกำกับเฉพาะ
- แสดง shape, จำนวนแถว, และตัวอย่างป้ายกำกับ