{"id":13992200,"url":"https://github.com/tensorflow/swift-models","last_synced_at":"2025-12-17T02:30:15.704Z","repository":{"id":39873723,"uuid":"130903312","full_name":"tensorflow/swift-models","owner":"tensorflow","description":"Models and examples built with Swift for TensorFlow","archived":false,"fork":false,"pushed_at":"2021-03-02T18:55:00.000Z","size":66317,"stargazers_count":649,"open_issues_count":46,"forks_count":150,"subscribers_count":45,"default_branch":"main","last_synced_at":"2025-02-12T15:10:43.567Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/tensorflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-24T19:21:41.000Z","updated_at":"2024-12-21T09:35:38.000Z","dependencies_parsed_at":"2022-08-30T01:31:25.628Z","dependency_job_id":null,"html_url":"https://github.com/tensorflow/swift-models","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/tensorflow%2Fswift-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fswift-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensorflow","download_url":"https://codeload.github.com/tensorflow/swift-models/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239690069,"owners_count":19681034,"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":[],"created_at":"2024-08-09T14:01:52.234Z","updated_at":"2025-12-17T02:30:13.646Z","avatar_url":"https://github.com/tensorflow.png","language":"Jupyter Notebook","readme":"# Swift for TensorFlow Models\n\n\nSwift for TensorFlow was an experiment in the next-generation platform for machine learning, incorporating the latest research across machine learning, compilers, differentiable programming, systems design, and beyond. It was archived in February 2021.\n\nThis repository contains many examples of how Swift for TensorFlow can be used to build machine\nlearning applications, as well as the models, datasets, and other components required to build them.\nThese examples are intended to demonstrate best practices for the use of \n[Swift for TensorFlow APIs](https://github.com/tensorflow/swift-apis) and act as end-to-end tests\nto validate the function and performance of those APIs.\n\nActive development occurs on the `main` branch, and that is kept current against the `main` branch\nof [the Swift compiler](https://github.com/apple/swift) and the `main` branch of [the Swift for TensorFlow APIs](https://github.com/tensorflow/swift-apis).\n\nFor stable snapshots, use the ```tensorflow-xx``` branch that corresponds to the toolchain you are using from the [Swift for TensorFlow releases](https://github.com/tensorflow/swift/blob/master/Installation.md#releases).  For example, for the 0.12 release, use the ```tensorflow-0.12``` branch.\n\nTo learn more about Swift for TensorFlow development, please visit\n[tensorflow/swift](https://github.com/tensorflow/swift).\n\n## Examples\n\nThe examples within this repository are all designed to be run as standalone applications. The easiest way to do this is to use Swift Package Manager to build and run individual examples. This \ncan be accomplished by changing to the root directory of the project and typing something like\n\n```bash\nswift run -c release [Example] [Options]\n```\n\nFor Windows, an additional flag may be required:\n\n```cmd\nswift run -Xswiftc -use-ld=lld -c release [Example] [Options]\n```\n\nThis will build and run a specific example in the release configuration. Due to significant\nperformance differences between debug and release builds in Swift, we highly recommend running the\nexamples from a release build. Some examples have additional command-line options, and those will\nbe described in the example's README.\n\nThe following is a catalog of the current examples, grouped by subject area, with links to their\nlocation within the project. Each example should have documentation for what it is demonstrating\nand how to use it.\n\n### Image classification\n\n- [A custom model training against CIFAR-10](Examples/Custom-CIFAR10)\n- [LeNet-5 training against MNIST](Examples/LeNet-MNIST)\n- [MobileNet V1 training against Imagenette](Examples/MobileNetV1-Imagenette)\n- [MobileNet V2 training against Imagenette](Examples/MobileNetV2-Imagenette)\n- [ResNet-56 training against CIFAR-10](Examples/ResNet-CIFAR10)\n- [ResNet-50 training against ImageNet](Examples/ResNet50-ImageNet)\n- [VGG-16 training against Imagewoof](Examples/VGG-Imagewoof)\n\n### Text\n\n- [BERT training against CoLA](Examples/BERT-CoLA)\n- [Pretrained GPT-2 performing text generation](Examples/GPT2-Inference)\n- [GPT-2 training against WikiText-2](Examples/GPT2-WikiText2)\n- [WordSeg](Examples/WordSeg)\n\n### Generative models\n\n- [1-D Autoencoder](Autoencoder/Autoencoder1D)\n- [2-D Autoencoder](Autoencoder/Autoencoder2D)\n- [1-D Variational Autoencoder](Autoencoder/VAE1D)\n- [CycleGAN](CycleGAN)\n- [GAN](GAN)\n- [DCGAN](DCGAN)\n- [pix2pix](pix2pix)\n\n### Reinforcement learning\n\n- [Blackjack](Gym)\n- [CartPole](Gym)\n- [Catch](Catch)\n- [FrozenLake](Gym)\n- [MiniGo](MiniGo)\n\n### Standalone\n\n- [Differentiable Shallow Water PDE Solver](Examples/Shallow-Water-PDE)\n- [Fast Style Transfer](FastStyleTransfer)\n- [Fractals](Examples/Fractals)\n- [Growing Neural Cellular Automata](Examples/GrowingNeuralCellularAutomata)\n- [Neural Collaborative Filtering using MovieLens](Examples/NeuMF-MovieLens)\n- [PersonLab Human Pose Estimator](PersonLab)\n- [Regression using BostonHousing](Examples/Regression-BostonHousing)\n\n## Components\n\nBeyond examples that use Swift for TensorFlow, this repository also contains reusable components\nfor constructing machine learning applications. These components reside in modules that can be\nimported into separate Swift projects and used by themselves.\n\nThese components provide standalone machine learning models, datasets, image loading and saving,\nTensorBoard integration, and a training loop abstraction, among other capabilities.\n\nThe Swift for TensorFlow models repository has acted as a staging ground for experimental\ncapabilities, letting us evaluate new components and interfaces before elevating them into the core\nSwift for TensorFlow APIs. As a result, the design and interfaces of these components may change\nregularly.\n\n### Models\n\nSeveral modules are provided that contain reusable Swift models for image classification, text\nprocessing, and more. These modules are used within the example applications to demonstrate the\ncapabilities of these models, but they can also be imported into many other projects.\n\n#### Image classification\n\nMany common image classification models are present within\n[the ImageClassificationModels module](Models/ImageClassification). To use them within a Swift\nproject, add ImageClassificationModels as a dependency and import the module:\n\n```swift\nimport ImageClassificationModels\n```\n\nThese models include:\n\n- DenseNet121\n- EfficientNet\n- LeNet-5\n- MobileNetV1\n- MobileNetV2\n- MobileNetV3\n- ResNet\n- ResNetV2\n- ShuffleNetV2\n- SqueezeNet\n- VGG\n- WideResNet\n- Xception\n\n#### Recommendation\n\nSeveral recommendation models are present within\n[the RecommendationModels module](Models/Recommendation). To use them within a Swift\nproject, add RecommendationModels as a dependency and import the module:\n\n```swift\nimport RecommendationModels\n```\n\nThese models include:\n\n- DLRM\n- MLP\n- NeuMF\n\n#### Text\n\nSeveral text models are present within\n[the TextModels module](Models/Text). To use them within a Swift\nproject, add TextModels as a dependency and import the module:\n\n```swift\nimport TextModels\n```\n\nThese models include:\n\n- [BERT](Models/Text/BERT)\n- [GPT-2](Models/Text/GPT2)\n- [WordSeg](Models/Text/WordSeg)\n\n### Datasets\n\nIn addition to the machine learning model itself, a dataset is usually required when training.\nSwift wrappers have been built for many common datasets to ease their use within machine learning\napplications. Most of these use the\n[Epochs](https://github.com/tensorflow/swift-apis/tree/main/Sources/TensorFlow/Epochs) API that \nprovides a generalized abstraction of common dataset operations.\n\nThe [Datasets](Datasets) module provides these wrappers. To use them within a Swift\nproject, add Datasets as a dependency and import the module:\n\n```swift\nimport Datasets\n```\n\nThese are the currently provided dataset wrappers:\n\n- [BostonHousing](Datasets/BostonHousing)\n- [CIFAR-10](Datasets/CIFAR10)\n- [MS COCO](Datasets/COCO)\n- [CoLA](Datasets/CoLA)\n- [ImageNet](Datasets/Imagenette)\n- [Imagenette](Datasets/Imagenette)\n- [Imagewoof](Datasets/Imagenette)\n- [FashionMNIST](Datasets/MNIST)\n- [KuzushijiMNIST](Datasets/MNIST)\n- [MNIST](Datasets/MNIST)\n- [MovieLens](Datasets/MovieLens)\n- [Oxford-IIIT Pet](Datasets/OxfordIIITPets)\n- [WordSeg](Datasets/WordSeg)\n\n### Model checkpoints\n\nModel saving and loading is provided by the [Checkpoints](Checkpoints) module. To use the model\ncheckpointing functionality, add Checkpoints as a dependency and import the module:\n\n```swift\nimport Checkpoints\n```\n\n### Image loading and saving\n\nThe [ModelSupport](Support) module contains many shared utilites that are needed within the Swift\nmachine learning examples. This includes the loading, saving, and processing of\n[still images](Support/Image.swift) via the\n[stb_image](https://github.com/nothings/stb) library.\n[Animated images](Support/AnimatedImage.swift) can also be written out as GIF files from multiple\ntensors.\n\nExperimental support for libjpeg-turbo as an accelerated image loader [is present](ImageLoader), \nbut has not yet been incorporated into the main image loading capabilities.\n\n### Generalized training loop\n\nA generalized training loop that can be customized via callbacks is provided within the \n[TrainingLoop](TrainingLoop) module. All of the image classification examples use this training\nloop, with the exception of the Custom-CIFAR10 example that demonstrates how to define your own\ntraining loop from scratch. Other examples are being gradually converted to use this training loop.\n\n### TensorBoard integration\n\n[TensorBoard](https://www.tensorflow.org/tensorboard) integration is provided in the\n[TensorBoard module](TensorBoard) as a callback for the generalized training loop. TensorBoard \nlets you visualize the progress of your model as it trains by plotting model statistics as they\nupdate, or to review the training process afterward.\n\nThe [GPT2-WikiText2](Examples/GPT2-WikiText2) example demonstrates how this can be used when\ntraining your own models.\n\n## Benchmarks and tests\n\nA core goal of this repository is to validate the proper function of the Swift for TensorFlow APIs.\nIn addition to the models and end-to-end applications present within this project, a suite of\nbenchmarks and unit tests reside here.\n\nThe benchmarks are split into a core of functionality, the\n[SwiftModelsBenchmarksCore](SwiftModelsBenchmarksCore) module, and a \n[Benchmarks](SwiftModelsBenchmarks) command-line application for running these benchmarks. Refer to\nthe [documentation](SwiftModelsBenchmarks) for how to run the benchmarks on your system.\n\nThe [unit tests](Tests) verify functionality within models, datasets and other components. To run\nthem using Swift Package Manager on macOS or Linux:\n\n```bash\nswift test\n```\n\nand to run them on Windows:\n\n```cmd\nswift test -Xswiftc -use-ld=lld -c debug\n```\n\n## Using CMake for Development\n\nIn addition to Swift Package Manager, CMake can be used to build and run Swift for TensorFlow\nmodels.\n\n### *Experimental* CMake Support\n\nThere is experimental support for building with CMake.  This can be used to cross-compile the models and the demo programs.\n\nIt is highly recommended that you use CMake 3.16 or newer to ensure that `-B`\nand parallel builds function properly in the example commands below. To install\nthis version on Ubuntu, we recommend following the instructions at\n[Kitware's apt repo](https://apt.kitware.com/).\n\n**Prerequisite:** [Ninja build tool](https://ninja-build.org/). Find\ninstallation commands for your favorite package manager\n[here](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages).\n\nmacOS:\n\n```\n# Configure\ncmake                                                              \\\n  -B /BinaryCache/tensorflow-swift-models                          \\\n  -D BUILD_TESTING=YES                                             \\\n  -D CMAKE_BUILD_TYPE=Release                                      \\\n  -D CMAKE_Swift_COMPILER=$(TOOLCHAINS=tensorflow xcrun -f swiftc) \\\n  -G Ninja                                                         \\\n  -S /SourceCache/tensorflow-swift-models\n# Build\ncmake --build /BinaryCache/tensorflow-swift-models\n# Test\ncmake --build /BinaryCache/tensorflow-swift-models --target test\n```\n\nLinux:\n\n```\n# Configure\ncmake                                     \\\n  -B /BinaryCache/tensorflow-swift-models \\\n  -D BUILD_TESTING=NO                     \\\n  -D CMAKE_BUILD_TYPE=Release             \\\n  -D CMAKE_Swift_COMPILER=$(which swiftc) \\\n  -G Ninja                                \\\n  -S /SourceCache/tensorflow-swift-models\n# Build\ncmake --build /BinaryCache/tensorflow-swift-models\n```\n\nWindows:\n\n```\nset DEVELOPER_LIBRARY_DIR=%SystemDrive%/Library/Developer/Platforms/Windows.platform/Developer/Library\n:: Configure\n\"%ProgramFiles%\\CMake\\bin\\cmake.exe\"                                                                                                                                                   ^\n  -B %SystemDrive%/BinaryCache/tensorflow-swift-models                                                                                                                                 ^\n  -D BUILD_SHARED_LIBS=YES                                                                                                                                                             ^\n  -D BUILD_TESTING=YES                                                                                                                                                                 ^\n  -D CMAKE_BUILD_TYPE=Release                                                                                                                                                          ^\n  -D CMAKE_Swift_COMPILER=%SystemDrive%/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe                                                        ^\n  -D CMAKE_Swift_FLAGS=\"-sdk %SDKROOT% -I %DEVELOPER_LIBRARY_DIR%/XCTest-development/usr/lib/swift/windows/x86_64 -L %DEVELOPER_LIBRARY_DIR%/XCTest-development/usr/lib/swift/windows\" ^\n  -G Ninja                                                                                                                                                                             ^\n  -S %SystemDrive%/SourceCache/tensorflow-swift-models\n:: Build\n\"%ProgramFiles%\\CMake\\bin\\cmake.exe\" --build %SystemDrive%/BinaryCache/tensorflow-swift-models\n:: Test\n\"%ProgramFiles%\\CMake\\bin\\cmake.exe\" --build %SystemDrive%/BinaryCache/tensorflow-swift-models --target test\n```\n\n## Bugs\n\nPlease report model-related bugs and feature requests using GitHub issues in\nthis repository.\n\n## Community\n\nDiscussion about Swift for TensorFlow happens on the\n[swift@tensorflow.org](https://groups.google.com/a/tensorflow.org/d/forum/swift)\nmailing list.\n\n## Contributing\n\nWe welcome contributions: please read the [Contributor Guide](CONTRIBUTING.md)\nto get started. It's always a good idea to discuss your plans on\n[the mailing list](https://groups.google.com/a/tensorflow.org/d/forum/swift) before making\nany major submissions.\n\nWe have labeled some issues as [\"good first issue\"](https://github.com/tensorflow/swift-models/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)\nor [\"help wanted\"](https://github.com/tensorflow/swift-models/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)\nto provide some suggestions for where new contributors might be able to start.\n\n## Code of Conduct\n\nIn the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, gender identity and expression, level of\nexperience, education, socio-economic status, nationality, personal appearance,\nrace, religion, or sexual identity and orientation.\n\nThe Swift for TensorFlow community is guided by our [Code of\nConduct](CODE_OF_CONDUCT.md), which we encourage everybody to read before\nparticipating.\n","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fswift-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensorflow%2Fswift-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fswift-models/lists"}