Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Huấn luyện mô hình Fashion MNIST với TensorFlow


TensorFlow (Google) framework học máy mã nguồn mở. Cài đặt: pip install tensorflow. Tensor: mảng đa chiều.

Fashion MNIST: >70.000 ảnh grayscale trang phục 10 loại, 28x28 pixel.

Chạy trên Google Colab (Python trên trình duyệt, GPU miễn phí).

Ví dụ

print("Fit mô hình vào dữ liệu")
model.fit(train_images, train_labels, epochs=15)

print("Tính độ chính xác")
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print('\nĐộ chính xác test:', test_acc)

Nguồn mã: TensorFlow Classification Tutorial

Đầu ra

Fit mô hình vào dữ liệu
Epoch 1/15 - loss: 0.6337 - accuracy: 0.7799
Epoch 2/15 - loss: 0.3806 - accuracy: 0.8622
Epoch 3/15 - loss: 0.3469 - accuracy: 0.8738
Epoch 4/15 - loss: 0.3131 - accuracy: 0.8853
Epoch 5/15 - loss: 0.2962 - accuracy: 0.8918
Epoch 6/15 - loss: 0.2875 - accuracy: 0.8935
Epoch 7/15 - loss: 0.2705 - accuracy: 0.8998
Epoch 8/15 - loss: 0.2569 - accuracy: 0.9023
Epoch 9/15 - loss: 0.2465 - accuracy: 0.9060
Epoch 10/15 - loss: 0.2440 - accuracy: 0.9088
Epoch 11/15 - loss: 0.2300 - accuracy: 0.9143
Epoch 12/15 - loss: 0.2255 - accuracy: 0.9152
Epoch 13/15 - loss: 0.2114 - accuracy: 0.9203
Epoch 14/15 - loss: 0.2101 - accuracy: 0.9211
Epoch 15/15 - loss: 0.2057 - accuracy: 0.9224
Tính độ chính xác
313/313 - loss: 0.3528 - accuracy: 0.8806
Độ chính xác test: 0.8805999755859375

Giải thích

  • Huấn luyện bằng fit() với train_images, train_labels (mảng đầu vào).
  • Mô hình học ánh xạ ảnh → nhãn.
  • test_images lưu dữ liệu test.
  • So khớp dự đoán với nhãn thực tế của test set.
  • model.fit() fit mô hình vào tập train.
  • model.evaluate() trả về loss và accuracy trên test set.