Track channel width through DenseNet blocks and transition layers. A dense block with n layers adds nK channels, where K is the growth rate. Every transition except the final block boundary compresses its input by factor θ.
Cblock=Cin+nK Ctransition=⌊θCblock⌋Here, stem_channels is the initial width, block_layers lists the number of layers in each block, and compression is θ. Return an int64 PyTorch tensor containing the stem width, every block output width, and every intervening transition output width in execution order. For B blocks, the tensor has length 2B.
Examples
Input: stem_channels = 24, growth_rate = 12, block_layers = [6,12], compression = 0.5
Output: [24,96,48,192]
Explanation: The first block adds 72 channels, the transition halves 96 to 48, and the second block adds 144 channels.
Input: stem_channels = 16, growth_rate = 8, block_layers = [2,2,2], compression = 1
Output: [16,32,32,48,48,64]
Input: stem_channels = 32, growth_rate = 16, block_layers = [4], compression = 0.5
Output: [32,96]
Hint 1
Start the result with stem_channels and update one running channel count.
Hint 2
Use math.floor after each block except the final block.
Requirements
- Use PyTorch.
- Add the growth contributed by every dense block.
- Apply compression only between blocks and round it down.
- Return every stage width in execution order as an int64 tensor.
Constraints
- stem_channels and growth_rate are positive integers.
- block_layers contains between one and five positive integers.
- compression is greater than zero and at most one.
- The return tensor has shape (2B), where B is the number of blocks.
All steps in DenseNet
Accepts: number
Accepts: number
Accepts: array
Accepts: number
Channel Growth
Track channel width through DenseNet blocks and transition layers. A dense block with n layers adds nK channels, where K is the growth rate. Every transition except the final block boundary compresses its input by factor θ.
Cblock=Cin+nK Ctransition=⌊θCblock⌋Here, stem_channels is the initial width, block_layers lists the number of layers in each block, and compression is θ. Return an int64 PyTorch tensor containing the stem width, every block output width, and every intervening transition output width in execution order. For B blocks, the tensor has length 2B.
Examples
Input: stem_channels = 24, growth_rate = 12, block_layers = [6,12], compression = 0.5
Output: [24,96,48,192]
Explanation: The first block adds 72 channels, the transition halves 96 to 48, and the second block adds 144 channels.
Input: stem_channels = 16, growth_rate = 8, block_layers = [2,2,2], compression = 1
Output: [16,32,32,48,48,64]
Input: stem_channels = 32, growth_rate = 16, block_layers = [4], compression = 0.5
Output: [32,96]
Hint 1
Start the result with stem_channels and update one running channel count.
Hint 2
Use math.floor after each block except the final block.
Requirements
- Use PyTorch.
- Add the growth contributed by every dense block.
- Apply compression only between blocks and round it down.
- Return every stage width in execution order as an int64 tensor.
Constraints
- stem_channels and growth_rate are positive integers.
- block_layers contains between one and five positive integers.
- compression is greater than zero and at most one.
- The return tensor has shape (2B), where B is the number of blocks.
All steps in DenseNet
Accepts: number
Accepts: number
Accepts: array
Accepts: number