Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

MNU

DP LARNING   K  R A    A N D   T  N  O R F LO W   T U TO R I A L 

Denoising autoencoders with

,
Keras  TensorFlow  and Deep ,
Learning
 Adrian Roserock on Feruar 24  2020 ,

Click here to download the source code to this post

,
In this tutorial  ou will learn how to use autoencoders to denoise images using

, ,
Keras  TensorFlow  and Deep Learning .
’ -
Toda s tutorial is part two in our three part series on the applications of

autoencoders :

1 , ,
Autoencoders with Keras  TensorFlow  and Deep Learning  last week s ( ’
tutorial )

2 ,
Denoising autoenecoders with Keras  TensorFlow and Deep Learning

(toda’s tutorial)

3 , ,
Anomal detection with Keras  TensorFlow  and Deep Learning  next (

week s tutorial )

,
Last week ou learned the fundamentals of autoencoders  including how to train

our ver 몭rst autoencoder using Keras and TensorFlow — however, the real-

world application of that tutorial was admittedl a it limited due to the fact that

we needed to la the groundwork .

, ’
Toda  we re going to take a deeper dive and learn how autoencoders can e

, “
used for denoising  also called  noise reduction ,” which is the process of
removing noise from a signal .

“ ”
The term  noise  here could e :

Produced  a fault or poor qualit image sensor

Random variations in rightness or color

Quantization noise
Artifacts due to JPG compression

Image perturations produced  an image scanner or threshold post -
processing

( )
Poor paper qualit  crinkles and folds  when tring to perform OCR

From the perspective of image processing and computer vision  ou should ,
think of noise as anthing that could e removed  a reall good pre -
processing 몭lter .

Our goal is to train an autoencoder to perform such pre processing  - — we call


such models denoising autoencoders .

To learn how to train a denoising autoencoder with Keras and TensorFlow  just ,
keep reading !

Looking for the source code to this post ?
J U M P   R I G H T   TO   T H    D O W N LOA D      C T I O N  

Denoising autoencoders with Keras ,
,
TensorFlow  and Deep Learning

, ’
In the 몭rst part of this tutorial  we ll discuss what denoising autoencoders are and

wh we ma want to use them .


From there I ll show ou how to implement and train a denoising autoencoder

using Keras and TensorFlow .


We ll wrap up this tutorial  examining the results of our denoising autoencoder .

What are denoising autoencoders  and wh would ,
we use them ?

: ,
Figure 1  A denoising autoencoder processes a nois image  generating a clean image on the

. ,
output side  Can we learn how to train denoising autoencoders with Keras  TensorFlow  and Deep ,
?(
Learning toda in less than an hour   image source )

Denoising autoencoders are an extension of simple autoencoders  however  it s ; , ’


worth noting that denoising autoencoders were not originall meant to

automaticall denoise an image .

,
Instead  the denoising autoencoder procedure was invented to help :

The hidden laers of the autoencoder learn more roust 몭lters

Reduce the risk of over몭tting in the autoencoder

Prevent the autoencoder from learning a simple identif function

.’ ,
In Vincent et al s 2008 ICML paper  xtracting and Composing Roust

Features with Denoising Autoencoders  the authors found that the could ,
( . .,
improve the roustness of their internal laers  i e  latent space representation - )
 purposel introducing noise to their signal .

( . ., )
Noise was stochasticall  i e  randoml  added to the input data  and then the ,
autoencoder was trained to recover the original  nonpertured signal , .

,
From an image processing standpoint  we can train an autoencoder to perform

-
automatic image pre processing for us .

-
A great example would e pre processing an image to improve the accurac of

( )
an optical character recognition  OCR  algorithm  If ou ve ever applied OCR . ’
,
efore  ou know how just a little it of the wrong tpe of noise  ex  printer ink ( .,
,
smudges  poor image qualit during the scan  etc  can dramaticall hurt the , .)
.
performance of our OCR method  Using denoising autoencoders  we can ,
- ,
automaticall pre process the image  improve the qualit  and therefore increase ,
the accurac of the downstream OCR algorithm .


If ou re interested in learning more aout denoising autoencoders  I would ,
strongl encourage ou to read this article as well engio and Delalleau s paper ’ ,
Justifing and Generalizing Contrastive Divergence .

