File size: 3,281 Bytes
8a073aa
 
15637df
 
 
 
562e6ef
8a073aa
c839a9a
ee248fd
 
9f99290
ee248fd
 
 
 
 
 
 
 
 
 
 
 
 
820c1ec
ee248fd
 
 
 
 
 
 
 
 
 
 
 
 
 
ecc64f1
9f99290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee248fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c839a9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
library_name: keras-hub
license: bsd-3-clause
tags:
- image-classification
- keras
pipeline_tag: image-classification
---
### Model Overview
DenseNet is a convolution network which densely connects each layer to every other layer in a feed-forward fashion. The model was originally evaluated on four object recognition benchmark tasks (CIFAR-10, CIFAR-100, SVHN, and ImageNet). See the model card below for benchmarks, data sources, and intended use cases. This model is supported in both KerasCV and KerasHub. KerasCV will no longer be actively developed, so please try to use KerasHub.

Weights are released under the [3-Clause BSD License](https://github.com/liuzhuang13/DenseNet/blob/master/LICENSE). Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).

## Links

* [DenseNet Quickstart Notebook: coming soon]()
* [DenseNet API Documentation](https://keras.io/api/keras_hub/models/densnet/)
* [DenseNet Model Card](https://github.com/liuzhuang13/DenseNet)

## Installation

Keras and KerasHub can be installed with:

```
pip install -U -q keras-hub
pip install -U -q keras>=3
```

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: https://huggingface.co/timm. Full code examples for each are available below.

| Preset name           | Parameters | Description   |
|-----------------------|------------|---------------|
| `densenet_121_imagenet` | 7037504 | DenseNet model with 121 layers. Trained on Imagenet 2012 classification task. |
| `densenet_169_imagenet` | 12642880 | DenseNet model with 169 layers. Trained on Imagenet 2012 classification task. |
| `densenet_201_imagenet` | 18321984 | DenseNet model with 201 layers. Trained on Imagenet 2012 classification task. |

## Example Usage
```python
input_data = np.ones(shape=(8, 224, 224, 3))

# Pretrained backbone
model = keras_hub.models.DenseNetBackbone.from_preset("densenet_121_imagenet")
model(input_data)

# Randomly initialized backbone with a custom config
model = keras_hub.models.DenseNetBackbone(
    stackwise_num_repeats=[6, 12, 24, 16],
)
model(input_data)

# Use densenet for image classification task
model = keras_hub.models.ImageClassifier.from_preset("densenet_121_imagenet")

# User Timm presets directly from HuggingFace
model = keras_hub.models.ImageClassifier.from_preset('hf://timm/densenet121.tv_in1k')
```

## Example Usage with Hugging Face URI

```python
input_data = np.ones(shape=(8, 224, 224, 3))

# Pretrained backbone
model = keras_hub.models.DenseNetBackbone.from_preset("hf://keras/densenet_121_imagenet")
model(input_data)

# Randomly initialized backbone with a custom config
model = keras_hub.models.DenseNetBackbone(
    stackwise_num_repeats=[6, 12, 24, 16],
)
model(input_data)

# Use densenet for image classification task
model = keras_hub.models.ImageClassifier.from_preset("hf://keras/densenet_121_imagenet")

# User Timm presets directly from HuggingFace
model = keras_hub.models.ImageClassifier.from_preset('hf://timm/densenet121.tv_in1k')
```