Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docstring examples #1970

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions keras_hub/src/models/deeplab_v3/deeplab_v3_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ class DeepLabV3ImageSegmenter(ImageSegmenter):
Load a DeepLabV3 preset with all the 21 class, pretrained segmentation head.
```python
images = np.ones(shape=(1, 96, 96, 3))
labels = np.zeros(shape=(1, 96, 96, 1))
labels = np.zeros(shape=(1, 96, 96, 2))
segmenter = keras_hub.models.DeepLabV3ImageSegmenter.from_preset(
"deeplabv3_resnet50_pascalvoc",
"deeplab_v3_plus_resnet50_pascalvoc",
)
segmenter.predict(images)
```

Specify `num_classes` to load randomly initialized segmentation head.
```python
segmenter = keras_hub.models.DeepLabV3ImageSegmenter.from_preset(
"deeplabv3_resnet50_pascalvoc",
"deeplab_v3_plus_resnet50_pascalvoc",
num_classes=2,
)
segmenter.preprocessor.image_size = (96, 96)
segmenter.fit(images, labels, epochs=3)
segmenter.predict(images) # Trained 2 class segmentation.
```

Load DeepLabv3+ presets a extension of DeepLabv3 by adding a simple yet
effective decoder module to refine the segmentation results especially
along object boundaries.
Expand Down
2 changes: 1 addition & 1 deletion keras_hub/src/models/densenet/densenet_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DenseNetBackbone(FeaturePyramidBackbone):
input_data = np.ones(shape=(8, 224, 224, 3))

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

# Randomly initialized backbone with a custom config
Expand Down
1 change: 0 additions & 1 deletion keras_hub/src/models/sam/sam_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class SAMBackbone(Backbone):
image_encoder=image_encoder,
prompt_encoder=prompt_encoder,
mask_decoder=mask_decoder,
image_shape=(image_size, image_size, 3),
)
backbone(input_data)
```
Expand Down
19 changes: 9 additions & 10 deletions keras_hub/src/models/sam/sam_image_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class SAMImageSegmenter(ImageSegmenter):
(batch_size, 0, image_size, image_size, 1)
),
}
# todo: update preset name
sam = keras_hub.models.SAMImageSegmenter.from_preset(`sam_base`)
sam(input_data)
sam = keras_hub.models.SAMImageSegmenter.from_preset('sam_base_sa1b')
outputs = sam.predict(input_data)
masks, iou_pred = outputs["masks"], outputs["iou_pred"]
```

Load segment anything image segmenter with custom backbone
Expand All @@ -65,7 +65,7 @@ class SAMImageSegmenter(ImageSegmenter):
(batch_size, image_size, image_size, 3),
dtype="float32",
)
image_encoder = ViTDetBackbone(
image_encoder = keras_hub.models.ViTDetBackbone(
hidden_size=16,
num_layers=16,
intermediate_dim=16 * 4,
Expand All @@ -76,7 +76,7 @@ class SAMImageSegmenter(ImageSegmenter):
window_size=2,
image_shape=(image_size, image_size, 3),
)
prompt_encoder = SAMPromptEncoder(
prompt_encoder = keras_hub.layers.SAMPromptEncoder(
hidden_size=8,
image_embedding_size=(8, 8),
input_image_size=(
Expand All @@ -85,7 +85,7 @@ class SAMImageSegmenter(ImageSegmenter):
),
mask_in_channels=16,
)
mask_decoder = SAMMaskDecoder(
mask_decoder = keras_hub.layers.SAMMaskDecoder(
num_layers=2,
hidden_size=8,
intermediate_dim=32,
Expand All @@ -95,13 +95,12 @@ class SAMImageSegmenter(ImageSegmenter):
iou_head_depth=3,
iou_head_hidden_dim=8,
)
backbone = SAMBackbone(
backbone = keras_hub.models.SAMBackbone(
image_encoder=image_encoder,
prompt_encoder=prompt_encoder,
mask_decoder=mask_decoder,
image_shape=(image_size, image_size, 3),
)
sam = SAMImageSegmenter(
sam = keras_hub.models.SAMImageSegmenter(
backbone=backbone
)
```
Expand All @@ -115,7 +114,7 @@ class SAMImageSegmenter(ImageSegmenter):
labels = np.array([[1., 0.]])
box = np.array([[[[384., 384.], [640., 640.]]]])
input_mask = np.ones((1, 1, 256, 256, 1))
Prepare an input dictionary:
# Prepare an input dictionary:
inputs = {
"images": image,
"points": points,
Expand Down
2 changes: 1 addition & 1 deletion keras_hub/src/models/vgg/vgg_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class VGGBackbone(Backbone):
input_data = np.ones((2, 224, 224, 3), dtype="float32")

# Pretrained VGG backbone.
model = keras_hub.models.VGGBackbone.from_preset("vgg16")
model = keras_hub.models.VGGBackbone.from_preset("vgg_16_imagenet")
model(input_data)

# Randomly initialized VGG backbone with a custom config.
Expand Down
Loading