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

Standardized / preferred way to implement blocks and models. #59

Closed
sebastian-sz opened this issue Jan 27, 2022 · 4 comments
Closed

Standardized / preferred way to implement blocks and models. #59

sebastian-sz opened this issue Jan 27, 2022 · 4 comments

Comments

@sebastian-sz
Copy link
Contributor

Given the models requirements are being gathered in the discussion, is there a preferred way to implement them?

There are multiple ways, to implement blocks and models:

  1. keras.applications way -> Models and blocks are functional Example.
  2. Model Garden way -> Model is functional, but blocks are layer subclasses. (even though the model is a direct subclass, it does not override call method).
  3. Blocks are layer subclasses, and models are model subclasses of keras.layers.Layer and keras.Model respectively. Both implement call method.

Each way has it's own benefits and drawbacks. Is one of the above preferred? Or maybe something entirely different?

@chjort
Copy link
Contributor

chjort commented Jan 27, 2022

Personally, I would prefer the keras.applications way, where the model is purely functional. Functional models are validated and built during construction. So if a functional models is constructed, the forward pass is guaranteed to work. This also makes model.summary() available right away.

Some applications will require non-standard keras layers, so these can be implemented by subclassing keras.layers.Layer, and then included in the functional model building.

@sebastian-sz
Copy link
Contributor Author

@chjort Yes, personally I would also prefer keras.applications way. This works well with Tensorflow Model Optimization (I'm not sure about subclassed model's) and the flat structure allows for easy layer modifications.

@LukeWood
Copy link
Contributor

We will be following the keras.applications standard. For example, ResNetBlock will be a functional model.

@sebastian-sz
Copy link
Contributor Author

@LukeWood thank you, that answer's the question.

freedomtan pushed a commit to freedomtan/keras-cv that referenced this issue Jul 20, 2023
* Add golden correctness tests for Adam and SGD

* Fix dtype issues

* Sync with main (keras-team#56)

* Minor touch ups

* Fix a pretty major bug

* Format code

* Big rethink of Variable API

* Make build-by-run the default build(), leveraging new zero_history KerasTensor mode

* Minor fixes

* Format code

* Switch back to build-by-eager-run for simplicity

* Add raise upon build failure

* Work around JAX bug.

* Add a few more tests.

* Add saving tests

* Adds test suite for SGD and golden correctness tests for all optimizers (keras-team#40)

* Add golden correctness tests for Adam and SGD

* Fix dtype issues

* Add binary accuracy (keras-team#41)

* chore: adding binary accuracy

* chore: fix docstring

* Add tests for add_loss and activity regularization.

* Reformat code

* Add ActivityRegularization layer

* Fix JAX CI.

* Add Lambda Callback (keras-team#42)

* Add LambdaCallback

* Add Lambda Callback

* Add Lambda Callback

* Rename lambda_callback_test.py

* Add einsum (keras-team#43)

* Add einsum

* address comments

* Fix format line length (keras-team#45)

* Add Embedding layer

* Shorten lines

* Add .vscode to .gitignore (keras-team#46)

* rm vscode settings

* add .vscode to gitignore

* Set demo program backend (keras-team#48)

* Add tests for training arg resolution in Layer.

* Implement mixed precision.

* Replace backend.execute with backend.numpy.XXX (keras-team#50)

* Add cosine similarity loss and update l2_normalize from regularizers (keras-team#34)

* Begin cosine loss

* Add testing for cosine similarity

* Fix formatting

* Docstring standardization

* Formatting

* Create numerical_utils

* Fix issue with call context lingering.

* Add the EarlyStopping callback (keras-team#44)

* add earlystopping callback

* addressing comments

* address comments

* addressing comments

* remove unused imports

* re-enable imports checks (keras-team#51)

* Add nn.one_hot (keras-team#52)

* Add GaussianDropout layer.

* Add GaussianNoise layer

* Add Categorical Accuracy Metric (keras-team#47)

* chore: adding categorical accuracy metric

* chore: reformat docstrings

* chore: reformat

* chore: ndims with len

* refactor the docstring

* Fix typos

* Implement masking.

---------

Co-authored-by: Francois Chollet <francois.chollet@gmail.com>
Co-authored-by: Aritra Roy Gosthipaty <aritra.born2fly@gmail.com>
Co-authored-by: Ramesh Sampath <1437573+sampathweb@users.noreply.github.com>
Co-authored-by: Chen Qian <chenmoney@google.com>
Co-authored-by: Haifeng Jin <5476582+haifeng-jin@users.noreply.github.com>
Co-authored-by: Gabriel Rasskin <43894452+grasskin@users.noreply.github.com>

* Adds rmsprop optimizer and tests

* Add AdamW optimizer and tests, minor formatting changes

* Implemented formatting fixes

---------

Co-authored-by: Francois Chollet <francois.chollet@gmail.com>
Co-authored-by: Aritra Roy Gosthipaty <aritra.born2fly@gmail.com>
Co-authored-by: Ramesh Sampath <1437573+sampathweb@users.noreply.github.com>
Co-authored-by: Chen Qian <chenmoney@google.com>
Co-authored-by: Haifeng Jin <5476582+haifeng-jin@users.noreply.github.com>
Co-authored-by: Gabriel Rasskin <43894452+grasskin@users.noreply.github.com>
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

No branches or pull requests

3 participants