File size: 3,700 Bytes
cdc43be
 
 
c512381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
library_name: keras-hub
---
### Model Overview
This class represents the CSPDarkNet architecture.

**Reference**

-  [CSPNet Paper](https://arxiv.org/abs/1911.11929)

For transfer learning use cases, make sure to read the
[guide to transfer learning & fine-tuning](https://keras.io/guides/transfer_learning/).

## Links
* [CSPNet Quickstart Notebook](https://www.kaggle.com/code/prasadsachin/cspnet-quickstart-kerashub)
* [CSPDarkNet API Documentation](https://keras.io/keras_hub/api/models/cspnet/)
* [CSPDarkNet Model Card](https://huggingface.co/timm/cspdarknet53.ra_in1k)
* [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: https://huggingface.co/timm. Full code examples for each are available below.

| Preset name           | Parameters | Description   |
|-----------------------|------------|---------------|
| `csp_darknet_53_ra_imagenet` | 27642184 | A CSP-DarkNet (Cross-Stage-Partial) image classification model pre-trained on the Randomly Augmented ImageNet 1k dataset at a 256x256 resolution.|
| `csp_resnext_50_ra_imagenet` | 20569896 | A CSP-ResNeXt (Cross-Stage-Partial) image classification model pre-trained on the Randomly Augmented ImageNet 1k dataset at a 256x256 resolution.|
| `csp_resnet_50_ra_imagenet` | 21616168 | A CSP-ResNet (Cross-Stage-Partial) image classification model pre-trained on the Randomly Augmented ImageNet 1k dataset at a 256x256 resolution.|
| `darknet_53_imagenet` | 41609928 | A DarkNet image classification model pre-trained on the Randomly Augmented ImageNet 1k dataset at a 256x256 resolution.|

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

# Pretrained backbone
model = keras_hub.models.CSPNetBackbone.from_preset("darknet_53_imagenet")
model(input_data)

# Randomly initialized backbone with a custom config
    model = keras_hub.models.CSPNetBackbone(
        stem_filters=32,
        stem_kernel_size=3,
        stem_strides=1,
        stackwise_depth=[1, 2, 4],
        stackwise_strides=[1, 2, 2],
        stackwise_num_filters=[32, 64, 128],
        block_type="dark",
)

model(input_data)

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

#Use Timm presets directly from HuggingFace
model = keras_hub.models.ImageClassifier.from_preset('hf://timm/cspdarknet53.ra_in1k')
```

## Example Usage with Hugging Face URI

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

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

# Randomly initialized backbone with a custom config
    model = keras_hub.models.CSPNetBackbone(
        stem_filters=32,
        stem_kernel_size=3,
        stem_strides=1,
        stackwise_depth=[1, 2, 4],
        stackwise_strides=[1, 2, 2],
        stackwise_num_filters=[32, 64, 128],
        block_type="dark",
)

model(input_data)

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

#Use Timm presets directly from HuggingFace
model = keras_hub.models.ImageClassifier.from_preset('hf://timm/cspdarknet53.ra_in1k')
```