CSPDarkNet
Collection
4 items • Updated
How to use keras/darknet_53_imagenet with KerasHub:
import keras_hub
import keras
# Load ImageClassifier model
image_classifier = keras_hub.models.ImageClassifier.from_preset(
"hf://keras/darknet_53_imagenet",
num_classes=2,
)
# Fine-tune
image_classifier.fit(
x=keras.random.randint((32, 64, 64, 3), 0, 256),
y=keras.random.randint((32, 1), 0, 2),
)
# Classify image
image_classifier.predict(keras.random.randint((1, 64, 64, 3), 0, 256))
import keras_hub
# Create a Backbone model unspecialized for any task
backbone = keras_hub.models.Backbone.from_preset("hf://keras/darknet_53_imagenet")
How to use keras/darknet_53_imagenet with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://keras/darknet_53_imagenet")
This class represents the CSPDarkNet architecture.
Reference
For transfer learning use cases, make sure to read the guide to transfer learning & fine-tuning.
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 page.
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. |
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')
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')