text_plain_output_1.png image_output_1.png
from keras import models

from keras.backend import set_session

from skimage.transform import resize

from skimage.transform import resize

from tensorflow.keras.optimizers import Adam

import cv2

import datetime

import datetime

import datetime

import matplotlib.image as mpimg

import numpy as np

import os

import pickle

import tensorflow as tf

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import pickle
import os
import csv
import keras
import tensorflow as tf
from keras import backend
from keras.backend import set_session
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Flatten, Dense, Dropout, BatchNormalization
from tensorflow.keras.layers import Conv2D, MaxPooling2D, UpSampling2D, Dropout, LeakyReLU, Conv2DTranspose, ReLU
from tensorflow.keras.optimizers import Adam
from skimage.transform import resize
from keras.layers import Reshape
from keras import layers
import datetime
from keras import initializers
config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
config.gpu_options.visible_device_list = '0'
set_session(tf.compat.v1.Session(config=config))

path = '/kaggle/input/face-mask-dataset-1'
xname = '/kaggle/input/face-mask-dataset-1/celebA_real_with_mask1.pickle'
yname = '/kaggle/input/face-mask-dataset-1/celebA_real_with_out_mask1.pickle'
pickle_in = open(os.path.join(path, xname), 'rb')
x = pickle.load(pickle_in)
pickle_in = open(os.path.join(path, yname), 'rb')
y = pickle.load(pickle_in)
x = resize(x, (len(x), 64, 64, 1), anti_aliasing=False)
y = resize(y, (len(y), 64, 64, 1), anti_aliasing=False)

from keras import models
from keras.models import model_from_json
model = models.load_model('/kaggle/input/weight/results/results/500_mg_04-07-20_47.h5')
model_json = model.to_json()
with open('dcgan.json', 'w') as json_file:
    json_file.write(model_json)

with open('/kaggle/input/build-in-models/dcgan.json', 'r') as json_file:
    json_savedModel = json_file.read()
    generator = tf.keras.models.model_from_json(json_savedModel)
    generator.load_weights('/kaggle/input/build-in-models/250_wg_12-07-12_42.h5/250_wg_12-07-12_42.h5')
    generator.compile(loss='mean_squared_error', optimizer=Adam(lr=2e-05))

# Making predictions and drawing them.
# First row: Occluded images
# Second row: Ground Truth images
# Third row: Predictions

import datetime
plot_path = "./"

a = 8690
b = 8700
pred=generator.predict(x[a:b])

fig = plt.figure(figsize = (20,10))
for ctr in range(10):
  fig.add_subplot(3,10,ctr+1)
  plt.imshow(np.reshape(x[a + ctr],(64,64)),  cmap = "gray")

  

for ctr in range(10):
  fig.add_subplot(3,10,(10 + ctr + 1))
  plt.imshow(np.reshape(y[a + ctr]/255,(64,64)),  cmap = "gray")  

for ctr in range(10):
  fig.add_subplot(3,10,(20 + ctr + 1))
  plt.imshow(np.reshape(pred[ctr],(64,64)),  cmap = "gray")
  
plt.savefig(os.path.join(plot_path,str(datetime.datetime.now().strftime('%m-%d-%H:%M'))))

import cv2
import matplotlib.image as mpimg
img = mpimg.imread('/kaggle/input/real-time-face/WithMask/5)Thivagaran_surgical1.png')
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img.shape
from skimage.transform import resize
img = resize(img, (64, 64), anti_aliasing=False)

import datetime
plot_path = './'
img = np.expand_dims(img, axis=-1)
print(img.shape)