Skip to content

Instantly share code, notes, and snippets.

@ianstenbit
Created January 13, 2023 02:35
Show Gist options
  • Save ianstenbit/e3ece567c292d8e90066ddecc5a91f3c to your computer and use it in GitHub Desktop.
Save ianstenbit/e3ece567c292d8e90066ddecc5a91f3c to your computer and use it in GitHub Desktop.
# Copyright 2022 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
resizing_demo.py shows how to use the resizing preprocessing layer for
object detection.
"""
import demo_utils
from keras_cv import layers
from luketils import visualization
class_ids = [
"Aeroplane",
"Bicycle",
"Bird",
"Boat",
"Bottle",
"Bus",
"Car",
"Cat",
"Chair",
"Cow",
"Dining Table",
"Dog",
"Horse",
"Motorbike",
"Person",
"Potted Plant",
"Sheep",
"Sofa",
"Train",
"Tvmonitor",
"Total",
]
class_mapping = dict(zip(range(len(class_ids)), class_ids))
def visualize_dataset(dataset, bounding_box_format):
example = next(iter(dataset))
images, boxes = example["images"], example["bounding_boxes"]
visualization.plot_bounding_box_gallery(
images,
value_range=(0, 255),
bounding_box_format=bounding_box_format,
y_true=boxes,
scale=4,
rows=3,
cols=3,
show=True,
thickness=4,
font_scale=1,
class_mapping=class_mapping,
)
def main():
dataset = demo_utils.load_voc_dataset(bounding_box_format="xywh")
visualize_dataset(dataset, bounding_box_format="xywh")
resizing = layers.Resizing(
height=300, width=400, pad_to_aspect_ratio=True, bounding_box_format="xywh"
)
dataset = dataset.map(resizing).map(layers.Resizing(bounding_box_format="xywh"))
visualize_dataset(dataset, bounding_box_format="xywh")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment