ICP_13 DeepLearning - acvc279/Python_Deeplearning GitHub Wiki

VideoLink:https://drive.google.com/file/d/1BFGk_1reA8ZvQ_7OFlNu0xY7q8Yol0Mh/view?usp=drivesdk

Q1: Add one more hidden layer to autoencoder.

  • Import all the required libraries.
  • This is the size of our encoded representations. 32 floats -> compression of factor 24.5, assuming the input is 784 floats.encoding_dim = 32
  • this is our input placeholder.input_img = Input(shape=(784,))
  • encoded is the encoded representation of the input.decoded is the lossy reconstruction of the input.This model maps an input to its reconstruction.
  • this model maps an input to its encoded representation:
  • train and test the data:
  • fit the model:autoencoder.fit(x_train, x_train, epochs=5, batch_size=256, shuffle=True, validation_data=(x_test, x_test))
  • Output of sourcecode:
  • Adding a hidden layer:
encoded = Dense(encoding_dim, activation='relu')(input_img)
#Adding hidden layer
Adding_Hidden_Layer=Dense(encoding_dim, activation= 'relu')(encoded)
# decoded is the lossy reconstruction of the input
decoded = Dense(784, activation='sigmoid')(Adding_Hidden_Layer)
  • Output after adding hidden layer:

Q2:Do the prediction on the test data and then visualize one of the reconstructed versionof that test data. Also, visualize the same test data before reconstructionusing Matplotlib.

After executing first program perform predict function and viuaize the img and reconstructed here are the output:

Q3: Repeat the question 2 on the denoisening autoencoder.

  • Perform the source code and add noise factor:
noise_factor = 0.5
x_train_noisy = x_train + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=x_train.shape)
x_test_noisy = x_test + noise_factor * np.random.normal(loc=0.0, scale=1.0, size=x_test.shape)
  • Fit the model: history=autoencoder.fit(x_train_noisy, x_train, epochs=10, batch_size=256, shuffle=True, validation_data=(x_test_noisy, x_test_noisy))
  • input the image to visuvalize:
  • After applying noise to the data:
  • aFter predection of noise image:
  • Final reconstructed image:

Q4:plot lossand accuracy using the history object.

  • plot loss and accuraccy of hiastory object of question three.
  • Plot the graph by using:
plt.plot(history.history['loss'])                        plt.plot(history.history['accuracy'])
plt.plot(history.history['val_loss'])                    plt.plot(history.history['val_accuracy'])
plt.title('Data loss')                                   plt.title('Data accuraccy')
plt.xlabel('epoch')                                      plt.xlabel('epoch')
plt.ylabel('loss')                                       plt.ylabel('accuraccy')
plt.legend(['train','test'])                             plt.legend(['train','test'])
plt.show()                                               plt.show()
  • here is the Plot of data loss and accuraccy plot of data accuraccy:

Learned from these icp:Autoencoders.

challengings faced: every thing is good.