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

Fix code example in RetinaNet class docstring #2045

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

DiegoMont
Copy link
Contributor

Fix code example in RetinaNet class docstring

When running the code as it is currently written in the example (the imports are not in the example), an error is thrown:

images = np.ones((1, 512, 512, 3))
labels = {
    "boxes": [
        [
            [0, 0, 100, 100],
            [100, 100, 200, 200],
            [300, 300, 100, 100],
        ]
    ],
    "classes": [[1, 1, 1]],
}
model = keras_cv.models.RetinaNet(
    num_classes=20,
    bounding_box_format="xywh",
    backbone=keras_cv.models.ResNet50Backbone.from_preset(
        "resnet50_imagenet"
    )
)

# Evaluate model without box decoding and NMS
model(images)

# Prediction with box decoding and NMS
model.predict(images)

# Train model
model.compile(
    classification_loss='focal',
    box_loss='smoothl1',
    optimizer=keras.optimizers.SGD(global_clipnorm=10.0),
    jit_compile=False,
)
model.fit(images, labels)
ValueError: Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'dict'> containing {"<class 'str'>"} keys and {'(<class \'list\'> containing values of types {\'(<class \\\'list\\\'> containing values of types {"<class \\\'int\\\'>"})\'})', '(<class \'list\'> containing values of types {\'(<class \\\'list\\\'> containing values of types {\\\'(<class \\\\\\\'list\\\\\\\'> containing values of types {"<class \\\\\\\'int\\\\\\\'>"})\\\'})\'})'} values)

This pull request adds a correction to the labels dictionary that fixes the error. I took how the dictionary is created from the definition of the unpackage_raw_tfds_inputs function in the Object Detection with KerasCV guide from keras.io

labels = {
    "boxes": tf.cast([
        [
            [0, 0, 100, 100],
            [100, 100, 200, 200],
            [300, 300, 100, 100],
        ]
    ], dtype=tf.float32),
    "classes": tf.cast([[1, 1, 1]], dtype=tf.float32),
}

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@google-cla
Copy link

google-cla bot commented Aug 30, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor Author

@DiegoMont DiegoMont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request adds a correction to the labels dictionary that fixes the error. I took how the dictionary is created from the definition of the unpackage_raw_tfds_inputs function in the Object Detection with KerasCV guide from keras.io
@ianstenbit @jbischof

Copy link
Contributor

@ianstenbit ianstenbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you for the fix!

@ianstenbit ianstenbit merged commit ac7fc88 into keras-team:master Aug 30, 2023
6 of 9 checks passed
@jbischof
Copy link
Contributor

@ianstenbit do we want to reintroduce TF code?

@ianstenbit
Copy link
Contributor

@ianstenbit do we want to reintroduce TF code?

I figure for the purpose of a code example this is fine. I thought about using ops instead but to new users that might be a bit confusing

ghost pushed a commit to y-vectorfield/keras-cv that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants