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

Object detection docstrings broken #2018

Closed
jbischof opened this issue Aug 8, 2023 · 4 comments
Closed

Object detection docstrings broken #2018

jbischof opened this issue Aug 8, 2023 · 4 comments
Assignees
Labels
type:Bug Something isn't working

Comments

@jbischof
Copy link
Contributor

jbischof commented Aug 8, 2023

In the docstrings for at least three OD models/metrics, we create a single example using a tf tensor and Python dictionary. However, they don't seem to work even with tf.keras with the following error:

Code:

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)

See colab gist.

@jbischof jbischof added the type:Bug Something isn't working label Aug 8, 2023
@sampathweb
Copy link
Collaborator

Its not able to find a data adapter in tf.keras that can handle the inputs provided. If we create a TF Dataset, it works fine -

ds = tf.data.Dataset.from_tensor_slices((images, labels)).batch(2)
model.fit(ds)

We may need to update the doc string.
This still doesn't work with keras_core with TensorFlow backend and has a different error. Looking into it

@jbischof
Copy link
Contributor Author

jbischof commented Aug 8, 2023

@sampathweb if there's a more lightweight approach that works it might be a better fit for example docstrings. However, since most users will be brining tf.data I'm also OK with this.

@sampathweb
Copy link
Collaborator

sampathweb commented Aug 8, 2023

The above format of using dataset works with tf.keras backend and also with keras_core - jax and torch backend. Strangely it fails in keras-core with TensorFlow backend. Looking more into it.

import os
os.environ["KERAS_BACKEND"] = "tensorflow" # Fails
os.environ["KERAS_BACKEND"] = "jax" # Works
os.environ["KERAS_BACKEND"] = "torch" # Works

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

ds = tf.data.Dataset.from_tensor_slices((images, labels)).batch(2)
# Train model
model.compile(
    classification_loss='focal',
    box_loss='smoothl1',
    optimizer=keras.optimizers.SGD(global_clipnorm=10.0),
    jit_compile=False,
)
model.fit(ds)

@sampathweb
Copy link
Collaborator

Addressed in #2119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants