import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
(x_train,x_label),(y_train,y_label)=tf.keras.datasets.mnist.load_data()
x_train.shape,y_train.shape
((60000, 28, 28), (10000, 28, 28))
x_train = x_train.astype('float32')
y_train = y_train.astype('float32')
x_train = x_train/255
y_train = y_train/255
x_train = np.reshape(x_train,(len(x_train),28,28,1))
y_train = np.reshape(y_train,(len(y_train),28,28,1))
y_train.shape
(10000, 28, 28, 1)
noise_factor = 0.5
noise_x = x_train + noise_factor*np.random.normal(loc=0.0, scale=1.0, size=x_train.shape)
noise_y = y_train + noise_factor*np.random.normal(loc=0.0, scale=1.0, size=y_train.shape)
n = 20
plt.figure(figsize=(60, 12))
for i in range(1, 11):
ax = plt.subplot(2, n/2, i)
plt.imshow(x_train[i].reshape(28, 28))
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
ax = plt.subplot(2, n/2, 10+i)
plt.imshow(noise_x[i].reshape(28, 28))
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.show()

input = tf.keras.layers.Input(shape=(28,28,1))
x1 = tf.keras.layers.Conv2D(32,(3,3),padding='same',activation = 'relu',name = 'x1')(input)
x2 = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),strides=(2, 2),padding='same',name = 'x2')(x1)
x3 = tf.keras.layers.Conv2D(64,(3,3),padding='same',activation = 'relu',name = 'x3')(x2)
x4 = tf.keras.layers.MaxPooling2D