Model Pipeline - Training an image classifier
This pipeline trains a model to recognize images by learning from labeled pictures. It starts with raw images, processes them, trains a neural network, and then predicts the image category.
Jump into concepts and practice - no test required
This pipeline trains a model to recognize images by learning from labeled pictures. It starts with raw images, processes them, trains a neural network, and then predicts the image category.
Epoch 1: ************ (loss=1.2) Epoch 2: ********* (loss=0.9) Epoch 3: ******* (loss=0.7) Epoch 4: ***** (loss=0.5) Epoch 5: **** (loss=0.4)
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.55 | Model starts learning basic patterns |
| 2 | 0.9 | 0.68 | Accuracy improves as model adjusts weights |
| 3 | 0.7 | 0.75 | Model captures more complex features |
| 4 | 0.5 | 0.82 | Loss decreases steadily, accuracy rises |
| 5 | 0.4 | 0.87 | Model converges with good accuracy |
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(64, 64, 3))) [OK]import tensorflow as tf
from tensorflow.keras import layers, models
model = models.Sequential([
layers.Conv2D(16, (3,3), activation='relu', input_shape=(28,28,1)),
layers.Flatten(),
layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
import numpy as np
x_train = np.random.random((100, 28, 28, 1))
y_train = np.random.randint(0, 10, 100)
history = model.fit(x_train, y_train, epochs=1, verbose=0)
print(f"Accuracy: {history.history['accuracy'][0]:.2f}")model = tf.keras.Sequential() model.add(tf.keras.layers.Conv2D(32, 3, activation='relu')) model.add(tf.keras.layers.Flatten()) model.add(tf.keras.layers.Dense(10, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5)
x_train shape is (100, 28, 28, 1).