code: def _find_penultimate_layer(model, layer_idx, penultimate_layer_idx):
      """Searches for the nearest penultimate `Conv` or `Pooling` layer.
  
      Args:
          model: The `keras.models.Model` instance.
          layer_idx: The layer index within `model.layers`.
          penultimate_layer_idx: The pre-layer to `layer_idx`. If set to None, the nearest penultimate
              `Conv` or `Pooling` layer is used.
  
      Returns:
          The penultimate layer.
      """
      if penultimate_layer_idx is None:
          for idx, layer in utils.reverse_enumerate(
              model.layers[: layer_idx - 1]
          ):
              if isinstance(layer, Wrapper):
                  layer = layer.layer
              if isinstance(
                  layer, (_Conv, _Pooling1D, _Pooling2D, _Pooling3D)
              ):
                  penultimate_layer_idx = idx
                  break
  
      if penultimate_layer_idx is None:
          raise ValueError(
              "Unable to determine penultimate `Conv` or `Pooling` "
              "layer for layer_idx: {}".format(layer_idx)
          )
  
      # Handle negative indexing otherwise the next check can fail.
      if layer_idx < 0:
          layer_idx = len(model.layers) + layer_idx
      if penultimate_layer_idx > layer_idx:
          raise ValueError(
              "`penultimate_layer_idx` needs to be before `layer_idx`"
          )
  
      return model.layers[penultimate_layer_idx]
  
file_path: keras-vis/vis/visualization/saliency.py
imports: from __future__ import absolute_import
  import numpy
  from scipy.ndimage.interpolation import zoom
  from keras.layers.convolutional import _Conv
  from keras.layers.pooling import _Pooling1D, _Pooling2D, _Pooling3D
  from keras.layers.wrappers import Wrapper
  from keras import backend
  from ..losses import ActivationMaximization
  from ..optimizer import Optimizer
  from ..backprop_modifiers import get
  from ..utils import utils
label_desc: Use image node_id 1 for calling a global function with example usage: _find_penultimate_layer(model, layer_idx, penultimate_layer_idx) and returns: model