{"id":15638682,"url":"https://github.com/sayakpaul/convnext-tf","last_synced_at":"2025-04-16T03:44:19.784Z","repository":{"id":44537571,"uuid":"447511750","full_name":"sayakpaul/ConvNeXt-TF","owner":"sayakpaul","description":"Includes PyTorch -\u003e Keras model porting code for ConvNeXt family of models with fine-tuning and inference notebooks. ","archived":false,"fork":false,"pushed_at":"2022-03-27T06:56:09.000Z","size":2593,"stargazers_count":100,"open_issues_count":1,"forks_count":13,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-29T04:43:02.090Z","etag":null,"topics":["computer-vision","convolutional-neural-networks","efficient-models","imagenet-1k","imagenet-21k","keras","tensorflow"],"latest_commit_sha":null,"homepage":"https://tfhub.dev/sayakpaul/collections/convnext/1","language":"Jupyter Notebook","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/sayakpaul.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}},"created_at":"2022-01-13T07:55:19.000Z","updated_at":"2024-06-06T13:37:38.000Z","dependencies_parsed_at":"2022-08-24T00:50:25.123Z","dependency_job_id":null,"html_url":"https://github.com/sayakpaul/ConvNeXt-TF","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FConvNeXt-TF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FConvNeXt-TF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FConvNeXt-TF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sayakpaul%2FConvNeXt-TF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sayakpaul","download_url":"https://codeload.github.com/sayakpaul/ConvNeXt-TF/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249191936,"owners_count":21227683,"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":["computer-vision","convolutional-neural-networks","efficient-models","imagenet-1k","imagenet-21k","keras","tensorflow"],"created_at":"2024-10-03T11:22:28.398Z","updated_at":"2025-04-16T03:44:19.759Z","avatar_url":"https://github.com/sayakpaul.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConvNeXt-TF\n\nThis repository provides TensorFlow / Keras implementations of different ConvNeXt\n[1] variants. It also provides the TensorFlow / Keras models that have been\npopulated with the original ConvNeXt pre-trained weights available from [2]. These\nmodels are not blackbox SavedModels i.e., they can be fully expanded into `tf.keras.Model`\nobjects and one can call all the utility functions on them (example: `.summary()`).\n\nAs of today, all the TensorFlow / Keras variants of the models listed\n[here](https://github.com/facebookresearch/ConvNeXt#results-and-pre-trained-models)\nare available in this repository except for the\n[isotropic ones](https://github.com/facebookresearch/ConvNeXt#imagenet-1k-trained-models-isotropic).\nThis list includes the ImageNet-1k as well as ImageNet-21k models.\n\nRefer to the [\"Using the models\"](https://github.com/sayakpaul/ConvNeXt-TF#using-the-models)\nsection to get started. Additionally, here's a [related blog post](https://sayak.dev/convnext-tfhub/)\nthat jots down my experience.\n\n## Conversion\n\nTensorFlow / Keras implementations are available in `models/convnext_tf.py`.\nConversion utilities are in `convert.py`.\n\n## Models\n\nThe converted models are available on [TF-Hub](https://tfhub.dev/sayakpaul/collections/convnext/1). \n\nThere should be a total of 15 different models each having two variants: classifier and\nfeature extractor. You can load any model and get started like so:\n\n```py\nimport tensorflow as tf\n\nmodel_gcs_path = \"gs://tfhub-modules/sayakpaul/convnext_tiny_1k_224/1/uncompressed\"\nmodel = tf.keras.models.load_model(model_gcs_path)\nprint(model.summary(expand_nested=True))\n```\n\nThe model names are interpreted as follows:\n\n* `convnext_large_21k_1k_384`: This means that the model was first pre-trained\non the ImageNet-21k dataset and was then fine-tuned on the ImageNet-1k dataset. \nResolution used during pre-training and fine-tuning: 384x384. `large` denotes\nthe topology of the underlying model.\n* `convnext_large_1k_224`: Means that the model was pre-trained on the ImageNet-1k\ndataset with a resolution of 224x224.\n\n## Results\n\nResults are on ImageNet-1k validation set (top-1 accuracy). \n\n| name | original acc@1 | keras acc@1 |\n|:---:|:---:|:---:|\n| convnext_tiny_1k_224 | 82.1 | 81.312 |\n| convnext_small_1k_224 | 83.1 | 82.392 |\n| convnext_base_1k_224 | 83.8 | 83.28 |\n| convnext_base_1k_384 | 85.1 | 84.876 |\n| convnext_large_1k_224 | 84.3 | 83.844 |\n| convnext_large_1k_384 | 85.5 | 85.376 |\n|  |  |  |\n| convnext_base_21k_1k_224 | 85.8 | 85.364 |\n| convnext_base_21k_1k_384 | 86.8 | 86.79 |\n| convnext_large_21k_1k_224 | 86.6 | 86.36 |\n| convnext_large_21k_1k_384 | 87.5 | 87.504 |\n| convnext_xlarge_21k_1k_224 | 87.0 | 86.732 |\n| convnext_xlarge_21k_1k_384 | 87.8 | 87.68 |\n\nDifferences in the results are primarily because of the differences in the library\nimplementations especially how image resizing is implemented in PyTorch and\nTensorFlow. Results can be verified with the code in `i1k_eval`. Logs\nare available at [this URL](https://tensorboard.dev/experiment/odN7OPCqQvGYCRpJP1GhRQ/).\n\n## Using the models\n\n**Pre-trained models**:\n\n* Off-the-shelf classification: [Colab Notebook](https://colab.research.google.com/github/sayakpaul/ConvNeXt-TF/blob/main/notebooks/classification.ipynb)\n* Fine-tuning: [Colab Notebook](https://colab.research.google.com/github/sayakpaul/ConvNeXt-TF/blob/main/notebooks/finetune.ipynb)\n \n **Randomly initialized models**:\n \n ```py\n from models.convnext_tf import get_convnext_model\n \n convnext_tiny = get_convnext_model()\n print(convnext_tiny.summary(expand_nested=True))\n ```\n \n To view different model configurations, refer [here](https://github.com/sayakpaul/ConvNeXt-TF/blob/main/models/model_configs.py).\n \n## Upcoming (contributions welcome)\n\n- [ ] Align layer initializers (useful if someone wanted to train the models\nfrom scratch)\n- [ ] Allow the models to accept arbitrary shapes (useful for downstream tasks)\n- [ ] Convert the [isotropic models](https://github.com/facebookresearch/ConvNeXt#imagenet-1k-trained-models-isotropic) as well \n- [x] Fine-tuning notebook (thanks to [awsaf49](https://github.com/awsaf49))\n- [x] Off-the-shelf-classification notebook\n- [x] Publish models on TF-Hub\n\n## References\n\n[1] ConvNeXt paper: https://arxiv.org/abs/2201.03545\n\n[2] Official ConvNeXt code: https://github.com/facebookresearch/ConvNeXt\n\n## Acknowledgements\n\n* [Vasudev Gupta](https://github.com/vasudevgupta7) \n* [Gus](https://twitter.com/gusthema)\n* [Willi](https://ch.linkedin.com/in/willi-gierke)\n* [ML-GDE program](https://developers.google.com/programs/experts/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayakpaul%2Fconvnext-tf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsayakpaul%2Fconvnext-tf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsayakpaul%2Fconvnext-tf/lists"}