text stringlengths 0 4.99k |
|---|
187/187 - 31s - loss: 0.6823 - accuracy: 0.7880 - val_loss: 0.7814 - val_accuracy: 0.7872 |
Epoch 7/10 |
187/187 - 31s - loss: 0.6536 - accuracy: 0.7953 - val_loss: 0.7850 - val_accuracy: 0.7873 |
Epoch 8/10 |
187/187 - 31s - loss: 0.6104 - accuracy: 0.8111 - val_loss: 0.7774 - val_accuracy: 0.7879 |
Epoch 9/10 |
187/187 - 32s - loss: 0.5990 - accuracy: 0.8067 - val_loss: 0.7925 - val_accuracy: 0.7870 |
Epoch 10/10 |
187/187 - 31s - loss: 0.5531 - accuracy: 0.8239 - val_loss: 0.7870 - val_accuracy: 0.7836 |
png |
Tips for fine tuning EfficientNet |
On unfreezing layers: |
The BathcNormalization layers need to be kept frozen (more details). If they are also turned to trainable, the first epoch after unfreezing will significantly reduce accuracy. |
In some cases it may be beneficial to open up only a portion of layers instead of unfreezing all. This will make fine tuning much faster when going to larger models like B7. |
Each block needs to be all turned on or off. This is because the architecture includes a shortcut from the first layer to the last layer for each block. Not respecting blocks also significantly harms the final performance. |
Some other tips for utilizing EfficientNet: |
Larger variants of EfficientNet do not guarantee improved performance, especially for tasks with less data or fewer classes. In such a case, the larger variant of EfficientNet chosen, the harder it is to tune hyperparameters. |
EMA (Exponential Moving Average) is very helpful in training EfficientNet from scratch, but not so much for transfer learning. |
Do not use the RMSprop setup as in the original paper for transfer learning. The momentum and learning rate are too high for transfer learning. It will easily corrupt the pretrained weight and blow up the loss. A quick check is to see if loss (as categorical cross entropy) is getting significantly larger than log(NUM_C... |
Smaller batch size benefit validation accuracy, possibly due to effectively providing regularization. |
Using the latest EfficientNet weights |
Since the initial paper, the EfficientNet has been improved by various methods for data preprocessing and for using unlabelled data to enhance learning results. These improvements are relatively hard and computationally costly to reproduce, and require extra code; but the weights are readily available in the form of TF... |
To use a checkpoint provided at the official model repository, first download the checkpoint. As example, here we download noisy-student version of B1: |
!wget https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet\ |
/noisystudent/noisy_student_efficientnet-b1.tar.gz |
!tar -xf noisy_student_efficientnet-b1.tar.gz |
Then use the script efficientnet_weight_update_util.py to convert ckpt file to h5 file. |
!python efficientnet_weight_update_util.py --model b1 --notop --ckpt \ |
efficientnet-b1/model.ckpt --o efficientnetb1_notop.h5 |
When creating model, use the following to load new weight: |
model = EfficientNetB1(weights=\"efficientnetb1_notop.h5\", include_top=False) |
An all-convolutional network applied to patches of images. |
Introduction |
Vision Transformers (ViT; Dosovitskiy et al.) extract small patches from the input images, linearly project them, and then apply the Transformer (Vaswani et al.) blocks. The application of ViTs to image recognition tasks is quickly becoming a promising area of research, because ViTs eliminate the need to have strong in... |
In the Patches Are All You Need paper (note: at the time of writing, it is a submission to the ICLR 2022 conference), the authors extend the idea of using patches to train an all-convolutional network and demonstrate competitive results. Their architecture namely ConvMixer uses recipes from the recent isotrophic archit... |
In this example, we will implement the ConvMixer model and demonstrate its performance on the CIFAR-10 dataset. |
To use the AdamW optimizer, we need to install TensorFlow Addons: |
pip install -U -q tensorflow-addons |
Imports |
from tensorflow.keras import layers |
from tensorflow import keras |
import matplotlib.pyplot as plt |
import tensorflow_addons as tfa |
import tensorflow as tf |
import numpy as np |
Hyperparameters |
To keep run time short, we will train the model for only 10 epochs. To focus on the core ideas of ConvMixer, we will not use other training-specific elements like RandAugment (Cubuk et al.). If you are interested in learning more about those details, please refer to the original paper. |
learning_rate = 0.001 |
weight_decay = 0.0001 |
batch_size = 128 |
num_epochs = 10 |
Load the CIFAR-10 dataset |
(x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data() |
val_split = 0.1 |
val_indices = int(len(x_train) * val_split) |
new_x_train, new_y_train = x_train[val_indices:], y_train[val_indices:] |
x_val, y_val = x_train[:val_indices], y_train[:val_indices] |
print(f\"Training data samples: {len(new_x_train)}\") |
print(f\"Validation data samples: {len(x_val)}\") |
print(f\"Test data samples: {len(x_test)}\") |
Training data samples: 45000 |
Validation data samples: 5000 |
Test data samples: 10000 |
Prepare tf.data.Dataset objects |
Our data augmentation pipeline is different from what the authors used for the CIFAR-10 dataset, which is fine for the purpose of the example. |
image_size = 32 |
auto = tf.data.AUTOTUNE |
data_augmentation = keras.Sequential( |
[layers.RandomCrop(image_size, image_size), layers.RandomFlip(\"horizontal\"),], |
name=\"data_augmentation\", |
) |
def make_datasets(images, labels, is_train=False): |
dataset = tf.data.Dataset.from_tensor_slices((images, labels)) |
if is_train: |
dataset = dataset.shuffle(batch_size * 10) |
dataset = dataset.batch(batch_size) |
if is_train: |
dataset = dataset.map( |
lambda x, y: (data_augmentation(x), y), num_parallel_calls=auto |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.