For more information on denoising autoencoders for OCR related preprocessing - ,
take a look at this dataset on Kaggle .

Con몭guring our development environment


To follow along with toda s tutorial on autoencoders  ou should use ,
. .
TensorFlow 2 0  I have two installation tutorials for TF 2 0 and associated .
packages to ring our development sstem up to speed :

. (
How to install TensorFlow 2 0 on Uuntu  Uuntu 18 04 O  CPU and . ;
optional NVIDIA GPU )

. (
How to install TensorFlow 2 0 on macO  Catalina and Mojave Oes )

:
Please note  PImageearch does not support Windows  — refer to our FAQ.

Project structure

. “ ”
Go ahead and gra the  zip from the  Downloads  section of toda s tutorial ’ .
,
From there  extract the zip .


You ll e presented with the following project laout :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
1.  $ tree ­­dirsfirst
2.  .
3.  ├── pyimagesearch
4.  │   ├── __init__.py
5.  │   └── convautoencoder.py
6.  ├── output.png
7.  ├── plot.png
8.  └── train_denoising_autoencoder.py
9.  
10.  1 directory, 5 files
The  pyimagesearch  module contains the  ConvAutoencoder .
 class  We

; , ’
reviewed this class in our previous tutorial  however  we ll rie몭 walk through it

again toda .


The heart of toda s tutorial is inside the  train_denoising_autoencoder.py
.
Pthon training script  This script is di몭erent from the previous tutorial in one

main wa :

We will purposel add noise to our MNIT training images using a random

normal distriution centered at  0.5  with a standard deviation of  0.5 .

The purpose of adding noise to our training data is so that our autoencoder can

e몭ectivel remove noise from an input image  i e  denoise ( . ., ).

Implementing our denoising autoencoder with Keras

and TensorFlow


The denoising autoencoder we ll e implementing toda is essentiall identical


to the one we implemented in last week s tutorial on autoencoder

fundamentals .


We ll review the model architecture here toda as a matter of completeness  ut ,

make sure ou refer to last week s guide for more details .

,
With that said  open up the  convautoencoder.py  몭le in our project structure ,
and insert the following code :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
1.  # import the necessary packages
2.  from tensorflow.keras.layers import BatchNormalization
3.  from tensorflow.keras.layers import Conv2D
4.  from tensorflow.keras.layers import Conv2DTranspose
5.  from tensorflow.keras.layers import LeakyReLU
6.  from tensorflow.keras.layers import Activation
7.  from tensorflow.keras.layers import Flatten
8.  from tensorflow.keras.layers import Dense
9.  from tensorflow.keras.layers import Reshape
10.  from tensorflow.keras.layers import Input
11.  from tensorflow.keras.models import Model
12.  from tensorflow.keras import backend as K
13.  import numpy as np
14.  
15.  class ConvAutoencoder:
16.    @staticmethod
17.    def build(width, height, depth, filters=(32, 64), latentDim=16):
18.      # initialize the input shape to be "channels last" along with
19.      # the channels dimension itself
20.      # channels dimension itself
21.      inputShape = (height, width, depth)
22.      chanDim = ­1
23.  
24.      # define the input to the encoder
25.      inputs = Input(shape=inputShape)
26.      x = inputs

Imports include  tf.keras  and NumP .

Our  ConvAutoencoder  class contains one static method   , build  which accepts

몭ve parameters :

width : Width of the input image in pixels

height : Heigh of the input image in pixels

depth : Numer of channels (i.e., depth) of the input volume

filters : A tuple that contains the set of 몭lters for convolution operations. 
default, if this parameter is not provided  the caller, we’ll add two sets of 

CONV => RELU => BN  with  32  and  64  몭lters

: The numer of neurons in our full-connected ( Dense ) latent


latentDim
vector.  default, if this parameter is not passed, the value is set to  16

,
From there  we initialize the  inputShape  and de몭ne the  Input  to the encoder

(Lines 25 and 26).


