class_docstr: Provides an interface for activation maximization via gradient descent.
  
  This class implements the gradient ascent algorithm in order to perform
  activation maximization with convolutional neural networks (CNN).
  
  `Activation maximization <https://pdfs.semanticscholar.org/65d9/94fb778a8d9e0f632659fb33a082949a50d3.pdf>`_
  is one form of feature visualization that allows us to visualize what CNN
  filters are "looking for", by applying each filter to an input image and
  updating the input image so as to maximize the activation of the filter of
  interest (i.e. treating it as a gradient ascent task with activation as the
  loss). The implementation is inspired by `this demo <https://blog.keras.io/category/demo.html>`_
  by Francois Chollet.
  
  Args:
      model: A neural network model from `torchvision.models
          <https://pytorch.org/docs/stable/torchvision/models.html>`_,
          typically without the fully-connected part of the network.
          e.g. torchvisions.alexnet(pretrained=True).features
      img_size (int, optional, default=224): The size of an input image to be
          optimized.
      lr (float, optional, default=1.): The step size (or learning rate) of
          the gradient ascent.
      use_gpu (bool, optional, default=False): Use GPU if set to True and
          `torch.cuda.is_available()`.
class_docstr_tok: ["Provides","an","interface","for","activation","maximization","via","gradient","descent",".","This","class","implements","the","gradient","ascent","algorithm","in","order","to","perform","activation","maximization","with","convolutional","neural","networks","(","CNN",")",".","`","Activation","maximization","<","https",":","\/\/pdfs.semanticscholar.org\/65d9\/94fb778a8d9e0f632659fb33a082949a50d3.pdf",">","`","_","is","one","form","of","feature","visualization","that","allows","us","to","visualize","what","CNN","filters","are","``","looking","for","''",",","by","applying","each","filter","to","an","input","image","and","updating","the","input","image","so","as","to","maximize","the","activation","of","the","filter","of","interest","(","i.e",".","treating","it","as","a","gradient","ascent","task","with","activation","as","the","loss",")",".","The","implementation","is","inspired","by","`","this","demo","<","https",":","\/\/blog.keras.io\/category\/demo.html",">","`","_","by","Francois","Chollet",".","Args",":","model",":","A","neural","network","model","from","`","torchvision.models","<","https",":","\/\/pytorch.org\/docs\/stable\/torchvision\/models.html",">","`","_",",","typically","without","the","fully-connected","part","of","the","network",".","e.g",".","torchvisions.alexnet","(","pretrained=True",")",".features","img_size","(","int",",","optional",",","default=224",")",":","The","size","of","an","input","image","to","be","optimized",".","lr","(","float",",","optional",",","default=1",".",")",":","The","step","size","(","or","learning","rate",")","of","the","gradient","ascent",".","use_gpu","(","bool",",","optional",",","default=False",")",":","Use","GPU","if","set","to","True","and","`","torch.cuda.is_available","(",")","`","."]
docstr: Creates DeepDream.
  
  It applies the optimization on the image provided. The image is loaded
  and made into a torch.Tensor that is compatible as the input to the
  network.
  
  Read the original blog post by Google for more information on
  `DeepDream <https://ai.googleblog.com/2015/06/inceptionism-going-deeper-into-neural.html>`_.
  
  Args:
      img_path (str): A path to the image you want to apply DeepDream on
      layer (torch.nn.modules.conv.Conv2d): The target Conv2d layer from
          which the filter to be chosen, based on `filter_idx`.
      filter_idx (int): The index of the target filter.
      lr (float, optional, default=.1): The step size of optimization.
      num_iter (int, optional, default=30): The number of iteration for
          the gradient ascent operation.
      figsize (tuple, optional, default=(4, 4)): The size of the plot.
          Relevant in case 1 above.
      title (str, optional default='Conv2d'): The title of the plot.
      return_output (bool, optional, default=False): Returns the
          output(s) of optimization if set to True.
  
  Returns:
      output (list of torch.Tensor): With dimentions
          :math:`(num_iter, C, H, W)`. The size of the image is
          determined by `img_size` attribute which defaults to 224.
