submitted.pynumpy. No torch or cv2 ECE448_MP07_Instructions.ipynb contains step-by-step instructions for completing the Assignment.
python grade.py to evaluate code locally. In this assignment, you will build a computer vision pipeline from scratch. Similar to the well-known puzzle "Where is Waldo?", we will search for specific patterns within an image. For this simplified version, we will focus on identifying blobs and bars rather than Waldo's canonical red-and-white stripes.
You will start by implementing the fundamental mathematics of convolution, apply those operations to detect geometric patterns, explore gradient-based edge detection, and finally "train" a filter to recognize patterns automatically using gradient descent.
When finding a match between a pattern (kernel) and an image, we use two primary operations. While they are similar, the distinction is crucial for formal signal processing.
In this assignment, we use "Valid" padding. This means:
The output dimensions are calculated as:
$$ H_{out} = H_{in} - K_h + 1 $$ $$ W_{out} = W_{in} - K_w + 1 $$correlation2d(image, kernel)convolve2d(image, kernel)correlation2d function.Computers "see" features by scanning for regions with high mathematical response to specific kernels.
detect_blob(image, k=5)detect_bar(image, k=7)Gradient filters measure the rate of change in pixel intensities to find edges.
detect_bar_gradient(image, scale=2)Implement a 3x3 horizontal gradient filter. Two most popular in this cathegory are Sobel and Prewitt. The main difference between these filters is the weight assigned to the central row or column.
scale=1, this is a Prewitt filter.scale=2, this is a Sobel filter.Modern AI doesn't rely on human-designed filters. Instead, kernels are "learned" from data. You will implement a simplified training loop to find a \(3 \times 3\) kernel that can distinguish a Blob (Label 1) from a Bar (Label 0).
SGD is an optimization algorithm that iteratively updates model parameters (weights) by calculating the gradient of the loss function for a single training example at a time.
train_classifiermax).convolve2d flips the kernel 180° in the forward pass, your backpropagation
must account for this.
Multi-Max Handling: If multiple locations share the exact same maximum response, calculate the gradient for ALL of them and average the result.