Let s egin uilding our encoder s 몭lters ’ :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
28.      # loop over the number of filters
29.      for f in filters:
30.        # apply a CONV => RELU => BN operation
31.        x = Conv2D(f, (3, 3), strides=2, padding="same")(x)
32.        x = LeakyReLU(alpha=0.2)(x)
33.        x = BatchNormalization(axis=chanDim)(x)
34.  
35.      # flatten the network and then construct our latent vector
36.      volumeSize = K.int_shape(x)
37.      x = Flatten()(x)
38.      latent = Dense(latentDim)(x)
39.  
40.      # build the encoder model
41.      encoder = Model(inputs, latent, name="encoder")
’ ,
Using Keras  functional API  we go ahead and Loop over numer of  filters
and add our sets of  CONV => RELU => BN (
 laers  Lines 29 33- ).

We then 몭atten the network and construct our latent vector  Lines 36 38  The ( - ).


-
latent space representation is the compressed form of our data .

From there  we uild the  , encoder  portion of our autoencoder  Line 41( ).

, ’ -
Next  we ll use our latent space representation to reconstruct the original input

image .

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
43.      # start building the decoder model which will accept the
44.      # output of the encoder as its inputs
45.      latentInputs = Input(shape=(latentDim,))
46.      x = Dense(np.prod(volumeSize[1:]))(latentInputs)
47.      x = Reshape((volumeSize[1], volumeSize[2], volumeSize[3]))(x)
48.  
49.      # loop over our number of filters again, but this time in
50.      # reverse order
51.      for f in filters[::­1]:
52.        # apply a CONV_TRANSPOSE => RELU => BN operation
53.        x = Conv2DTranspose(f, (3, 3), strides=2,
54.          padding="same")(x)
55.        x = LeakyReLU(alpha=0.2)(x)
56.        x = BatchNormalization(axis=chanDim)(x)
57.  
58.      # apply a single CONV_TRANSPOSE layer used to recover the
59.      # original depth of the image
60.      x = Conv2DTranspose(depth, (3, 3), padding="same")(x)
61.      outputs = Activation("sigmoid")(x)
62.  
63.      # build the decoder model
64.      decoder = Model(latentInputs, outputs, name="decoder")
65.  
66.      # our autoencoder is the encoder + decoder
67.      autoencoder = Model(inputs, decoder(encoder(inputs)),
68.        name="autoencoder")
69.  
70.      # return a 3­tuple of the encoder, decoder, and autoencoder
71.      return (encoder, decoder, autoencoder)

,
Here  we are taking the latent input and use a full connected laer to reshape it -
into a 3D volume  i e  the image data ( . ., ).

,
We loop over our 몭lters again  ut in reverse order  appling  ,
CONV_TRANSPOSE => RELU => BN  laers where the  CONV_TRANSPOSE  laer s ’
purpose is to increase the volume size .

,
Finall  we uild the decoder model and construct the autoencoder  Rememer . ,
the concept of an autoencoder  — discussed last week — consists of oth the
encoder and decoder components .

Implementing the denoising autoencoder training

script


Let s now implement the training script used to :

1 Add stochastic noise to the MNIT dataset

2 Train a denoising autoencoder on the nois dataset

3 Automaticall recover the original digits from the noise


M implementation follows Francois Chollet s own implementation of

denoising autoencoders on the o몭cial Keras log  — m primar contriution
here is to go into a it more detail regarding the implementation itself.

Open up the  train_denoising_autoencoder.py ,
 몭le  and insert the following

code :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
1.  # set the matplotlib backend so figures can be saved in the background
2.  import matplotlib
3.  matplotlib.use("Agg")
4.  
5.  # import the necessary packages
6.  from pyimagesearch.convautoencoder import ConvAutoencoder
7.  from tensorflow.keras.optimizers import Adam
8.  from tensorflow.keras.datasets import mnist
9.  import matplotlib.pyplot as plt
10.  import numpy as np
11.  import argparse
12.  import cv2
13.  
14.  # construct the argument parse and parse the arguments
15.  ap = argparse.ArgumentParser()
16.  ap.add_argument("­s", "­­samples", type=int, default=8,
17.    help="# number of samples to visualize when decoding")
18.  ap.add_argument("­o", "­­output", type=str, default="output.png",
19.    help="path to output visualization file")
20.  ap.add_argument("­p", "­­plot", type=str, default="plot.png",
21.    help="path to output plot file")
22.  args = vars(ap.parse_args())

