{"id":14958964,"url":"https://github.com/sebastian-sz/efficientnet-v2-keras","last_synced_at":"2025-07-17T10:35:31.535Z","repository":{"id":38252853,"uuid":"391073047","full_name":"sebastian-sz/efficientnet-v2-keras","owner":"sebastian-sz","description":"Efficientnet V2 adapted to Keras functional API.","archived":false,"fork":false,"pushed_at":"2023-03-23T01:58:34.000Z","size":261,"stargazers_count":22,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T02:04:11.711Z","etag":null,"topics":["keras","keras-application","onnx","onnxruntime","tensorflow","tensorflow-lite","tensorflow-models"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastian-sz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-30T13:23:56.000Z","updated_at":"2025-03-28T08:45:45.000Z","dependencies_parsed_at":"2024-09-29T06:19:10.641Z","dependency_job_id":null,"html_url":"https://github.com/sebastian-sz/efficientnet-v2-keras","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.18867924528301883","last_synced_commit":"1a673c8e875e4b042034a70e1e73f461f05b7358"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sebastian-sz/efficientnet-v2-keras","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-sz%2Fefficientnet-v2-keras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-sz%2Fefficientnet-v2-keras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-sz%2Fefficientnet-v2-keras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-sz%2Fefficientnet-v2-keras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastian-sz","download_url":"https://codeload.github.com/sebastian-sz/efficientnet-v2-keras/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-sz%2Fefficientnet-v2-keras/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265595779,"owners_count":23794783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keras","keras-application","onnx","onnxruntime","tensorflow","tensorflow-lite","tensorflow-models"],"created_at":"2024-09-24T13:18:35.887Z","updated_at":"2025-07-17T10:35:31.473Z","avatar_url":"https://github.com/sebastian-sz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"EfficientNetV2 models rewritten in Keras functional API.\n\n### Changelog:\n* Feb 2022: \n  * As of 2.8 Tensorflow release, the models in this repository (apart from XL variant) are accessible through `keras.applications.efficientnet_v2`  \nYou are free to use this repo or Keras directly.\n* Nov 2021: \n  * added more weights variants from original repo.\n  * added option to manually get preprocessing layer.\n* Sept. 2021 - Added XL model variant.\n    * Changed layer naming convention.\n    * Re-exported weights.\n\n\n# Table of contens\n1. [Introduction](https://github.com/sebastian-sz/efficientnet-v2-keras#introduction)\n2. [Quickstart](https://github.com/sebastian-sz/efficientnet-v2-keras#quickstart)\n3. [Installation](https://github.com/sebastian-sz/efficientnet-v2-keras#installation)\n4. [How to use](https://github.com/sebastian-sz/efficientnet-v2-keras#how-to-use)\n5. [Original Weights](https://github.com/sebastian-sz/efficientnet-v2-keras#original-weights)\n\n# Introduction\nThis is a package with EfficientNetV2 model variants adapted to Keras functional API.\nI rewrote them this way so that the usage is similar to `keras.applications`.\n\nThe model's weights are converted from [original repository](https://github.com/google/automl/tree/master/efficientnetv2).\n\n# Quickstart\nYou can use these models, similar to `keras.applications`:\n\n```python\n# Install\n!pip install git+https://github.com/sebastian-sz/efficientnet-v2-keras@main\n\n# Import package:\nfrom efficientnet_v2 import EfficientNetV2S\nimport tensorflow as tf\n\n# Use model directly:\nmodel = EfficientNetV2S(\n    weights='imagenet', input_shape=(384, 384, 3)\n) \nmodel.summary()\n\n# Or to extract features / fine tune:\nbackbone = EfficientNetV2S(\n   weights='imagenet', \n   input_shape=(384, 384, 3),\n   include_top=False\n)\n\nmodel = tf.keras.Sequential([\n    backbone,\n    tf.keras.layers.GlobalAveragePooling2D(),\n    tf.keras.layers.Dense(10)  # 10 = num classes\n])\nmodel.compile(...)\nmodel.fit(...)\n```\n\nYou can fine tune these models, just like other Keras models.  \n\nFor end-to-end fine-tuning and conversion examples check out the \n[Colab Notebook](https://colab.research.google.com/drive/1CPTho02wBl48oOMqR2Wkj0xd90F3I9Uj?usp=sharing).\n\n# Installation\nThere are multiple ways to install.  \nThe only requirements are Tensorflow 2.2+ and Python 3.6+.  \n(Though, it is recommended to use **at least** Tensorflow 2.4)\n\n### Option A: (recommended) pip install from github\n`pip install git+https://github.com/sebastian-sz/efficientnet-v2-keras@main`\n\n### Option B: Build from source\n```bash\ngit clone https://github.com/sebastian-sz/efficientnet-v2-keras.git  \ncd efficientnet-v2-keras  \npip install .\n```\n\n### Option C: (alternatively) no install:\nIf you do not want to install you could just drop the `efficientnet_v2/` directory, directly into your project.\n\n### Option D: Docker\nYou can also install this package as an extension to official Tensorflow docker container:\nBuild: `docker build -t efficientnet_v2_keras .`  \nRun: `docker run -it --rm efficientnet_v2_keras`\n\nFor GPU support or different TAG you can (for example) pass  \n`--build-arg IMAGE_TAG=2.5.0-gpu`  \nin build command.\n\n### Verify installation\nIf all goes well you should be able to import:  \n`from efficientnet_v2 import *`\n\n# How to use\n\n### Pretrained weights\nWeights converted from original repository will be automatically downloaded, once you \npass `weights=\"imagenet\"` (or `imagenet-21k`, `imagenet-21k-ft1k`) upon model creation.\n\nThere are 3 weight variants: \n* `imagenet` - pretrained on Imagenet1k\n* `imagenet-21k` - pretrained on Imagenet21k\n* `imagenet-21k-ft1k` - pretrained on Imagenet21k and fine tuned on Imagenet1k\n\nNote: `imagenet` weights have not been released for `XL` variant.\n\n### Input shapes \nThe variants expect the following input shapes.\n\n| Model variant | Input shape |\n|:-------------:|:-----------:|\n|       B0      | `224,224`   |\n|       B1      | `240,240`   |\n|       B2      | `260,260`   |\n|       B3      | `300,300`   |\n|       S       | `384,384`   |\n|       M       | `480,480`   |\n|       L       | `480,480`   |\n|       XL      | `512,512`   |\n\n### Preprocessing\n##### Option A: preprocessing function\nThe preprocessing is different for `Bx` and `S/M/L/XL` variants.\n`Bx`'s expect image normalized with Imagenet mean and stddev, while other's a simple \nrescale:\n```python\nimport tensorflow as tf\n\n# Bx preprocessing:\ndef preprocess(image):  # input image is in range 0-255.\n    mean_rgb = [0.485 * 255, 0.456 * 255, 0.406 * 255]\n    stddev_rgb = [0.229 * 255, 0.224 * 255, 0.225 * 255]\n    image -= tf.constant(mean_rgb, shape=(1, 1, 3), dtype=image.dtype)\n    image /= tf.constant(stddev_rgb, shape=(1, 1, 3), dtype=image.dtype)\n    return image\n    \n# S/M/L/XL preprocessing\ndef preprocess(image):  \n    return (tf.cast(image, dtype=tf.float32) - 128.00) / 128.00\n```\n##### Option B: Preprocessing layers\nor you can use [Preprocessing Layer](https://www.tensorflow.org/guide/keras/preprocessing_layers)\nincluded in this repo:\n```python\nfrom efficientnet_v2 import get_preprocessing_layer\n\npreprocessing_layer = get_preprocessing_layer(variant=\"b0\")\n```\n\n### Fine-tuning\nFor fine-tuning example, check out the [Colab Notebook](https://colab.research.google.com/drive/1CPTho02wBl48oOMqR2Wkj0xd90F3I9Uj?usp=sharing).\n\n### Tensorflow Lite\nThe models are TFLite compatible. You can convert them like any other Keras model:\n```python\nconverter = tf.lite.TFLiteConverter.from_keras_model(model)\ntflite_model = converter.convert()\nwith open(\"efficientnet_lite.tflite\", \"wb\") as file:\n  file.write(tflite_model)\n```\n\n### ONNX\nThe models are ONNX compatible. For ONNX Conversion you can use \n[tf2onnx](https://github.com/onnx/tensorflow-onnx) package:\n```python\n!pip install tf2onnx==1.8.4\n\n# Save the model in TF's Saved Model format:\nmodel.save(\"my_saved_model/\")\n\n# Convert:\n!python -m tf2onnx.convert \\\n  --saved-model my_saved_model/ \\\n  --output efficientnet_v2.onnx\n```\n# Original Weights\nThe original weights are present in the\n[original repoistory](https://github.com/google/automl/tree/master/efficientnetv2).\nThe original models were also trained using Keras are compatible with TF 2.\n\n### (Optionally) Convert the weights\nThe converted weights are on this repository's GitHub. If, for some reason, you wish to \ndownload and convert original weights yourself, I prepared the utility scripts: \n1. `bash scripts/download_all.sh`\n2. `bash scripts/convert_all.sh`\n\n# Bibliography\n[1] [Original repository](https://github.com/google/automl/tree/master/efficientnetv2)\n\n# Closing words\nIf you found this repo useful, please consider giving it a star!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-sz%2Fefficientnet-v2-keras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastian-sz%2Fefficientnet-v2-keras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-sz%2Fefficientnet-v2-keras/lists"}