Clarification wanted for make_step function of Google's deep dream script
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
The make_step function in DeepDream performs one gradient-ascent update on an input image to amplify features that strongly activate selected network layers. It is not a full training step and does not update model weights. Instead, it updates pixels to increase activations, producing the dream-like visual effect.
Conceptual Role of make_step
DeepDream treats the input image as an optimizable variable. During each step, it computes gradient of an objective with respect to image pixels, then nudges the image in the gradient direction. Repeating this process sharpens patterns detected by the network.
High-level flow:
- Forward pass to compute chosen layer activations.
- Compute objective from those activations.
- Backpropagate gradient to image.
- Normalize gradient and update pixels.
- Optionally clip or jitter for stability.
This is gradient ascent on input space, not gradient descent on parameters.
Minimal TensorFlow-style Example
The exact implementation depends on framework version, but the algorithm is stable.
Here, model is usually a submodel exposing intermediate layers rather than final classification logits.
Why Normalization, Jitter, and Octaves Matter
Raw gradients can be noisy and dominated by high-frequency artifacts. Gradient normalization stabilizes update scale across steps. Random jitter shifts image slightly between steps, reducing tile artifacts and encouraging broader feature amplification.
Octave processing repeats make_step across multiple image scales. Lower scales shape global structure, higher scales add fine texture. This multiscale strategy produces richer dream patterns than single-scale updates.
In production scripts, add logging for loss values and clamp ranges to avoid exploding pixel values.
Practical Debugging Guidance
If output stays unchanged, confirm gradients are non-zero and that chosen layer actually responds to current input. If output becomes noisy static, reduce step size and increase clipping discipline. Also verify preprocessing and deprocessing paths are inverse-compatible so visualized output is meaningful.
It helps to save intermediate frames every few steps. Visual checkpoints reveal whether changes are smooth and cumulative or unstable.
Layer Selection and Objective Design
DeepDream output quality depends heavily on which layers drive the objective. Lower layers emphasize edges and textures, while higher layers produce complex semantic motifs. Many implementations blend several layers with weighted contributions for balanced visuals.
Tune weights gradually and inspect outputs after small step batches. Aggressive weighting can create unstable artifacts quickly.
Octave Workflow in Practice
A common recipe scales image down, runs gradient ascent, then scales back up and repeats. This preserves global structure while adding detail progressively.
This staged process is why classical DeepDream images contain both coherent large forms and fine-grained local textures.
Common Pitfalls
- Interpreting
make_stepas model training instead of input optimization. - Using final softmax outputs as objective and getting weak gradients.
- Skipping gradient normalization and producing unstable updates.
- Forgetting to clip pixel values after each ascent step.
- Ignoring preprocessing conventions expected by the base network.
Summary
make_stepperforms one gradient-ascent update on the image pixels.- Model weights remain fixed; only input image changes.
- Gradient normalization and clipping improve stability.
- Multiscale octave processing yields richer DeepDream images.
- Debug with intermediate saves and gradient diagnostics for predictable results.
Related reading
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.