- .
On Lines 2 12 we handle our imports  We ll use the  ’ "Agg"  ackend of 

matplotlib .
 so that we can export our training plot to disk  Our custom 

ConvAutoencoder  class implemented in the previous section contains the
. ’
autoencoder architecture itself  Modeling after Chollet s example  we will also ,
use the Adam optimizer .

Our script accepts three optional command line arguments :

­­samples : The numer of output samples for visualization.  default this
value is set to  8 .

­­output : The path to the output visualization image. We’ll name our
visualization  output.png   default.

­­plot : The path to our matplotli output plot. A default of  plot.png  is

assigned if this argument is not provided in the terminal.

,
Next  we initialize hperparameters and preprocess our MNIT dataset :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
24.  # initialize the number of epochs to train for and batch size
25.  EPOCHS = 25
26.  BS = 32
27.  
28.  # load the MNIST dataset
29.  print("[INFO] loading MNIST dataset...")
30.  ((trainX, _), (testX, _)) = mnist.load_data()
31.  
32.  # add a channel dimension to every image in the dataset, then scale
33.  # the pixel intensities to the range [0, 1]
34.  trainX = np.expand_dims(trainX, axis=­1)
35.  testX = np.expand_dims(testX, axis=­1)
36.  trainX = trainX.astype("float32") / 255.0
37.  testX = testX.astype("float32") / 255.0

Our training epochs will e  25 ’
 and we ll use a atch size of  32 .

( )
We go ahead and gra the MNIT dataset  Line 30  while Lines 34 37  1  add a - ()
,
channel dimension to ever image in the dataset  and  2  scale the pixel ( )
intensities to the range  0  1 [ , ].

, ’
At this point  we ll deviate from last week s tutorial ’ :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
39.  # sample noise from a random normal distribution centered at 0.5 (since
40.  # our images lie in the range [0, 1]) and a standard deviation of 0.5
41.  trainNoise = np.random.normal(loc=0.5, scale=0.5, size=trainX.shape)
42.  testNoise = np.random.normal(loc=0.5, scale=0.5, size=testX.shape)
43.  trainXNoisy = np.clip(trainX + trainNoise, 0, 1)
44.  testXNoisy = np.clip(testX + testNoise, 0, 1)

,
To add random noise to the MNIT digits  we use NumP s random normal ’
distriution centered at  0.5  with a standard deviation of  0.5 ( -
  Lines 41 44 ).

The following 몭gure shows an example of how our images look efore  left ( )
adding noise followed  after  right ( ):

:
Figure 2  Prior to training a denoising autoencoder on MNIT with Keras ,
, ,
TensorFlow  and Deep Learning  we take input images  left  and ( )
(
delieratel add noise to them  right ).

,
As ou can see  our images are quite corrupted  — recovering the original digit
from the noise will require a powerful model .

,
Luckil  our denoising autoencoder will e up to the task :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
46.  # construct our convolutional autoencoder
47.  print("[INFO] building autoencoder...")
48.  (encoder, decoder, autoencoder) = ConvAutoencoder.build(28, 28, 1)
49.  opt = Adam(lr=1e­3)
50.  autoencoder.compile(loss="mse", optimizer=opt)
51.  
52.  # train the convolutional autoencoder
53.  H = autoencoder.fit(
54.    trainXNoisy, trainX,
55.    validation_data=(testXNoisy, testX),
56.    epochs=EPOCHS,
57.    batch_size=BS)
58.  
59.  # construct a plot that plots and saves the training history
60.  N = np.arange(0, EPOCHS)
61.  plt.style.use("ggplot")
62.  plt.figure()
63.  plt.plot(N, H.history["loss"], label="train_loss")
64.  plt.plot(N, H.history["val_loss"], label="val_loss")
65.  plt.title("Training Loss and Accuracy")
66.  plt.xlabel("Epoch #")
67.  plt.ylabel("Loss/Accuracy")
68.  plt.legend(loc="lower left")
69.  plt.savefig(args["plot"])

