Code Examples¶
This section describes the code examples found in objax/examples
Classification¶
Image¶
Example code available at examples/classify
.
examples/classify/img/logistic.py
¶
Train and evaluate a logistic regression model for binary classification on horses or humans dataset.
# Run command
python3 examples/classify/img/logistic.py
Data |
horses_or_humans from tensorflow_datasets |
Network |
Custom single layer |
Loss |
|
Optimizer |
|
Accuracy |
~77% |
Hardware |
CPU or GPU or TPU |
examples/classify/img/mnist_dnn.py
¶
Train and evaluate a DNNet model for multiclass classification on the MNIST dataset.
# Run command
python3 examples/classify/img/mnist_dnn.py
Data |
MNIST from tensorflow_datasets |
Network |
Deep Neural Net |
Loss |
|
Optimizer |
|
Accuracy |
~98% |
Hardware |
CPU or GPU or TPU |
Techniques |
Model weight averaging for improved accuracy using
|
examples/classify/img/mnist_cnn.py
¶
Train and evaluate a simple custom CNN model for multiclass classification on the MNIST dataset.
# Run command
python3 examples/classify/img/mnist_cnn.py
Data |
MNIST from tensorflow_datasets |
Network |
Custom Convolution Neural Net using |
Loss |
|
Optimizer |
|
Accuracy |
~99.5% |
Hardware |
CPU or GPU or TPU |
Techniques |
|
examples/classify/img/mnist_dp.py
¶
Train and evaluate a convNet model for MNIST dataset with differential privacy.
# Run command
python3 examples/classify/img/mnist_dp.py
# See available options with
python3 examples/classify/img/mnist_dp.py --help
Data |
MNIST from tensorflow_datasets |
Network |
Custom Convolution Neural Net using |
Loss |
|
Optimizer |
|
Accuracy |
|
Hardware |
GPU |
Techniques |
|
examples/classify/img/cifar10_simple.py
¶
Train and evaluate a wide resnet model for multiclass classification on the CIFAR10 dataset.
# Run command
python3 examples/classify/img/cifar10_simple.py
Data |
CIFAR10 from tf.keras.datasets |
Network |
Wide ResNet using |
Loss |
|
Optimizer |
|
Accuracy |
~91% |
Hardware |
GPU or TPU |
Techniques |
|
examples/classify/img/cifar10_advanced.py
¶
Train and evaluate convNet models for multiclass classification on the CIFAR10 dataset.
# Run command
python3 examples/classify/img/cifar10_advanced.py
# Run with custom settings
python3 examples/classify/img/cifar10_advanced.py --weight_decay=0.0001 --batch=64 --lr=0.03 --epochs=256
# See available options with
python3 examples/classify/img/cifar10_advanced.py --help
Data |
|
Network |
Configurable with |
Loss |
|
Optimizer |
|
Accuracy |
~94% |
Hardware |
GPU, Multi-GPU or TPU |
Techniques |
|
examples/classify/img/imagenet/imagenet_train.py
¶
Train and evaluate a ResNet50 model on the ImageNet dataset.
See examples/classify/img/imagenet/README.md
for additional information.
Data |
|
Network |
|
Loss |
|
Optimizer |
|
Accuracy |
|
Hardware |
GPU, Multi-GPU or TPU |
Techniques |
|
Semi-Supervised Learning¶
Example code available at examples/semi_supervised
.
examples/semi_supervised/img/fixmatch.py
¶
Semi-supervised learning of image classification models with FixMatch.
# Run command
python3 examples/classify/semi_supervised/img/fixmatch.py
# Run with custom settings
python3 examples/classify/semi_supervised/img/fixmatch.py --dataset=cifar10.3@1000-0
# See available options with
python3 examples/classify/semi_supervised/img/fixmatch.py --help
Data |
|
Network |
Custom implementation of Wide ResNet. |
Loss |
|
Optimizer |
|
Accuracy |
See paper |
Hardware |
GPU, Multi-GPU, TPU |
Techniques |
|
GPT-2¶
Example code available at examples/gpt-2
.
examples/gpt-2/gpt2.py
¶
Load pretrained GPT2
model (124M parameter) and demonstrate how to use the model to generate a text sequence.
See examples/gpt-2/README.md
for additional information.
Hardware |
GPU or TPU |
Techniques |
|
RNN¶
Example code is available at examples/rnn
.
examples/rnn/shakespeare.py
¶
Train and evaluate a vanilla RNN model on the Shakespeare corpus dataset.
See examples/rnn/README.md
for additional information.
# Run command
python3 examples/rnn/shakespeare.py
Data |
|
Network |
Custom implementation of vanilla RNN. |
Loss |
|
Optimizer |
|
Hardware |
GPU or TPU |
Techniques |
|
Optimization¶
Example codes available at examples/optimization
.