This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Add JPEG loading / saving via Raw TF operations, removing Matplotlib dependencies #188
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… matplotlib dependency from GAN and Autoencoder examples using this.
rxwei
reviewed
Aug 20, 2019
Good call on making failure of directory creation throw. I believe I've incorporated the remainder of the changes here. |
rxwei
reviewed
Aug 20, 2019
rxwei
approved these changes
Aug 20, 2019
ematejska
added a commit
that referenced
this pull request
Sep 24, 2019
* Use PascalCase for all Swift source files (#152) Except `main.swift` files which are the entry points for executables. Running the following command does not produce any output: `find . -type f -name "[[:lower:]]*.swift" | rg --pcre2 "^(?!.*(main.swift))"` Resolves #133. * Load config variable from `hparams.json` file so that Transformer can work with the bigger GPT-2 models (It is called "staged release". as of now, only 117M and 345M are available). (#154) * Style fixes from #154 (#155) * A few quick fixes to help unbreak swift-models. (#160) * Unbreak models by inserting `.call`. (#161) See https://bugs.swift.org/browse/TF-516 for additional context. * s/CotangentVector/TangentVector/g (#162) * Add MNIST test set evaluation and change hyperparameters. (#163) - Add MNIST test set evaluation. - The batch size and the optimizer are changed to `128` and `Adam`, respectively, based on test set evaluation results. Tested with higher batch sizes [256, 512], but found no improvement in performance. * Updated models to use revised name for callable (SE-0253), fixed a few issues caused by `swift-apis` changes. (#166) * Updated Transformer and MNIST models to work with 2019-06-04 development snapshot. * Updated other models. * Updated ResNet to work with 2019-06-04 development snapshot. * Updated Catch and CIFAR models. * Added a method to satisfy TensorGroup protocol that can pass build. * transformer: upstream api changes (#171) * rebuild resnet block based approach (#170) * add gym blackjack qlearning demo (#173) * Make 'GoModel' stored properties be variables. (#174) New 'Differentiable' derived conformances will not include constant properties in the tangent space. * Added .swift-format and updated .gitignore for Xcode 11's SwiftPM support. (#176) This replicates the following pull request on swift-apis: tensorflow/swift-apis#374 , adding a `swift-format` configuration file. Note the cautions indicated in that pull request around use of `swift-format` at present. This also adds a .gitignore line to prevent Xcode 11's new SwiftPM support from adding supporting files to the repository. * Replaced Python with Swift in CIFAR10 dataset loading (#178) * Replaced all Python code in the CIFAR10 and ResNet examples, removing Python 3 dependency. * Needed to import FoundationNetworking on Linux. * Added a check for FoundationNetworking, added an early exit for cached directory check. * Removed macOS availability check by targeting 10.13 in the package. * Style and formatting fixes. * Removed no-longer-needed _tensorHandles and supporting code. * Replace Autoencoder's tanh activation with sigmoid (#180) * Add GAN Example (#181) * Add GAN Example * Remove do blocks * Replace lrelu with closure * Remove typealiases * Add comment * Remove labels in GAN example * Rename variables * Code formatting, update comments * Fix: latentDim -> latentSize * Add spaces around * * Code formatting, rename loss functions * Fix: generatorLossFunc -> generatorLoss * Break lines to make it fit within 100 columns * Update comments * Rename plot->plotImage, imageGrid->gridImage, Code formatting * Refactor: Label creation * Update comment * Remove type parameter, empty line * Update readme * nightlies URL: s4tf-kokoro-artifact-testing => swift-tensorflow-artifacts (#183) * First steps in repository reorganization: extracting common MNIST dataset code (#182) * Extracted MNIST dataset, created LeNet network, added example combining the two. * Extracted redundant MNIST loading code from GAN and Autoencoder examples, replaced with central MNIST dataset. * Renamed input parameters and applied standard formatting style to MNIST. * Punctuation correction. Co-Authored-By: Richard Wei <[email protected]> * README formatting update. Co-Authored-By: Richard Wei <[email protected]> * Renamed trainImages -> trainingImages, corrected Python package names, formatted Package.swift. * Update Dockerfile to install Python libraries (#184) * Delete helpers.swift (#187) This file is no longer needed apple/swift #26023 and may be causing the segfault reported in swift-apis #186. * Continuing repository reorganization: extracting common CIFAR-10 and ResNet code (#185) * Extracted CIFAR-10 dataset and ResNet models into respective modules. * Minor formatting fixes. * Mirroring PR #187. * [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` `init` (#192) * [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` initialization * Start range at * Update ranges * SqueezeNet Implementation (#189) * Add files via upload * Implemented requested changes Corrected formatting mistakes, used dropout correctly, removed the hard coded number of classes and improved overall readability. * Update SqeezeNet.swift Renamed numClasses to classCount and limited all lines to a size of 100. * WideResNet - fix widenFactor and match model to citation (#193) * add identity connections to WideResNet * rename preact1 for clarity * remove extra relu, add dropout * fix declarartion * skip dropout in expansion blocks * remove enum, res layers to one line * Removal of deprecated allDifferentiableVariables. (#194) * Add JPEG loading / saving via Raw TF operations, removing Matplotlib dependencies (#188) * Added an Image struct as a wrapper for JPEG loading / saving, removed matplotlib dependency from GAN and Autoencoder examples using this. * Formatting update for Autoencoder. * Bring this inline with current API. * Made saveImage() a throwing function, improved formatting. * Changed function parameter. * Convert MNIST classifier to use sequential (#200) * Convert MNIST classifier to use sequential * Review Changes * Remove ImageClassification Models * Convert Autoencoder and Catch to use Sequential (#203) Partially fixes #202. * Adding shape-based inference tests for all image classification models (#198) * Implemented inference tests with random tensors and starting weights for all classification models. * Made sure tests ran on Linux, reshaped output of SqueezeNet to match other classification models. * WideResNet is expressed in terms of CIFAR10, so altered the inputs and outputs appropriately. * Wrapping the reshaping line in SqueezeNet. * Reset ownership. * Reworked TensorShape initializers to use array literals. * Minor formatting tweak to SqueezeNet. * Update deprecated APIs in Catch (#205) [swift-apis/#497](tensorflow/swift-apis#497) removes deprecated apis, now that we are moving onward to v0.5. This PR updates the catch file which uses a deprecated dense layer. * Update squeezenet and add V1.1 version (#204) * Update squeezenet and add V1.1 version * value error * Update tests * review changes * Fix '@noDerivative' warnings. (#208) (#209) (cherry picked from commit db72e4d)
BradLarson
added a commit
that referenced
this pull request
Nov 22, 2019
* Use PascalCase for all Swift source files (#152) Except `main.swift` files which are the entry points for executables. Running the following command does not produce any output: `find . -type f -name "[[:lower:]]*.swift" | rg --pcre2 "^(?!.*(main.swift))"` Resolves #133. * Load config variable from `hparams.json` file so that Transformer can work with the bigger GPT-2 models (It is called "staged release". as of now, only 117M and 345M are available). (#154) * Style fixes from #154 (#155) * A few quick fixes to help unbreak swift-models. (#160) * Unbreak models by inserting `.call`. (#161) See https://bugs.swift.org/browse/TF-516 for additional context. * s/CotangentVector/TangentVector/g (#162) * Add MNIST test set evaluation and change hyperparameters. (#163) - Add MNIST test set evaluation. - The batch size and the optimizer are changed to `128` and `Adam`, respectively, based on test set evaluation results. Tested with higher batch sizes [256, 512], but found no improvement in performance. * Updated models to use revised name for callable (SE-0253), fixed a few issues caused by `swift-apis` changes. (#166) * Updated Transformer and MNIST models to work with 2019-06-04 development snapshot. * Updated other models. * Updated ResNet to work with 2019-06-04 development snapshot. * Updated Catch and CIFAR models. * Added a method to satisfy TensorGroup protocol that can pass build. * transformer: upstream api changes (#171) * rebuild resnet block based approach (#170) * add gym blackjack qlearning demo (#173) * Make 'GoModel' stored properties be variables. (#174) New 'Differentiable' derived conformances will not include constant properties in the tangent space. * Added .swift-format and updated .gitignore for Xcode 11's SwiftPM support. (#176) This replicates the following pull request on swift-apis: tensorflow/swift-apis#374 , adding a `swift-format` configuration file. Note the cautions indicated in that pull request around use of `swift-format` at present. This also adds a .gitignore line to prevent Xcode 11's new SwiftPM support from adding supporting files to the repository. * Replaced Python with Swift in CIFAR10 dataset loading (#178) * Replaced all Python code in the CIFAR10 and ResNet examples, removing Python 3 dependency. * Needed to import FoundationNetworking on Linux. * Added a check for FoundationNetworking, added an early exit for cached directory check. * Removed macOS availability check by targeting 10.13 in the package. * Style and formatting fixes. * Removed no-longer-needed _tensorHandles and supporting code. * Replace Autoencoder's tanh activation with sigmoid (#180) * Add GAN Example (#181) * Add GAN Example * Remove do blocks * Replace lrelu with closure * Remove typealiases * Add comment * Remove labels in GAN example * Rename variables * Code formatting, update comments * Fix: latentDim -> latentSize * Add spaces around * * Code formatting, rename loss functions * Fix: generatorLossFunc -> generatorLoss * Break lines to make it fit within 100 columns * Update comments * Rename plot->plotImage, imageGrid->gridImage, Code formatting * Refactor: Label creation * Update comment * Remove type parameter, empty line * Update readme * nightlies URL: s4tf-kokoro-artifact-testing => swift-tensorflow-artifacts (#183) * First steps in repository reorganization: extracting common MNIST dataset code (#182) * Extracted MNIST dataset, created LeNet network, added example combining the two. * Extracted redundant MNIST loading code from GAN and Autoencoder examples, replaced with central MNIST dataset. * Renamed input parameters and applied standard formatting style to MNIST. * Punctuation correction. Co-Authored-By: Richard Wei <[email protected]> * README formatting update. Co-Authored-By: Richard Wei <[email protected]> * Renamed trainImages -> trainingImages, corrected Python package names, formatted Package.swift. * Update Dockerfile to install Python libraries (#184) * Delete helpers.swift (#187) This file is no longer needed apple/swift #26023 and may be causing the segfault reported in swift-apis #186. * Continuing repository reorganization: extracting common CIFAR-10 and ResNet code (#185) * Extracted CIFAR-10 dataset and ResNet models into respective modules. * Minor formatting fixes. * Mirroring PR #187. * [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` `init` (#192) * [Models] Fix enumeration of blocks in `ResidualBasicBlockStack` initialization * Start range at * Update ranges * SqueezeNet Implementation (#189) * Add files via upload * Implemented requested changes Corrected formatting mistakes, used dropout correctly, removed the hard coded number of classes and improved overall readability. * Update SqeezeNet.swift Renamed numClasses to classCount and limited all lines to a size of 100. * WideResNet - fix widenFactor and match model to citation (#193) * add identity connections to WideResNet * rename preact1 for clarity * remove extra relu, add dropout * fix declarartion * skip dropout in expansion blocks * remove enum, res layers to one line * Removal of deprecated allDifferentiableVariables. (#194) * Add JPEG loading / saving via Raw TF operations, removing Matplotlib dependencies (#188) * Added an Image struct as a wrapper for JPEG loading / saving, removed matplotlib dependency from GAN and Autoencoder examples using this. * Formatting update for Autoencoder. * Bring this inline with current API. * Made saveImage() a throwing function, improved formatting. * Changed function parameter. * Convert MNIST classifier to use sequential (#200) * Convert MNIST classifier to use sequential * Review Changes * Remove ImageClassification Models * Convert Autoencoder and Catch to use Sequential (#203) Partially fixes #202. * Adding shape-based inference tests for all image classification models (#198) * Implemented inference tests with random tensors and starting weights for all classification models. * Made sure tests ran on Linux, reshaped output of SqueezeNet to match other classification models. * WideResNet is expressed in terms of CIFAR10, so altered the inputs and outputs appropriately. * Wrapping the reshaping line in SqueezeNet. * Reset ownership. * Reworked TensorShape initializers to use array literals. * Minor formatting tweak to SqueezeNet. * Update deprecated APIs in Catch (#205) [swift-apis/#497](tensorflow/swift-apis#497) removes deprecated apis, now that we are moving onward to v0.5. This PR updates the catch file which uses a deprecated dense layer. * Update squeezenet and add V1.1 version (#204) * Update squeezenet and add V1.1 version * value error * Update tests * review changes * Fix '@noDerivative' warnings. (#208) * Indentation and formatting fixes in CartPole (#214) * DenseNet Implementaion (#213) * Create DenseNet.swift Implementation for the DenseNet Architecture * Added test for DenseNet * Fixed Typo * Refractored the code * Updated ConvPair description Co-Authored-By: Richard Wei <[email protected]> * Fixed comment Co-Authored-By: Richard Wei <[email protected]> * Fixed typos, and improved code quality * Removed extra whitespace and '\' * Used 3 '/' for documentation and removed return * Renamed DenseNet to DenseNet121 * Renamed tests * Updated names * Renamed all DenseNet identifiers to DenseNet121 * Download MNIST dataset from remote URL (#215) This PR is intended to fix the second item listed in [this issue](#206): > it currently relies on hardcoded paths, which will break if you take the dataset outside of that project and try to use it in something like Colab. In this PR, the datasets are instead downloaded from a remote URL, so they are not fragile with respect to the current working directory where the MNIST dataset is instantiated from. The implementation in this PR brings the MINST dataset in line with how the CFAR10 dataset is loaded. * use enable in _vjpCausallyMasked (#218) Fixes #217 * Change momentum and epsilon properties to scalars. (#220) * Uses switch instead of ifs (#219) * Fixes deprecation warning in MiniGo (#221) * Fixing deprecation warnings on all but the MiniGo example. (#223) * Initial training and inference benchmarks (#222) * Initial implementation of training and inference benchmarks. * Resolved a typechecker issue. * Added a Readme. * Added copyright headers. * Reworked the benchmarking functions to use a single function that is specialized via enums. * Reworked the model-specific benchmark into general inference and training cases that can work on arbitrary image classification models. * Restructured BenchmarkResults to be a plain collection of timings, with specific benchmark processing working on that. * Rename interpretTimings to interpretedTimings. Co-Authored-By: Dan Zheng <[email protected]> * Change reference to interpretedTimings later.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a wrapper Image struct for encapsulating JPEG (and potentially other formats) image loading and saving, using Raw TensorFlow operators. This allows for JPEG loading and saving without any external dependencies.
To date, Matplotlib had been used for image export, but this provides a means of performing this directly in Swift. As a result, the Matplotlib (and Python, in general) dependencies have been removed for the Autoencoder and GAN examples.
This is a first step for providing general image dataset loading for training and tests.