,
Line 48 uilds our denoising autoencoder  passing the necessar arguments .
Using our  Adam  optimizer with an initial learning rate of  1e­3 , we go ahead
and compile the autoencoder with mean squared error  - loss (
  Lines 49 and 50 ).

- .
Training is launched via Lines 53 57  Using the training histor data   , H , Lines
- ,
60 69 plot the loss  saving the resulting 몭gure to disk .


Let s write a quick loop that will help us visualize the denoising autoencoder

results :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
71.  # use the convolutional autoencoder to make predictions on the
72.  # testing images, then initialize our list of output images
73.  print("[INFO] making predictions...")
74.  decoded = autoencoder.predict(testXNoisy)
75.  outputs = None
76.  
77.  # loop over our number of output samples
78.  for i in range(0, args["samples"]):
79.    # grab the original image and reconstructed image
80.    original = (testXNoisy[i] * 255).astype("uint8")
81.    recon = (decoded[i] * 255).astype("uint8")
82.  
83.    # stack the original and reconstructed image side­by­side
84.    output = np.hstack([original, recon])
85.  
86.    # if the outputs array is empty, initialize it as the current
87.    # side­by­side image display
88.    if outputs is None:
89.      outputs = output
90.  
91.    # otherwise, vertically stack the outputs
92.    else:
93.      outputs = np.vstack([outputs, output])
94.  
95.  # save the outputs image to disk
96.  cv2.imwrite(args["output"], outputs)

We go ahead and use our trained autoencoder to remove the noise from the

(
images in our testing set  Line 74 ).

We then gra N  ­­samples  worth of  original  and reconstructed data  and ,


( - ).
put together a visualization montage  Lines 78 93  Line 96 writes the

visualization 몭gure to disk for inspection .

Training the denoising autoencoder with Keras and

TensorFlow

,
To train our denoising autoencoder  make sure ou use the  Downloads “ ”
section of this tutorial to download the source code .

,
From there  open up a terminal and execute the following command :
,
From there  open up a terminal and execute the following command :

→ Launch Jupter Noteook on Google Cola

Denoising autoencoders with Keras, TensorFlow, and Deep Learning
46.  $ python train_denoising_autoencoder.py ­­output output_denoising.png \
47.    ­­plot plot_denoising.png
48.  [INFO] loading MNIST dataset...
49.  [INFO] building autoencoder...
50.  Train on 60000 samples, validate on 10000 samples
51.  Epoch 1/25
52.  60000/60000 [==============================] ­ 85s 1ms/sample ­ loss: 0.0285 ­ 
val_loss: 0.0191
53.  Epoch 2/25
54.  60000/60000 [==============================] ­ 83s 1ms/sample ­ loss: 0.0187 ­ 
val_loss: 0.0211
55.  Epoch 3/25
56.  60000/60000 [==============================] ­ 84s 1ms/sample ­ loss: 0.0177 ­ 
val_loss: 0.0174
57.  Epoch 4/25
58.  60000/60000 [==============================] ­ 84s 1ms/sample ­ loss: 0.0171 ­ 
val_loss: 0.0170
59.  Epoch 5/25
60.  60000/60000 [==============================] ­ 83s 1ms/sample ­ loss: 0.0167 ­ 
val_loss: 0.0177
61.  ...
62.  Epoch 21/25
63.  60000/60000 [==============================] ­ 67s 1ms/sample ­ loss: 0.0146 ­ 
val_loss: 0.0161
64.  Epoch 22/25
65.  60000/60000 [==============================] ­ 67s 1ms/sample ­ loss: 0.0145 ­ 
val_loss: 0.0164
66.  Epoch 23/25
67.  60000/60000 [==============================] ­ 67s 1ms/sample ­ loss: 0.0145 ­ 
val_loss: 0.0158
68.  Epoch 24/25
69.  60000/60000 [==============================] ­ 67s 1ms/sample ­ loss: 0.0144 ­ 
val_loss: 0.0155
70.  Epoch 25/25
71.  60000/60000 [==============================] ­ 66s 1ms/sample ­ loss: 0.0144 ­ 
val_loss: 0.0157
72.  [INFO] making predictions...
:
Figure 3  xample results from training a deep learning denoising autoencoder with Keras and

