#126The classifier head — FC + softmaxMediumCNNComputer VisionActivation Functions
The classifier head — FC + softmax
Background
After the conv stack, a CNN flattens the features and runs a fully-connected layer followed by softmax to produce class probabilities, then predicts the top class:
Problem statement
Implement classify_head(features, W, b) returning (label, probs).
Input
features— array-like of lengthD, the flattened feature vector.W— array-like of shape(D, K), the FC weight matrix (Kclasses).b— array-like of lengthK, the bias.
Output
Returns (label, probs): label is the int predicted class; probs is an np.ndarray of K probabilities summing to 1.
Examples
Example 1
Input: features = [1, 0], W = [[2, 0], [0, 2]], b = [0, 0]
Output: label = 0, probs ≈ [0.8808, 0.1192]
Explanation: logits ; softmax ; argmax is class 0.
Constraints
- Compute logits
features @ W + b, softmax (numerically stable), then argmax. - Return
(int label, np.ndarray probs)withprobssumming to 1.
Notes
- Subtract the max logit before exponentiating to avoid overflow — the standard stable softmax.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example: two-class head probabilities
- •Reference: predicted label when other class wins
- •Sample: three-class probabilities