0% found this document useful (0 votes)
4 views5 pages

Mini 3

The document loads grayscale and color image data and splits it into training and non-seen test data. It then processes the data and trains an autoencoder model to colorize grayscale images, comparing the output images to the original color images.

Uploaded by

shellierathee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Mini 3

The document loads grayscale and color image data and splits it into training and non-seen test data. It then processes the data and trains an autoencoder model to colorize grayscale images, comparing the output images to the original color images.

Uploaded by

shellierathee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DEEP LEARNING

MINI-PROJECT 3
BY MEGHA KUMARI (7435)
In [4]: Gray_NPY = np.load("../input/image-colorization/l/gray_scale.npy")
AB_1_NPY = np.load("../input/image-colorization/ab/ab/ab1.npy")

In [5]: print(type(Gray_NPY))
print(type(AB_1_NPY))

<class 'numpy.ndarray'>
<class 'numpy.ndarray'>

In [6]: print(Gray_NPY.shape)
print(AB_1_NPY.shape)

(25000, 224, 224)


(10000, 224, 224, 2)

In [7]: splitting_count = 300


end_splitting_count = 600

In [8]: X_Train = Gray_NPY[:splitting_count,:,:].astype("float32").reshape(splitting_count,


Gray_NPY.shape[1],
Gray_NPY.shape[2])

In [9]: X_Non_Seen = Gray_NPY[splitting_count:end_splitting_count,:,:].astype("float32").reshape(splitting_count,


Gray_NPY.shape[1],
Gray_NPY.shape[2])

In [10]: Y_Train = AB_1_NPY[:splitting_count,:,:].astype("float32")

In [11]: print(X_Train.shape)
print(X_Non_Seen.shape)
print(Y_Train.shape)

(300, 224, 224)


(300, 224, 224)
(300, 224, 224, 2)

In [12]: def line_image(gray_images,splitting_count=splitting_count,preprocess_function=preprocess_input):


Zeros_Imp = np.zeros((splitting_count,224,224,3))
for indexing in range(0,3):
Zeros_Imp[:splitting_count,:,:,indexing] = gray_images[:splitting_count]

return preprocess_function(Zeros_Imp)

In [13]: Input_Images = line_image(X_Train,splitting_count)

In [14]: Non_Seen_Input = line_image(X_Non_Seen,splitting_count)

In [15]: print(Input_Images.shape)

(300, 224, 224, 3)

In [16]: print(Non_Seen_Input.shape)

(300, 224, 224, 3)

In [23]: print(Y_Train[:,:,:,1:].shape)

(300, 224, 224, 1)

In [24]: print(Y_Train[:,:,:,1:][2].shape)

(224, 224, 1)

In [25]: X_Train_Testing = np.zeros(shape=(splitting_count,224,224,3))

for indexing in range(len(Y_Train)):


X_Train_Testing[:,:,:,0][indexing] = X_Train[:,:,:][indexing]
X_Train_Testing[:,:,:,1:][indexing] = Y_Train[:,:,:,:][indexing]

X_Train_Testing = X_Train_Testing.astype("uint8")
In [26]: plt.imshow(X_Train_Testing[30]) # LAB

<matplotlib.image.AxesImage at 0x7c6b774f5690>
Out[26]:

In [27]: print(X_Train_Testing.shape)

(300, 224, 224, 3)

In [28]: Main_Img_Testing = []

for indexing in range(0,splitting_count):


Main_Img_Testing.append(cv2.cvtColor(X_Train_Testing[indexing],cv2.COLOR_LAB2RGB))

In [29]: plt.imshow(Main_Img_Testing[30]) # RGB

<matplotlib.image.AxesImage at 0x7c6b7746e0e0>
Out[29]:

In [30]: figure,axis = plt.subplots(1,2,figsize=(10,10))

axis[0].imshow(Output_Images[123])
axis[1].imshow(Input_Images[123])

<matplotlib.image.AxesImage at 0x7c6b770bca30>
Out[30]:
In [31]: figure,axis = plt.subplots(1,2,figsize=(10,10))

axis[0].imshow(Output_Images[10])
axis[1].imshow(X_Train[10],cmap="gray")

<matplotlib.image.AxesImage at 0x7c6b770eaf50>
Out[31]:

In [32]: figure,axis = plt.subplots(1,2,figsize=(10,10))

axis[0].imshow(Output_Images[100])
axis[1].imshow(X_Train[100],cmap="gray")

<matplotlib.image.AxesImage at 0x7c6a9e263fa0>
Out[32]:
In [33]: figure,axis = plt.subplots(1,2,figsize=(10,10))

axis[0].imshow(Output_Images[200])
axis[1].imshow(X_Train[200],cmap="gray")

<matplotlib.image.AxesImage at 0x7c6a9e15f280>
Out[33]:

In [46]: figure,axis = plt.subplots(1,2,figsize=(10,10))


prediction_img_number = 2

Original_Img = Non_Seen_Input[prediction_img_number]
Predict_Image_AE = Prediction_Non_Seen[prediction_img_number]

axis[0].imshow(Original_Img)
axis[0].set_xlabel(Original_Img.shape)
axis[0].set_ylabel(Original_Img.size)
axis[0].set_title("NON SEEN INPUT")
axis[1].imshow(Predict_Image_AE)
axis[1].set_xlabel(Predict_Image_AE.shape)
axis[1].set_ylabel(Predict_Image_AE.size)
axis[1].set_title("AUTO ENCODER OUTPUT")

Text(0.5, 1.0, 'AUTO ENCODER OUTPUT')


Out[46]:

You might also like