Image inpainting over CIFAR-10¶
The purpose of this project is to build and train a neural network for image inpainting over the CIFAR-10 dataset.
Inpainting is a restauration process where damaged, deteriorated, or missing parts of an artwork are filled in to present a complete image.
In our case, we create the portion of the image to be filled in by cropping a fixed size rectangular area from CIFAR-10 images.
The networks must be trained over the training set, and tested on the test set. You can split the train set into a validation set, if you wish.
The metrics that will be used to evaluate you result is Mean Square Error.
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras import layers, models, metrics
from tensorflow.keras.datasets import cifar10
Here we load the dataset.
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print("image range is {}, {}".format(np.min(x_test,axis=(0,1,2,3)),np.max(x_test,axis=(0,1,2,3))))
x_train = (x_train/255.).astype(np.float32)
x_test = (x_test/255.).astype(np.float32)
print("new image range is {}, {}".format(np.min(x_test,axis=(0,1,2,3)),np.max(x_test,axis=(0,1,2,3))))
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz 170498071/170498071 [==============================] - 14s 0us/step image range is 0, 255 new image range is 0.0, 1.0
Let's see some examples.
plt.imshow(x_test[1])
plt.show()
Now we hide a portion of the input, and the purpose of the network is to reconstruct it.
def mask(X,coords):
x0,y0,x1,y1 = coords
X[:,x0:x1,y0:y1] = 0
return X
masked_x_train = mask(np.copy(x_train),(2,16,30,30))
masked_x_test = mask(np.copy(x_test),(2,16,30,30))
plt.imshow(masked_x_test[1])
plt.show()
Approaches and evaluation¶
The network is supposed to take in input the masked image and fill in the missing part.
You may basically follow two main approaches:
- either you return the full image
- you just return the missing crop
In the first case, the mse is to be evaluated on the full image; in the second case just on the crop (since on the reamining part is 0).
If you want to take a different approach, you can ask for my approuval.
What to deliver¶
As usual, you are supposed to deliver a single notebook comprising the code, the training history, and the evaluation on test data in terms of Mean Square Error.
Good work!