text stringlengths 0 4.99k |
|---|
output = model.predict(image) |
output_image = output[0] * 255.0 |
output_image = output_image.clip(0, 255) |
output_image = output_image.reshape( |
(np.shape(output_image)[0], np.shape(output_image)[1], 3) |
) |
output_image = Image.fromarray(np.uint8(output_image)) |
original_image = Image.fromarray(np.uint8(original_image)) |
return output_image |
Inference on Test Images |
We compare the test images from LOLDataset enhanced by MIRNet with images enhanced via the PIL.ImageOps.autocontrast() function. |
for low_light_image in random.sample(test_low_light_images, 6): |
original_image = Image.open(low_light_image) |
enhanced_image = infer(original_image) |
plot_results( |
[original_image, ImageOps.autocontrast(original_image), enhanced_image], |
[\"Original\", \"PIL Autocontrast\", \"MIRNet Enhanced\"], |
(20, 12), |
) |
png |
png |
png |
png |
png |
png |
Implementing Masked Autoencoders for self-supervised pretraining. |
Introduction |
In deep learning, models with growing capacity and capability can easily overfit on large datasets (ImageNet-1K). In the field of natural language processing, the appetite for data has been successfully addressed by self-supervised pretraining. |
In the academic paper Masked Autoencoders Are Scalable Vision Learners by He et. al. the authors propose a simple yet effective method to pretrain large vision models (here ViT Huge). Inspired from the pretraining algorithm of BERT (Devlin et al.), they mask patches of an image and, through an autoencoder predict the m... |
In this example, we implement Masked Autoencoders Are Scalable Vision Learners with the CIFAR-10 dataset. After pretraining a scaled down version of ViT, we also implement the linear evaluation pipeline on CIFAR-10. |
This implementation covers (MAE refers to Masked Autoencoder): |
The masking algorithm |
MAE encoder |
MAE decoder |
Evaluation with linear probing |
As a reference, we reuse some of the code presented in this example. |
Imports |
This example requires TensorFlow Addons, which can be installed using the following command: |
pip install -U tensorflow-addons |
from tensorflow.keras import layers |
import tensorflow_addons as tfa |
from tensorflow import keras |
import tensorflow as tf |
import matplotlib.pyplot as plt |
import numpy as np |
import random |
# Setting seeds for reproducibility. |
SEED = 42 |
keras.utils.set_random_seed(SEED) |
Hyperparameters for pretraining |
Please feel free to change the hyperparameters and check your results. The best way to get an intuition about the architecture is to experiment with it. Our hyperparameters are heavily inspired by the design guidelines laid out by the authors in the original paper. |
# DATA |
BUFFER_SIZE = 1024 |
BATCH_SIZE = 256 |
AUTO = tf.data.AUTOTUNE |
INPUT_SHAPE = (32, 32, 3) |
NUM_CLASSES = 10 |
# OPTIMIZER |
LEARNING_RATE = 5e-3 |
WEIGHT_DECAY = 1e-4 |
# PRETRAINING |
EPOCHS = 100 |
# AUGMENTATION |
IMAGE_SIZE = 48 # We will resize input images to this size. |
PATCH_SIZE = 6 # Size of the patches to be extracted from the input images. |
NUM_PATCHES = (IMAGE_SIZE // PATCH_SIZE) ** 2 |
MASK_PROPORTION = 0.75 # We have found 75% masking to give us the best results. |
# ENCODER and DECODER |
LAYER_NORM_EPS = 1e-6 |
ENC_PROJECTION_DIM = 128 |
DEC_PROJECTION_DIM = 64 |
ENC_NUM_HEADS = 4 |
ENC_LAYERS = 6 |
DEC_NUM_HEADS = 4 |
DEC_LAYERS = ( |
2 # The decoder is lightweight but should be reasonably deep for reconstruction. |
) |
ENC_TRANSFORMER_UNITS = [ |
ENC_PROJECTION_DIM * 2, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.