Implement a configuration-driven VGG feature extractor in NHWC layout. Each integer entry applies the next supplied same-padded convolution and bias followed by ReLU. Each M entry applies non-overlapping 2 by 2 max pooling. Return the final features as a float64 NumPy array.
Examples
Input: x = [[[[1],[2]],[[3],[4]]]], config = [1,"M"], kernels = [[[[[2]]]]], biases = [[-1]]
Output: [[[[7]]]]
Explanation: The integer entry applies a convolution and ReLU before M pools the resulting spatial grid.
Input: x = [[[[1,-1]]]], config = [2,1], kernels = [[[[[1,0],[0.5,1]]]],[[[[0.5],[2]]]]], biases = [[0,0.1],[-0.2]]
Output: [[[[0.05]]]]
Input: x = [[[[1],[-1]],[[2],[0]]]], config = [1,"M"], kernels = [[[[[1]]]]], biases = [[0.5]]
Output: [[[[2.5]]]]
Hint 1
Keep a separate index for kernels because M consumes no weights.
Hint 2
Reuse the same convolution operation for every integer entry.
Hint 3
Apply max pooling immediately when M is encountered.
Requirements
- Use NumPy.
- Consume one kernel and bias for each integer entry.
- Apply same-padded convolution and ReLU for integer entries.
- Apply 2 by 2 max pooling for M entries.
- Return a float64 NumPy array.
Constraints
- x uses NHWC layout and dtype float64.
- config contains positive integers and M strings.
- kernels and biases contain one compatible pair per integer entry.
- Spatial dimensions are even whenever pooling occurs.
- Every supplied numeric array has dtype float64.
All steps in VGG
Accepts: array
Accepts: array
Accepts: array
Accepts: array
VGG Feature Extractor
Implement a configuration-driven VGG feature extractor in NHWC layout. Each integer entry applies the next supplied same-padded convolution and bias followed by ReLU. Each M entry applies non-overlapping 2 by 2 max pooling. Return the final features as a float64 NumPy array.
Examples
Input: x = [[[[1],[2]],[[3],[4]]]], config = [1,"M"], kernels = [[[[[2]]]]], biases = [[-1]]
Output: [[[[7]]]]
Explanation: The integer entry applies a convolution and ReLU before M pools the resulting spatial grid.
Input: x = [[[[1,-1]]]], config = [2,1], kernels = [[[[[1,0],[0.5,1]]]],[[[[0.5],[2]]]]], biases = [[0,0.1],[-0.2]]
Output: [[[[0.05]]]]
Input: x = [[[[1],[-1]],[[2],[0]]]], config = [1,"M"], kernels = [[[[[1]]]]], biases = [[0.5]]
Output: [[[[2.5]]]]
Hint 1
Keep a separate index for kernels because M consumes no weights.
Hint 2
Reuse the same convolution operation for every integer entry.
Hint 3
Apply max pooling immediately when M is encountered.
Requirements
- Use NumPy.
- Consume one kernel and bias for each integer entry.
- Apply same-padded convolution and ReLU for integer entries.
- Apply 2 by 2 max pooling for M entries.
- Return a float64 NumPy array.
Constraints
- x uses NHWC layout and dtype float64.
- config contains positive integers and M strings.
- kernels and biases contain one compatible pair per integer entry.
- Spatial dimensions are even whenever pooling occurs.
- Every supplied numeric array has dtype float64.
All steps in VGG
Accepts: array
Accepts: array
Accepts: array
Accepts: array