Introduction
We follow a clear step-by-step plan to build computer vision projects so they work well and solve real problems.
Jump into concepts and practice - no test required
We follow a clear step-by-step plan to build computer vision projects so they work well and solve real problems.
1. Define the problem 2. Collect and prepare data 3. Choose or build a model 4. Train the model 5. Evaluate the model 6. Improve and tune the model 7. Deploy the model 8. Monitor and maintain
This is a general workflow, steps may repeat or overlap.
Good data and clear goals make the project easier and better.
1. Problem: Detect cats in photos 2. Data: Gather cat and no-cat images 3. Model: Use a simple CNN 4. Train: Teach model on images 5. Evaluate: Check accuracy 6. Improve: Add more data or layers 7. Deploy: Put model in a phone app 8. Monitor: Watch app performance
1. Problem: Sort fruits by type 2. Data: Collect fruit pictures 3. Model: Use pretrained model like ResNet 4. Train: Fine-tune on fruit data 5. Evaluate: Measure precision and recall 6. Improve: Adjust learning rate 7. Deploy: Use in supermarket scanner 8. Monitor: Update model with new fruits
This program follows the CV project workflow to build a digit classifier using MNIST data.
import tensorflow as tf from tensorflow.keras import layers, models import numpy as np # 1. Define problem: classify digits from images # 2. Load data (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data() # Normalize data x_train, x_test = x_train / 255.0, x_test / 255.0 # 3. Build model model = models.Sequential([ layers.Flatten(input_shape=(28, 28)), layers.Dense(128, activation='relu'), layers.Dense(10, activation='softmax') ]) # 4. Compile model model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # 5. Train model history = model.fit(x_train, y_train, epochs=3, validation_split=0.1, verbose=2) # 6. Evaluate model loss, accuracy = model.evaluate(x_test, y_test, verbose=0) print(f'Test accuracy: {accuracy:.4f}')
Good quality and enough data is key for success.
Start simple, then improve your model step by step.
Always check your model on new data to avoid surprises.
Follow a clear step plan from problem to deployment.
Data preparation and evaluation are very important.
Keep improving and monitoring your model after deployment.
train_test_split with parameter test_size to specify test data fraction.import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Conv2D(16, 3, activation='relu', input_shape=(28,28,1)), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) history = model.fit(x_train, y_train, epochs=1, batch_size=32) print(history.history['accuracy'][0])
history object stores metrics per epoch. Accessing history.history['accuracy'][0] gives training accuracy after first epoch.metrics=['accuracy'] was set, accuracy is recorded and printed as a float between 0 and 1.