. ,
Tensor몭ow on the MNIT enchmarking dataset  Inside our training script  we added random

noise with NumP to the MNIT images .

Training the denoising autoencoder on m iMac Pro with a 3 GHz Intel Xeon W

~
processor took  32 20 minutes . .

,
As Figure 3 shows  our training process was stale and shows no signs of

over몭tting .

Denoising autoencoder results

Our denoising autoencoder has een successfull trained  ut how did it ,
perform when removing the noise we added to the MNIT dataset ?

,
To answer that question  take a look at Figure 4 :

:
Figure 4  The results of removing noise from MNIT images using a denoising

, ,
autoencoder trained with Keras  TensorFlow  and Deep Learning .

On the left we have the original MNIT digits that we added noise to while on

the right we have the output of the denoising autoencoder  — we can clearl see
that the denoising autoencoder was ale to recover the original signal  i e ( . .,
)
digit  from the image while removing the noise .
)
digit  from the image while removing the noise .

More advanced denosing autoencoders can e used to automaticall pre -
process images to facilitate etter OCR accurac .

' ?
What s next  I recommend PImageearch

Universit .

Course information   :
• • : /
13 total classes   21h 2m video   Last updated  4 2021 

★★★★★ 4.84 (128 Ratings) • 3,690 tudents nrolled

I strongl elieve that if ou had the right teacher ou could master

computer vision and deep learning .

Do ou think learning computer vision and deep learning has to e

- , , ?
time consuming  overwhelming  and complicated  Or has to involve

?
complex mathematics and equations  Or requires a degree in

computer science ?


That s not the case .
All ou need to master computer vision and deep learning is for

,
someone to explain things to ou in simple  intuitive terms  And that s . ’
.
exactl what I do  M mission is to change education and how complex

Arti몭cial Intelligence topics are taught .

' ,
If ou re serious aout learning computer vision  our next stop should

,
e PImageearch Universit  the most comprehensive computer

, ,
vision  deep learning  and OpenCV course online toda  Here ou ll . ’
learn how to successfull and con몭dentl appl computer vision to

, , .
our work  research  and projects  Join me in computer vision master .

Inside PImageearch Universit ou ll 몭nd ' :

✓ 13 courses on essential computer vision, deep learning, and
OpenCV topics

✓ 13 Certi몭cates of Completion

✓ 21h 2m on-demand video

✓ rand new courses released ever month, ensuring ou can keep
up with state-of-the-art techniques

✓ Pre-con몭gured Jupter Noteooks in Google Cola

✓ Run all code examples in our we rowser — works on Windows,
macO, and Linux (no dev environment con몭guration required!)

✓ Access to centralized code repos for all 400+ tutorials on
PImageearch

✓ as one-click downloads for code, datasets, pre-trained models,
etc.

✓ Access on moile, laptop, desktop, etc.

C L I C K   H  R    TO   J O I N   P Y I M AG    A R C H   U N I V  R  I T Y
ummar

, ,,
In this tutorial  ou learned aout denoising autoencoders  which  as the name

suggests, are models that are used to remove noise from a signal.

,
In the context of computer vision  denoising autoencoders can e seen as ver

- .
powerful 몭lters that can e used for automatic pre processing  For example  a ,
-
denoising autoencoder could e used to automaticall pre process an image ,
improving its qualit for an OCR algorithm and there increasing OCR accurac .

,
To demonstrate a denoising autoencoder in action  we added noise to the

,
MNIT dataset  greatl degrading the image qualit to the point where an

.
model would struggle to correctl classif the digit in the image  Using our

,
denoising autoencoder  we were ale to remove the noise from the image ,
( . .,
recovering the original signal  i e  the digit ).

’ , ’ -
In next week s tutorial  ou ll learn aout another real world application of

autoencoders  — anomal and outlier detection.

(
To download the source code to this post  and e noti몭ed when future

tutorials are pulished here on PImageearch ), just enter our email address
in the form elow !
Download the ource Code and FR 17 page -
Resource Guide

.
nter our email address elow to get a  zip of the code and a FR 17 page -
, ,
Resource Guide on Computer Vision  OpenCV  and Deep Learning  Inside ou ll . '
- , , ,
몭nd m hand picked tutorials  ooks  courses  and liraries to help ou master CV

