docstr: Creates image harmonization model supported by the features extracted from the pre-trained backbone.
  
  Parameters
  ----------
  model : nn.Module
      Image harmonization model takes image and mask as an input and handles features from the backbone network.
  backbone : nn.Module
      Backbone model accepts RGB image and returns a list of features.
  downsize_backbone_input : bool
      If the input image should be half-sized for the backbone.
  mask_fusion : str
      How to fuse the binary mask with the backbone input:
      'sum': apply convolution to the mask and sum it with the output of the first convolution in the backbone
      'rgb': concatenate the mask to the input image and translate it back to 3 channels with convolution
      otherwise: do not fuse mask with the backbone input
  backbone_conv1_channels : int
      If mask_fusion is 'sum', define the number of channels for the convolution applied to the mask.
docstr_tok: ["Creates","image","harmonization","model","supported","by","the","features","extracted","from","the","pre-trained","backbone",".","Parameters","--","--","--","--","--","model",":","nn.Module","Image","harmonization","model","takes","image","and","mask","as","an","input","and","handles","features","from","the","backbone","network",".","backbone",":","nn.Module","Backbone","model","accepts","RGB","image","and","returns","a","list","of","features",".","downsize_backbone_input",":","bool","If","the","input","image","should","be","half-sized","for","the","backbone",".","mask_fusion",":","str","How","to","fuse","the","binary","mask","with","the","backbone","input",":","'sum","'",":","apply","convolution","to","the","mask","and","sum","it","with","the","output","of","the","first","convolution","in","the","backbone","'rgb","'",":","concatenate","the","mask","to","the","input","image","and","translate","it","back","to","3","channels","with","convolution","otherwise",":","do","not","fuse","mask","with","the","backbone","input","backbone_conv1_channels",":","int","If","mask_fusion","is","'sum","'",",","define","the","number","of","channels","for","the","convolution","applied","to","the","mask","."]
code: def __init__(
      self,
      model,
      backbone,
      downsize_backbone_input=False,
      mask_fusion="sum",
      backbone_conv1_channels=64,
  ):
      """
      Creates image harmonization model supported by the features extracted from the pre-trained backbone.
  
      Parameters
      ----------
      model : nn.Module
          Image harmonization model takes image and mask as an input and handles features from the backbone network.
      backbone : nn.Module
          Backbone model accepts RGB image and returns a list of features.
      downsize_backbone_input : bool
          If the input image should be half-sized for the backbone.
      mask_fusion : str
          How to fuse the binary mask with the backbone input:
          'sum': apply convolution to the mask and sum it with the output of the first convolution in the backbone
          'rgb': concatenate the mask to the input image and translate it back to 3 channels with convolution
          otherwise: do not fuse mask with the backbone input
      backbone_conv1_channels : int
          If mask_fusion is 'sum', define the number of channels for the convolution applied to the mask.
      """
      super(IHModelWithBackbone, self).__init__()
      self.downsize_backbone_input = downsize_backbone_input
      self.mask_fusion = mask_fusion
  
      self.backbone = backbone
      self.model = model
  
      if mask_fusion == "rgb":
          self.fusion = SimpleInputFusion()
      elif mask_fusion == "sum":
          self.mask_conv = nn.Sequential(
              nn.Conv2d(
                  1,
                  backbone_conv1_channels,
                  kernel_size=3,
                  stride=2,
                  padding=1,
                  bias=True,
              ),
              ScaleLayer(init_value=0.1, lr_mult=1),
          )
  
file_path: carefree-learn/cflearn/api/cv/third_party/iharm/model/backboned/ih_model.py
imports: import torch
  import torch.nn
  from ..ops import ScaleLayer
  from ..ops import SimpleInputFusion
label_desc: Use image node_id 1 to create a new IHModelWithBackbone object from inherited base classes: nn with example: obj = IHModelWithBackbone(model, backbone, downsize_backbone_input, mask_fusion, backbone_conv1_channels)