Divyasreepat commited on
Commit
5fc25a6
·
verified ·
1 Parent(s): 9058829

Update README.md with new model card content

Browse files
Files changed (1) hide show
  1. README.md +195 -14
README.md CHANGED
@@ -1,17 +1,198 @@
1
  ---
2
  library_name: keras-hub
3
  ---
4
- This is a [`RetinaNet` model](https://keras.io/api/keras_hub/models/retina_net) uploaded using the KerasHub library and can be used with JAX, TensorFlow, and PyTorch backends.
5
- This model is related to a `ObjectDetector` task.
6
-
7
- Model config:
8
- * **name:** retina_net_backbone
9
- * **trainable:** True
10
- * **image_encoder:** {'module': 'keras_hub.src.models.resnet.resnet_backbone', 'class_name': 'ResNetBackbone', 'config': {'name': 'res_net_backbone', 'trainable': True, 'input_conv_filters': [64], 'input_conv_kernel_sizes': [7], 'stackwise_num_filters': [64, 128, 256, 512], 'stackwise_num_blocks': [3, 4, 6, 3], 'stackwise_num_strides': [1, 2, 2, 2], 'block_type': 'bottleneck_block', 'use_pre_activation': False, 'image_shape': [None, None, 3]}, 'registered_name': 'keras_hub>ResNetBackbone'}
11
- * **min_level:** 3
12
- * **max_level:** 7
13
- * **use_p5:** True
14
- * **use_fpn_batch_norm:** False
15
- * **image_shape:** [None, None, 3]
16
-
17
- This model card has been generated automatically and should be completed by the model author. See [Model Cards documentation](https://huggingface.co/docs/hub/model-cards) for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: keras-hub
3
  ---
4
+ ### Model Overview
5
+ A Keras model implementing the RetinaNet meta-architecture.
6
+
7
+ Implements the RetinaNet architecture for object detection. The constructor
8
+ requires `num_classes`, `bounding_box_format`, and a backbone. Optionally,
9
+ a custom label encoder, and prediction decoder may be provided.
10
+
11
+ ## Links
12
+
13
+ * [RetinaNet Quickstart Notebook](https://www.kaggle.com/code/sineeli/retinanet-training-guide)
14
+ * [RetinaNet API Documentation](https://keras.io/keras_hub/api/models/retinanet/)
15
+ * [RetinaNet Model Card](https://huggingface.co/keras-io/Object-Detection-RetinaNet)
16
+ * [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
17
+ * [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
18
+
19
+ ## Installation
20
+
21
+ Keras and KerasHub can be installed with:
22
+
23
+ ```
24
+ pip install -U -q keras-hub
25
+ pip install -U -q keras
26
+ ```
27
+
28
+ 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.
29
+
30
+ ## Presets
31
+
32
+ The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
33
+ | Preset name | Parameters | Description |
34
+ |----------------|------------|--------------------------------------------------|
35
+ | retinanet_resnet50_fpn_coco | 34.12M | RetinaNet model with ResNet50 backbone fine-tuned on COCO in 800x800 resolution.|
36
+
37
+ __Arguments__
38
+
39
+
40
+ - __num_classes__: the number of classes in your dataset excluding the
41
+ background class. Classes should be represented by integers in the
42
+ range [0, num_classes).
43
+ - __bounding_box_format__: The format of bounding boxes of input dataset.
44
+ Refer
45
+ [to the keras.io docs](https://keras.io/api/keras_cv/bounding_box/formats/)
46
+ for more details on supported bounding box formats.
47
+ - __backbone__: `keras.Model`. If the default `feature_pyramid` is used,
48
+ must implement the `pyramid_level_inputs` property with keys "P3", "P4",
49
+ and "P5" and layer names as values. A somewhat sensible backbone
50
+ to use in many cases is the:
51
+ `keras_cv.models.ResNetBackbone.from_preset("resnet50_imagenet")`
52
+ - __anchor_generator__: (Optional) a `keras_cv.layers.AnchorGenerator`. If
53
+ provided, the anchor generator will be passed to both the
54
+ `label_encoder` and the `prediction_decoder`. Only to be used when
55
+ both `label_encoder` and `prediction_decoder` are both `None`.
56
+ Defaults to an anchor generator with the parameterization:
57
+ `strides=[2**i for i in range(3, 8)]`,
58
+ `scales=[2**x for x in [0, 1 / 3, 2 / 3]]`,
59
+ `sizes=[32.0, 64.0, 128.0, 256.0, 512.0]`,
60
+ and `aspect_ratios=[0.5, 1.0, 2.0]`.
61
+ - __label_encoder__: (Optional) a keras.Layer that accepts an image Tensor, a
62
+ bounding box Tensor and a bounding box class Tensor to its `call()`
63
+ method, and returns RetinaNet training targets. By default, a
64
+ KerasCV standard `RetinaNetLabelEncoder` is created and used.
65
+ Results of this object's `call()` method are passed to the `loss`
66
+ object for `box_loss` and `classification_loss` the `y_true`
67
+ argument.
68
+ - __prediction_decoder__: (Optional) A `keras.layers.Layer` that is
69
+ responsible for transforming RetinaNet predictions into usable
70
+ bounding box Tensors. If not provided, a default is provided. The
71
+ default `prediction_decoder` layer is a
72
+ `keras_cv.layers.MultiClassNonMaxSuppression` layer, which uses
73
+ a Non-Max Suppression for box pruning.
74
+ - __feature_pyramid__: (Optional) A `keras.layers.Layer` that produces
75
+ a list of 4D feature maps (batch dimension included)
76
+ when called on the pyramid-level outputs of the `backbone`.
77
+ If not provided, the reference implementation from the paper will be used.
78
+ - __classification_head__: (Optional) A `keras.Layer` that performs
79
+ classification of the bounding boxes. If not provided, a simple
80
+ ConvNet with 3 layers will be used.
81
+ - __box_head__: (Optional) A `keras.Layer` that performs regression of the
82
+ bounding boxes. If not provided, a simple ConvNet with 3 layers
83
+ will be used.
84
+
85
+ ## Example Usage
86
+ ## Pretrained RetinaNet model
87
+ ```
88
+ object_detector = keras_hub.models.ImageObjectDetector.from_preset(
89
+ "retinanet_resnet50_fpn_v2_coco"
90
+ )
91
+
92
+ input_data = np.random.uniform(0, 1, size=(2, 224, 224, 3))
93
+ object_detector(input_data)
94
+ ```
95
+
96
+ ## Fine-tune the pre-trained model
97
+ ```python3
98
+ backbone = keras_hub.models.Backbone.from_preset(
99
+ "retinanet_resnet50_fpn_v2_coco"
100
+ )
101
+ preprocessor = keras_hub.models.RetinaNetObjectDetectorPreprocessor.from_preset(
102
+ "retinanet_resnet50_fpn_v2_coco"
103
+ )
104
+ model = RetinaNetObjectDetector(
105
+ backbone=backbone,
106
+ num_classes=len(CLASSES),
107
+ preprocessor=preprocessor
108
+ )
109
+ ```
110
+
111
+ ## Custom training the model
112
+ ```python3
113
+ image_converter = keras_hub.layers.RetinaNetImageConverter(
114
+ scale=1/255
115
+ )
116
+
117
+ preprocessor = keras_hub.models.RetinaNetObjectDetectorPreprocessor(
118
+ image_converter=image_converter
119
+ )
120
+ # Load a pre-trained ResNet50 model.
121
+ # This will serve as the base for extracting image features.
122
+ image_encoder = keras_hub.models.Backbone.from_preset(
123
+ "resnet_50_imagenet"
124
+ )
125
+
126
+ # Build the RetinaNet Feature Pyramid Network (FPN) on top of the ResNet50
127
+ # backbone. The FPN creates multi-scale feature maps for better object detection
128
+ # at different sizes.
129
+ backbone = keras_hub.models.RetinaNetBackbone(
130
+ image_encoder=image_encoder,
131
+ min_level=3,
132
+ max_level=5,
133
+ use_p5=False
134
+ )
135
+ model = RetinaNetObjectDetector(
136
+ backbone=backbone,
137
+ num_classes=len(CLASSES),
138
+ preprocessor=preprocessor
139
+ )
140
+ ```
141
+
142
+ ## Example Usage with Hugging Face URI
143
+
144
+ ## Pretrained RetinaNet model
145
+ ```
146
+ object_detector = keras_hub.models.ImageObjectDetector.from_preset(
147
+ "hf://keras/retinanet_resnet50_fpn_v2_coco"
148
+ )
149
+
150
+ input_data = np.random.uniform(0, 1, size=(2, 224, 224, 3))
151
+ object_detector(input_data)
152
+ ```
153
+
154
+ ## Fine-tune the pre-trained model
155
+ ```python3
156
+ backbone = keras_hub.models.Backbone.from_preset(
157
+ "hf://keras/retinanet_resnet50_fpn_v2_coco"
158
+ )
159
+ preprocessor = keras_hub.models.RetinaNetObjectDetectorPreprocessor.from_preset(
160
+ "hf://keras/retinanet_resnet50_fpn_v2_coco"
161
+ )
162
+ model = RetinaNetObjectDetector(
163
+ backbone=backbone,
164
+ num_classes=len(CLASSES),
165
+ preprocessor=preprocessor
166
+ )
167
+ ```
168
+
169
+ ## Custom training the model
170
+ ```python3
171
+ image_converter = keras_hub.layers.RetinaNetImageConverter(
172
+ scale=1/255
173
+ )
174
+
175
+ preprocessor = keras_hub.models.RetinaNetObjectDetectorPreprocessor(
176
+ image_converter=image_converter
177
+ )
178
+ # Load a pre-trained ResNet50 model.
179
+ # This will serve as the base for extracting image features.
180
+ image_encoder = keras_hub.models.Backbone.from_preset(
181
+ "resnet_50_imagenet"
182
+ )
183
+
184
+ # Build the RetinaNet Feature Pyramid Network (FPN) on top of the ResNet50
185
+ # backbone. The FPN creates multi-scale feature maps for better object detection
186
+ # at different sizes.
187
+ backbone = keras_hub.models.RetinaNetBackbone(
188
+ image_encoder=image_encoder,
189
+ min_level=3,
190
+ max_level=5,
191
+ use_p5=False
192
+ )
193
+ model = RetinaNetObjectDetector(
194
+ backbone=backbone,
195
+ num_classes=len(CLASSES),
196
+ preprocessor=preprocessor
197
+ )
198
+ ```