|
--- |
|
library_name: keras-hub |
|
license: apache-2.0 |
|
tags: |
|
- image-classification |
|
pipeline_tag: image-classification |
|
--- |
|
### Model Overview |
|
# Model Summary |
|
|
|
Instantiates the ResNet architecture amended by “bag of tricks” modifications. |
|
## Reference |
|
[Bag of Tricks for Image Classification with Convolutional Neural Networks](https://arxiv.org/abs/1812.01187) |
|
|
|
ResNetVd introduces two key modifications to the standard ResNet. First, the initial convolutional layer is replaced by a series of three successive convolutional layers. Second, shortcut connections use an additional pooling operation rather than performing downsampling within the convolutional layers themselves. |
|
## Links |
|
|
|
* [ResNetVD Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/resnetvd-quickstart-notebook) |
|
* [ResNet and ResNetVD series Doc](https://paddleclas.readthedocs.io/en/latest/models/ResNet_and_vd_en.html) |
|
* [ResNetVD Model Card](https://arxiv.org/abs/1812.01187) |
|
* [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/) |
|
* [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/) |
|
|
|
## Installation |
|
|
|
Keras and KerasHub can be installed with: |
|
|
|
``` |
|
pip install -U -q keras-hub |
|
pip install -U -q keras |
|
``` |
|
|
|
Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page. |
|
|
|
## Presets |
|
|
|
The following model checkpoints are provided by the Keras team.Weights have been ported from: [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR). Full code examples for each are available below. |
|
|
|
|
|
| Preset name | Parameters | Description | |
|
|------------------------|------------|-------------------------------------------------------------------------------------------------| |
|
| `resnet_vd_18_imagenet` | 11.72M | 18-layer ResNetVD model pre-trained on the ImageNet 1k dataset at a 224x224 resolution.| |
|
| `resnet_vd_34_imagenet` | 21.84M | 34-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. | |
|
| `resnet_vd_50_imagenet` | 25.63M | 50-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. | |
|
| `resnet_vd_50_ssld_imagenet` | 25.63M | 50-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution with knowledge distillation. | |
|
| `resnet_vd_50_ssld_v2_imagenet` | 25.63M | 50-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution with knowledge distillation and AutoAugment. | |
|
| `resnet_vd_50_ssld_v2_fix_imagenet` | 25.63M | 50-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution with knowledge distillation, AutoAugment and additional fine-tuning of the classification head. | |
|
| `resnet_vd_101_imagenet` | 44.67M | 101-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. | |
|
| `resnet_vd_101_ssld_imagenet` | 44.67M | 101-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution with knowledge distillation. | |
|
| `resnet_vd_152_imagenet` | 60.36M | 152-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. | |
|
| `resnet_vd_200_imagenet` | 74.93M | 200-layer ResNet model pre-trained on the ImageNet 1k dataset at a 224x224 resolution. | |
|
|
|
## Example Usage |
|
```python |
|
|
|
from keras_hub.models import ResNetBackbone |
|
import keras |
|
import numpy as np |
|
|
|
input_data = np.ones(shape=(8, 224, 224, 3)) |
|
|
|
# Pretrained backbone |
|
model = ResNetBackbone.from_preset("resnet_vd_18_imagenet") |
|
output = model(input_data) |
|
|
|
# Randomly initialized backbone with a custom config |
|
model = ResNetBackbone( |
|
input_conv_filters=[32, 32, 64], |
|
input_conv_kernel_sizes=[3, 3, 3], |
|
stackwise_num_filters=[64, 128, 256, 512], |
|
stackwise_num_blocks=[3, 4, 5, 6], |
|
stackwise_num_strides=[1, 2, 2, 2], |
|
block_type="bottleneck_block_vd", |
|
) |
|
output = model(input_data) |
|
|
|
``` |
|
|
|
## Example Usage with Hugging Face URI |
|
|
|
```python |
|
|
|
from keras_hub.models import ResNetBackbone |
|
import keras |
|
import numpy as np |
|
|
|
input_data = np.ones(shape=(8, 224, 224, 3)) |
|
|
|
# Pretrained backbone |
|
model = ResNetBackbone.from_preset("hf://keras/resnet_vd_18_imagenet") |
|
output = model(input_data) |
|
|
|
# Randomly initialized backbone with a custom config |
|
model = ResNetBackbone( |
|
input_conv_filters=[32, 32, 64], |
|
input_conv_kernel_sizes=[3, 3, 3], |
|
stackwise_num_filters=[64, 128, 256, 512], |
|
stackwise_num_blocks=[3, 4, 5, 6], |
|
stackwise_num_strides=[1, 2, 2, 2], |
|
block_type="bottleneck_block_vd", |
|
) |
|
output = model(input_data) |
|
|
|
``` |
|
|