A fully serializable 3D implementation of ResNet18, incorporating improvements from the paper "Bag of Tricks for Image Classification with Convolutional Neural Networks" along with additional personal optimizations and modifications.
This repository also includes implementations of the Hardswish and Mish activation functions:
The codebase is fully integratable inside the TensorFlow and Keras code pipelines.
- Modified Stem: Utilizes three convolutional layers instead of a single one.
- ResNet-B Inspired Strides: Moved the stride placement in the residual blocks from the first convolution to the second.
- ResNet-D Inspired Shortcut: Introduces an average pooling layer before the 1x1 convolution in the shortcut connection.
- Reduced Downsampling: The temporal dimension is now downsampled only twice in the stem block, while the spatial dimension follows the original approach, undergoing downsampling five times.
Note: The images above represent the architectural modifications. They depict 2D convolutional layers, whereas this project is focused on 3D convolutions. The ResNet-C image is sourced from the referenced paper, while the shortcut image is created by the author.
This code is compatible with Python 3.12.8 and TensorFlow 2.18.0.
from ResNet183DD import ResNet183DD
model = ResNet183DD(1000)
model.build((None, 32, 256, 256, 3))
model.summary()Model: "res_net183dd"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ conv3d_layer (Conv3DLayer) │ (None, 16, 128, 128, 32) │ 2,592 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv3d_layer_1 (Conv3DLayer) │ (None, 16, 128, 128, 32) │ 27,648 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ conv3d_layer_2 (Conv3DLayer) │ (None, 16, 128, 128, 64) │ 55,296 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ max_pooling3d (MaxPooling3D) │ (None, 8, 64, 64, 64) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd (Residual3DD) │ (None, 8, 64, 64, 64) │ 221,184 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_1 (Residual3DD) │ (None, 8, 32, 32, 128) │ 671,744 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_2 (Residual3DD) │ (None, 8, 32, 32, 128) │ 884,736 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_3 (Residual3DD) │ (None, 8, 16, 32, 256) │ 2,686,976 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_4 (Residual3DD) │ (None, 8, 16, 32, 256) │ 3,538,944 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_5 (Residual3DD) │ (None, 8, 8, 16, 512) │ 10,747,904 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ residual3dd_6 (Residual3DD) │ (None, 8, 8, 16, 512) │ 14,155,776 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ global_average_pooling3d │ (None, 512) │ 0 │
│ (GlobalAveragePooling3D) │ │ │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ dense (Dense) │ (None, 256) │ 131,328 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
Total params: 33,124,128 (126.36 MB)
Trainable params: 33,124,128 (126.36 MB)
Non-trainable params: 0 (0.00 B)This work is under an MIT License.

