class_docstr: Interface for torch models.
class_docstr_tok: ["Interface","for","torch","models","."]
docstr: Consider the first layer neuron before non-linearity: z = w^T * x1 + b1. We update
  the bias b1 to b2:= b1 - w^T * m (= 2*b1 - (w^T * m + b1)). The operation is necessary
  for Input Invariance metric.
  
  
  Parameters
  ----------
  input_shift: Union[int, float]
      Shift to be applied.
  shape: tuple
      Model input shape, ndim = 4.
  
  Returns
  -------
  random_layer_model: torch.nn
      The resulting model with a shifted first layer.
docstr_tok: ["Consider","the","first","layer","neuron","before","non-linearity",":","z","=","w^T","*","x1","+","b1",".","We","update","the","bias","b1","to","b2",":","=","b1","-","w^T","*","m","(","=","2","*","b1","-","(","w^T","*","m","+","b1",")",")",".","The","operation","is","necessary","for","Input","Invariance","metric",".","Parameters","--","--","--","--","--","input_shift",":","Union","[","int",",","float","]","Shift","to","be","applied",".","shape",":","tuple","Model","input","shape",",","ndim","=","4",".","Returns","--","--","--","-","random_layer_model",":","torch.nn","The","resulting","model","with","a","shifted","first","layer","."]
code: def add_mean_shift_to_first_layer(
      self,
      input_shift: Union[int, float],
      shape: tuple,
  ):
      """
      Consider the first layer neuron before non-linearity: z = w^T * x1 + b1. We update
      the bias b1 to b2:= b1 - w^T * m (= 2*b1 - (w^T * m + b1)). The operation is necessary
      for Input Invariance metric.
  
  
      Parameters
      ----------
      input_shift: Union[int, float]
          Shift to be applied.
      shape: tuple
          Model input shape, ndim = 4.
  
      Returns
      -------
      random_layer_model: torch.nn
          The resulting model with a shifted first layer.
      """
      with torch.no_grad():
          new_model = deepcopy(self.model)
  
          modules = [l for l in new_model.named_modules()]
          module = modules[1]
  
          delta = torch.zeros(size=shape).fill_(input_shift)
          fw = module[1].forward(delta)[0]
  
          for i in range(module[1].out_channels):
              if self.channel_first:
                  module[1].bias[i] = torch.nn.Parameter(
                      2 * module[1].bias[i] - torch.unique(fw[i])[0]
                  )
              else:
                  module[1].bias[i] = torch.nn.Parameter(
                      2 * module[1].bias[i]
                      - torch.unique(fw[..., i])[0]
                  )
  
      return new_model
  
imports: import copy
  from contextlib import suppress
  from copy import deepcopy
  from typing import Any, Dict, Optional, Tuple, List, Union, Generator
  import warnings
  import logging
  import numpy
  import torch
  from torch import nn
  from functools import lru_cache
  from quantus.helpers import utils
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 11 for calling the PyTorchModel obj's underlying member method code with example usage: obj.add_mean_shift_to_first_layer(input_shift, shape) and returns: new_model