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 KerasCV quickstart to match github #1496

Merged
merged 1 commit into from
Aug 24, 2023
Merged
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
13 changes: 8 additions & 5 deletions templates/keras_cv/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ using it on top of your backend of choice:
```python
import keras_cv
import keras_core as keras
import numpy as np

filepath = keras.utils.get_file(origin="https://i.imgur.com/gCNcJJI.jpg")
image = np.array(keras.utils.load_img(filepath))
image_resized = ops.image.resize(image, (640, 640))[None, ...]
image_resized = keras.ops.image.resize(image, (640, 640))[None, ...]

model = keras_cv.models.YOLOV8Detector.from_preset(
"yolo_v8_m_pascalvoc",
Expand All @@ -88,25 +89,27 @@ to take effect.

```python
import tensorflow as tf
from tensorflow import keras
import keras_cv
import tensorflow_datasets as tfds
import keras_core as keras

# Create a preprocessing pipeline with augmentations
BATCH_SIZE = 16
NUM_CLASSES = 3
augmenter = keras.Sequential(
augmenter = keras_cv.layers.Augmenter(
pcoet marked this conversation as resolved.
Show resolved Hide resolved
[
keras_cv.layers.RandomFlip(),
keras_cv.layers.RandAugment(value_range=(0, 255)),
keras_cv.layers.CutMix(),
]
],
)

def preprocess_data(images, labels, augment=False):
labels = tf.one_hot(labels, NUM_CLASSES)
inputs = {"images": images, "labels": labels}
outputs = augmenter(inputs) if augment else inputs
outputs = inputs
if augment:
outputs = augmenter(outputs)
return outputs['images'], outputs['labels']

train_dataset, test_dataset = tfds.load(
Expand Down
Loading