docstr_tok: ["Creates","DeepDream",".","It","applies","the","optimization","on","the","image","provided",".","The","image","is","loaded","and","made","into","a","torch.Tensor","that","is","compatible","as","the","input","to","the","network",".","Read","the","original","blog","post","by","Google","for","more","information","on","`","DeepDream","<","https",":","\/\/ai.googleblog.com\/2015\/06\/inceptionism-going-deeper-into-neural.html",">","`","_",".","Args",":","img_path","(","str",")",":","A","path","to","the","image","you","want","to","apply","DeepDream","on","layer","(","torch.nn.modules.conv.Conv2d",")",":","The","target","Conv2d","layer","from","which","the","filter","to","be","chosen",",","based","on","`","filter_idx","`",".","filter_idx","(","int",")",":","The","index","of","the","target","filter",".","lr","(","float",",","optional",",","default=.1",")",":","The","step","size","of","optimization",".","num_iter","(","int",",","optional",",","default=30",")",":","The","number","of","iteration","for","the","gradient","ascent","operation",".","figsize","(","tuple",",","optional",",","default=","(","4",",","4",")",")",":","The","size","of","the","plot",".","Relevant","in","case","1","above",".","title","(","str",",","optional","default='Conv2d","'",")",":","The","title","of","the","plot",".","return_output","(","bool",",","optional",",","default=False",")",":","Returns","the","output","(","s",")","of","optimization","if","set","to","True",".","Returns",":","output","(","list","of","torch.Tensor",")",":","With","dimentions",":","math",":","`","(","num_iter",",","C",",","H",",","W",")","`",".","The","size","of","the","image","is","determined","by","`","img_size","`","attribute","which","defaults","to","224","."]
code: def deepdream(
      self,
      img_path,
      layer,
      filter_idx,
      lr=0.1,
      num_iter=20,
      figsize=(4, 4),
      title="DeepDream",
      return_output=False,
  ):
      """Creates DeepDream.
  
      It applies the optimization on the image provided. The image is loaded
      and made into a torch.Tensor that is compatible as the input to the
      network.
  
      Read the original blog post by Google for more information on
      `DeepDream <https://ai.googleblog.com/2015/06/inceptionism-going-deeper-into-neural.html>`_.
  
      Args:
          img_path (str): A path to the image you want to apply DeepDream on
          layer (torch.nn.modules.conv.Conv2d): The target Conv2d layer from
              which the filter to be chosen, based on `filter_idx`.
          filter_idx (int): The index of the target filter.
          lr (float, optional, default=.1): The step size of optimization.
          num_iter (int, optional, default=30): The number of iteration for
              the gradient ascent operation.
          figsize (tuple, optional, default=(4, 4)): The size of the plot.
              Relevant in case 1 above.
          title (str, optional default='Conv2d'): The title of the plot.
          return_output (bool, optional, default=False): Returns the
              output(s) of optimization if set to True.
  
      Returns:
          output (list of torch.Tensor): With dimentions
              :math:`(num_iter, C, H, W)`. The size of the image is
              determined by `img_size` attribute which defaults to 224.
  
      """  # noqa
  
      input_ = apply_transforms(load_image(img_path), self.img_size)
  
      self._lr = lr
      output = self.optimize(
          layer, filter_idx, input_, num_iter=num_iter
      )
  
      plt.figure(figsize=figsize)
      plt.axis("off")
      plt.title(title)
  
      plt.imshow(
          format_for_plotting(
              standardize_and_clip(
                  output[-1], saturation=0.15, brightness=0.7
              )
          )
      )
      # noqa
  
      if return_output:
          return output
  
imports: import numpy
  import matplotlib.pyplot
  import torch
  import torch.nn
  from flashtorch.utils import apply_transforms, format_for_plotting, load_image, standardize_and_clip
label_desc: Use image node_id 10 for calling the GradientAscent obj's underlying member method code with example usage: obj.deepdream(img_path, layer, filter_idx, lr, num_iter, figsize, title, return_output) and returns: output