and DL !

Your email address D O W N L OA D   T H    C O D  !

Aout the Author

, ’ , .
Hi there  I m Adrian Roserock  PhD  All too often I see developers  students , ,
, ,
and researchers wasting their time  studing the wrong things  and generall

struggling to get started with Computer Vision, Deep Learning, and OpenCV. I

created this wesite to show ou what I elieve is the est possile wa to
get our start .

Previous Article :
,
Autoencoders with Keras  TensorFlow  and Deep Learning ,

:
Next Article

,
Anomal detection with Keras  TensorFlow  and Deep Learning ,

:
14 responses to  Denoising autoencoders with Keras ,
TensorFlow  and Deep Learning ,

Andre

,
Feruar 24  2020 at 2 57 pm :


I ve spotted an issue with the 몭gure that shows the addition of noise to the

MNIT dataset   .
,
The 몭gure has a horizontall laout  while clearl it should have een vertical .

Adrian Roserock

,
Feruar 27  2020 at 9 05 am :


That s not an issue at all  — it’s simpl how I decided to displa the image in
the log post .

.- .
W C  Cheng

,
Feruar 25  2020 at 1 36 am :
Hi ,

, “ ”
Line 74  the  testX  should e  testXNoise “ ”.

Adrian Roserock

, :
Feruar 27  2020 at 9 05 am

! ’ .
Thanks for catching that  I ll ensure the log post is updated

:
DIT  Tpo has een 몭xed .

Mingxing wang

, :
Feruar 25  2020 at 7 21 pm

.
Hi  Adrian   .
I am ver glad to e a 몭rst person who takes our newl organized

autoencoders with Keras Tensor몭ow deep learning online lectures   .
I studied all our lectures carefull step  step and full understood all the

.
contents  Your lecture is ver inevitale and succinct that could give great

help to learners without complexit and confusion   .
I will tr to stud the asic algorithms and program structures in the future for

deep understanding   .
,
Finall  I am ver appreciated for sending me everda lectures   .
est regards .

Adrian Roserock

, :
Feruar 27  2020 at 9 04 am

!
Thank ou for the kind words Mingxing  I reall appreciate it  ὤ
Johnn

,
Feruar 26  2020 at 2 58 pm :

, .
Hi Adrian  I am liking the encoders  o I want to create m own dataset .
()
Pictures of di몭erent  1  peles laing across di몭erent ackgrounds  concrete ( ,
, , , ).
pavement  asphalt  grass  etc  Are ou saing I can then train this encoder

with this dataset and if I input a ackground with a pele   of ankind  it will ( )


– without the ackground? I am tring to identif
output just that pele onl 

a certain tpe of pele against a ackground.

Thanks again

Adrian Roserock

,
Feruar 27  2020 at 9 04 am :

? ,
Your end goal is to classif the tpe of pele  If so  wh not use standard

?
CNN classi몭cation methods to classif the pele  Is there a particular

?
reason ou need the autoencoder  I think what ou re getting at is ou ’
want to use the autoencoder to remove the ackground from the image ?

umit vaise

,
March 12  2020 at 5 24 pm :

o we have to retrain our network on the nois dataset  Or is it training from ?
?
scratch on nois dataset  If that is so then how the network is ale to

reconstruct the clean images ecause we never train on the clean dataset

Adrian Roserock

,
March 19  2020 at 9 38 am :

’ ( . .,
We re actuall training from scratch here  i e  no transfer learning ).
jijou farah

,
March 13  2020 at 11 01 am:

, ,
Hi Adrian  i have a question please   i am working to denoise images with  (
gaussien noise and paper  & sel noise) , can i use autoencoder to these tpes
of noise  ?

Adrian Roserock

,
March 19  2020 at 9 38 am :

,
Yes  autoencoders tend to excel with removing that tpe of noise .

aghiles

,
March 18  2020 at 10 00 am :

, , ’ -
hello adrian  thanks for our tutorial  I m currentl tring to train an auto

encoder to detect defects in farics, ut I’m struggeling for con몭guring m

dataset, all tutorial found uses uilt-in keras datasets wich are testreams

rathen than real images, I would e grateful if ou could help me solve that.

