In [7]:
import matplotlib.image as mpimg
import matplotlib.pylab as plt
import numpy as np
%matplotlib inline
im = mpimg.imread("data/monalisa.jpg")
plt.imshow(im)
plt.show()
im.shape
Out[7]:
Ourt training dataset will be composed of pixels locatiions and input and pixel values as output:
In [8]:
X_train = []
Y_train = []
for i in range(im.shape[0]):
for j in range(im.shape[1]):
X_train.append([float(i),float(j)])
Y_train.append(im[i][j])
X_train = np.array(X_train)
Y_train = np.array(Y_train)
print 'Samples:', X_train.shape[0]
print '(x,y):', X_train[0],'\n', '(r,g,b):',Y_train[0]
Our objective is to train a deep MLP that is able to reconstruct the image:
In [ ]:
import keras
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout
# your model here
# hints: k*10^2 neurons per layer + good initialization + deep network (>2 layers)
In [ ]:
# use this cell to find the best model architecture
model.fit(X_train, Y_train, nb_epoch=1, shuffle=True, verbose=1, batch_size=10)
Y = model.predict(X_train, batch_size=10000)
k = 0
im_out = im[:]
for i in range(im.shape[0]):
for j in range(im.shape[1]):
im_out[i,j]= Y[k]
k += 1
plt.imshow(im_out)
plt.show()