The entire model with the inputs we had before.Next we create our DeepDream model, which consists of two parts: To do this we specify the names of the layers we're interested in: # Maximize the activation of these layersĪfter that we create a for loop for our names to go through our base_model and get the layer: layers = The early layers will be able to generate simpler features such as edges, and deeper layers will generate more complex features like faces, trees, etc. Now we're going to import Inception Net, which is a pre-trained model provided by Google, and we're going to use the imagenet weights: base_model = tf.3(include_top=False, weights='imagenet')Īs we can see this is a huge model with around 22 million total parameters:įor the DeepDream model we need to specify which activation, or which layer that we're interested in, and our objective is then to maximize the loss since we're using gradient ascent. Import random Step 2: Import the Model with Pre-Trained Weights The first step is to import the necessary libraries after we install TensorFlow 2.0: !pip install tensorflow-gpu=2.0.0.alpha0 import tensorflow as tf The following code has been adapted from the TensorFlow 2.0 Documentation. Now that we have the steps for the DeepDream algorithm, let's implement it in Google Colab. Iterate and repeat this process over multiple scales.Modify the image to increase these activations (we apply gradient ascent, not gradient descent), and thus we enhance the patterns seen by the network resulting in a dream-like hallucinated image.Calculate the gradient of the image with respect to the activations of the chosen layer.Calculate the activations (output) coming out of the layer of interest.Select the layer of choice, recall that the first layers capture edges and deeper layers capture shapes like faces.Forward an image through a trained ANN, CNN, ResNet, etc.Here are the steps we need to take for the mathematics of the DeepDream algorithm: This process is repeated until the input image now contains all the features that specific layer was originally looking for.įor example, if a specific layer was used to detect cat faces and we feed in an image of a sky, the DeepDream algorithm would continuously change the input image and start creating images of cats on top of the blue sky.We select which neurons and which layers we want to fire more prominently. DeepDream works by trying to change the input image in a way that makes some of these neurons fire more than others (i.e.When you feed an image to a trained artificial neural network, the neurons fire and generate activations.To get a bit more detailed, here is how the DeepDream algorithm works: The overall idea of how the DeepDream algorithm works is that we take a look at one of the layers, it could be a low level or high level feature, and we tell it to maximize the activation, or the effect that it has on an image. In short, there are different layers that are responsible to perform different tasks. The last few layers assemble these features into complete interpretations and classifies the image accordingly. ![]() The next set of layers of the network detect higher level features such as faces, trees, and cars. ![]() ![]()
0 Comments
Leave a Reply. |