Adrian Roserock

,
March 19  2020 at 9 37 am :

Have ou taken a look at Deep Learning for Computer Vision with

?
Pthon  That ook teaches ou how to train CNNs on our own custom

.
datasets  I would suggest starting there .
Comment section

, ,
He  Adrian Roserock here  author and creator of PImageearch  While I .
,
love hearing from readers  a couple ears ago I made the tough decision to

:
no longer o몭er 1 1 help over log post comments .

+
At the time I was receiving 200  emails per da and another 100  log +
.
post comments  I simpl did not have the time to moderate and respond to

,
them all  and the shear volume of requests was taking a toll on me .

,
Instead  m goal is to do the most good for the computer vision  deep ,
,
learning  and OpenCV communit at large  focusing m time on

- , ,
authoring high qualit log posts  tutorials  and ooks courses / .

If ou need help learning computer vision and deep learning  I suggest ,
ou refer to m full catalog of ooks and courses  — the have helped
, ,
tens of thousands of developers  students  and researchers just like

,
ourself learn Computer Vision  Deep Learning  and OpenCV , .

Click here to rowse m full catalog .

PImageearch Universit  — NOW NROLLING!

,
You can master Computer Vision  Deep Learning  and OpenCV ,

Course information   :
:
Course information  

• • : /
13 total classes   21h 2m video   Last updated  4 2021 

★★★★★ 
4.84 (128 Ratings) • 3,690 tudents nrolled

✓ 13 courses on essential computer vision, deep learning, and OpenCV topics 

✓ 13 Certi몭cates of Completion 

✓ 21h 2m on-demand video 

✓ rand new courses released ever month, ensuring ou can keep up with state-of-

-
the art techniques 

✓ Pre-con몭gured Jupter Noteooks in Google Cola 

✓ Run all code examples in our we rowser — works on Windows, macO, and Linux

(no dev environment con몭guration required!) 

✓ Access to centralized code repos for all 400+ tutorials on PImageearch 

✓ as one-click downloads for code, datasets, pre-trained models, etc. 

✓ Access on moile, laptop, desktop, etc.

JOIN NOW

Picked For You

Mixing normal images and adversarial images when training CNNs
Defending against adversarial image attacks with Keras and TensorFlow

(
Adversarial attacks with FGM  Fast Gradient ign Method)

Contrastive Loss for iamese Networks with Keras and TensorFlow

, ,
Comparing images for similarit using siamese networks  Keras  and TensorFlow

imilar articles
imilar articles

DP LARNING K  R A    A N D   T  N  O R F LOW T U TO R I A L 

Detecting Natural Disasters with Keras and Deep Learning

,
Novemer 11  2019

DP LARNING FAC    A P P L I C AT I O N  INTRVIW

,
An interview with Adam Geitge  creator of the face recognition Pthon lirar _
,
Jul 11  2018

DP LARNING K  R A    A N D   T  N  O R F LOW T U TO R I A L 

: ,
Keras Tutorial  How to get started with Keras  Deep Learning  and Pthon ,
eptemer 10  2018 ,
You can learn Computer Vision  Deep Learning  and , ,
OpenCV .
, ,
Get our FR 17 page Computer Vision  OpenCV  and Deep Learning Resource

. ’ - , , ,
Guide PDF  Inside ou ll 몭nd m hand picked tutorials  ooks  courses  and liraries to

help ou master CV and DL .

Your email address D O W N L OA D   F O R   F R  

Topics Machine Learning and Computer Vision

Medical Computer Vision
Deep Learning

Dli Lirar
Optical Character Recognition  OCR( )

/
medded IoT and Computer Vision
Oject Detection

Oject Tracking
Face Applications

OpenCV Tutorials
Image Processing

Rasperr Pi
Interviews

Keras
ooks  & Courses PImageearch

, ,
FR CV  DL  and OpenCV Crash Course Get tarted

Practical Pthon and OpenCV OpenCV Install Guides

Deep Learning for Computer Vision with Aout

Pthon
FAQ

PImageearch Gurus Course
log

Rasperr Pi for Computer Vision
Contact

Privac Polic

© 2021 PImageearch. All Rights Reserved.

You might also like