keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
62.12k stars 19.49k forks source link

Keras.io examples conversion gameplan #18468

Open fchollet opened 1 year ago

fchollet commented 1 year ago

We need to convert keras.io examples to work with Keras 3.

This involves two stages:

Stage 1: tf.keras backwards compatibility check

Keras 3 is intended as a drop-in replacement for tf.keras. We expect most examples to work with no code changes other changing the imports (when using TF as the backend). So the first thing to do with a keras.io example is:

  1. Install Keras 3 (via a git clone followed by python pip_build.py --install).
  2. Run the example. In many cases this involves some manual steps around data downloads and dependency installation. Also, in many cases you should also edit hyperparameters to reduce compute intensiveness in order to be able to debug quickly (e.g. set epochs=1 and steps_per_epoch=3, that sort of thing).
  3. Record anything that doesn't work out of the box and file issues on the Keras 3 GitHub accordingly. We will use these issues to improve the degree of compatibility of Keras 3 going forward. Try to work around each issue you find, so that you can reach the next issue.
  4. Open a PR to commit your converted examples in examples/keras_io/tensorflow/. PLEASE INCLUDE THE GIT DIFF (diff from the original example to the new file) in the PR description.

Note: in some cases this conversion will not be possible. There is some niche functionality that we removed from Keras 3, such as add_metric. When hitting such problems, if unable to work around the issue, simply record the problem in a GitHub issue and move on.

Stage 2: backend-agnostic conversion

Going one step further, once an example runs with the TF backend, we should seek to replace all TF APIs in the example with backend-agnostic keras.ops APIs.

In some cases this is not possible. Keras Core does not have backend-agnostic capabilities for custom train_step or custom training loops. In such cases, you should convert what is convertible, and then fork the example into 2 separate versions: a TF one and a JAX one, using APIs from each framework to implement the low-level functionality.

Keep in mind that it's ok to use TF APIs for data I/O and preprocessing. We only aim to convert modeling and training APIs -- all data preprocessing can stay as-is even if it uses TF. TF is the only feature-complete framework when it comes to data preprocessing, and generally the only viable option for many use cases.

Note on Keras preprocessing layers and tf.data: you can't use Keras 3 preprocessing layers in a tf.data pipeline when using a backend that is not TF. As a result, if you need to use Keras preprocessing layers in tf.data, import them from tf.keras.

Once you have converted an example to use backend-agnostic APIs and run with JAX and TF, open a PR to commit it:

Let's go!

Assignment - stage 1: conversion to Keras 3 with TF backend

CV

NLP

Structured data

Timeseries

Generative

Other

List of examples with significant incompatibilities

List of examples that cannot be converted at all

AakashKumarNain commented 1 year ago

Wow! Been contributing to these examples for a long time but never realized that we have so many high-quality examples. Amazing feat! šŸ‘

PS: I will setup keras_core GPU env, and will start working on some of the examples I contributed. Will update the issue accordingly

soumik12345 commented 1 year ago

Raised a PR to port the example Zero-DCE for low-light image enhancement to keras_core: https://github.com/keras-team/keras-core/pull/486 Also found a possible bug while doing so: https://github.com/keras-team/keras-core/issues/485

soumik12345 commented 1 year ago

Raised a PR to port example Low-light image enhancement using MIRNet to keras-core: https://github.com/keras-team/keras-core/pull/491

anas-rz commented 1 year ago

Raised PR to port example A Vision Transformer without Attention: keras-team/keras-core#497

anas-rz commented 1 year ago

Raised a PR to port example to keras-core: Compact Convolutional Transformers keras-team/keras-core#523

pksX01 commented 1 year ago

I would like to take 'Question Answering with Hugging Face Transformers' task.

pksX01 commented 1 year ago

I would like to take 'Question Answering with Hugging Face Transformers' task.

I am facing an issue while running after changes and I have raised an issue for the same #18572.

madhusshivakumar commented 1 year ago

I would like to work on

examples/vision/cait.py #18700 Facing issue #18699

examples/vision/metric_learning.py #18701 Facing issue #18698

madhusshivakumar commented 1 year ago

I was working on movielens recommendations and raised PR for the same #18690

ben-ad commented 1 year ago

I would like to work on "Text extraction with Bert" stage 1.

PS: the status on what has been done already is not up to date in the stage 1 list above.

sitamgithub-MSIT commented 12 months ago

"Image Classification using BigTransfer (BiT)" is the task that I would like to take on. Image Classification using BigTransfer (BiT)

Note: As of right now, I will focus on Stage 1: the tf.keras backward compatibility check. To make the backend agnostic, the remainder will attempt to work on stage 2.

sitamgithub-MSIT commented 11 months ago

"Image Classification using BigTransfer (BiT)" is the task that I would like to take on. Image Classification using BigTransfer (BiT)

Note: As of right now, I will focus on Stage 1: the tf.keras backward compatibility check. To make the backend agnostic, the remainder will attempt to work on stage 2.

Update: Find some issues specifically related to the model at tf.hub (now Kaggle Models). Anyway, I will create a detailed issue of my problems in one or two days.

sitamgithub-MSIT commented 11 months ago

"Train a Vision Transformer on small datasets" is the task that I would like to take on next. Train a Vision Transformer on small datasets

pksX01 commented 11 months ago

"Train a Vision Transformer on small datasets" is the task that I would like to take on next. Train a Vision Transformer on small datasets

@sitamgithub-MSIT I am already working on this from last couple of days, I had also raised issue which I was facing in this script but now that issue is gone and Stage 1 is already completed. I will raise PR soon.

Please select different problem/ example.

innat-asj commented 11 months ago

I've just noticed this keras example, Semi-supervised image classification using contrastive pretraining with SimCLR ( link ) has changed significantly, original author @beresandras , updated by @ariG23498. The core contributed part (SimCLR modelling) is replaced with built-in API (why). Also, what is the purpose of keras_cv.training, looks uncertain API.

class SimCLRTrainer(keras_cv.training.ContrastiveTrainer):
    def __init__(self, encoder, augmenter, projector, probe=None, **kwargs):
        super().__init__(
            encoder=encoder,
            augmenter=augmenter,
            projector=projector,
            probe=probe,
            **kwargs,
        )

simclr_model = SimCLRTrainer(...)
ariG23498 commented 11 months ago

That was part of the Keras Sprint.

CC: @martin-gorner

sitamgithub-MSIT commented 11 months ago

Working on the MixUp augmentation for image classification

innat-asj commented 11 months ago

That was part of the Keras Sprint.

CC: @martin-gorner

Looks like it (link) is reverted to its original form.

sitamgithub-MSIT commented 11 months ago

Working on the MixUp augmentation for image classification

It seems like it was already converted to Keras 3.0. The above list is not updated, and moreover, on the Keras website, it is showing as Keras 2.0.

CC: @fchollet

sitamgithub-MSIT commented 11 months ago

Working on the RandAugment for Image Classification for Improved Robustness

innat commented 10 months ago

Instead of replacing Keras 2 example with Keras 3, why not keeping both in the code example? As tf.keras is not getting invalid any time soon or is it?