class_docstr: Module for robust geometry estimation with RANSAC. https://en.wikipedia.org/wiki/Random_sample_consensus.
  
  Args:
      model_type: type of model to estimate: "homography", "fundamental", "fundamental_7pt",
          "homography_from_linesegments".
      inliers_threshold: threshold for the correspondence to be an inlier.
      batch_size: number of generated samples at once.
      max_iterations: maximum batches to generate. Actual number of models to try is ``batch_size * max_iterations``.
      confidence: desired confidence of the result, used for the early stopping.
      max_local_iterations: number of local optimization (polishing) iterations.
class_docstr_tok: ["Module","for","robust","geometry","estimation","with","RANSAC",".","https",":","\/\/en.wikipedia.org\/wiki\/Random_sample_consensus",".","Args",":","model_type",":","type","of","model","to","estimate",":","``","homography","''",",","``","fundamental","''",",","``","fundamental_7pt","''",",","``","homography_from_linesegments","''",".","inliers_threshold",":","threshold","for","the","correspondence","to","be","an","inlier",".","batch_size",":","number","of","generated","samples","at","once",".","max_iterations",":","maximum","batches","to","generate",".","Actual","number","of","models","to","try","is","``","batch_size","*","max_iterations","``",".","confidence",":","desired","confidence","of","the","result",",","used","for","the","early","stopping",".","max_local_iterations",":","number","of","local","optimization","(","polishing",")","iterations","."]
docstr: Main forward method to execute the RANSAC algorithm.
  
  Args:
      kp1: source image keypoints :math:`(N, 2)`.
      kp2: distance image keypoints :math:`(N, 2)`.
      weights: optional correspondences weights. Not used now.
  
  Returns:
      - Estimated model, shape of :math:`(1, 3, 3)`.
      - The inlier/outlier mask, shape of :math:`(1, N)`, where N is number of input correspondences.
docstr_tok: ["Main","forward","method","to","execute","the","RANSAC","algorithm",".","Args",":","kp1",":","source","image","keypoints",":","math",":","`","(","N",",","2",")","`",".","kp2",":","distance","image","keypoints",":","math",":","`","(","N",",","2",")","`",".","weights",":","optional","correspondences","weights",".","Not","used","now",".","Returns",":","-","Estimated","model",",","shape","of",":","math",":","`","(","1",",","3",",","3",")","`",".","-","The","inlier\/outlier","mask",",","shape","of",":","math",":","`","(","1",",","N",")","`",",","where","N","is","number","of","input","correspondences","."]
code: def forward(
      self, kp1: Tensor, kp2: Tensor, weights: Optional[Tensor] = None
  ) -> Tuple[Tensor, Tensor]:
      r"""Main forward method to execute the RANSAC algorithm.
  
      Args:
          kp1: source image keypoints :math:`(N, 2)`.
          kp2: distance image keypoints :math:`(N, 2)`.
          weights: optional correspondences weights. Not used now.
  
      Returns:
          - Estimated model, shape of :math:`(1, 3, 3)`.
          - The inlier/outlier mask, shape of :math:`(1, N)`, where N is number of input correspondences.
      """
      self.validate_inputs(kp1, kp2, weights)
      best_score_total: float = float(self.minimal_sample_size)
      num_tc: int = len(kp1)
      best_model_total = zeros(3, 3, dtype=kp1.dtype, device=kp1.device)
      inliers_best_total: Tensor = zeros(
          num_tc, 1, device=kp1.device, dtype=torch.bool
      )
      for i in range(self.max_iter):
          # Sample minimal samples in batch to estimate models
          idxs = self.sample(
              self.minimal_sample_size,
              num_tc,
              self.batch_size,
              kp1.device,
          )
          kp1_sampled = kp1[idxs]
          kp2_sampled = kp2[idxs]
  
          kp1_sampled, kp2_sampled = self.remove_bad_samples(
              kp1_sampled, kp2_sampled
          )
          if len(kp1_sampled) == 0:
              continue
          # Estimate models
          models = self.estimate_model_from_minsample(
              kp1_sampled, kp2_sampled
          )
          models = self.remove_bad_models(models)
          if (models is None) or (len(models) == 0):
              continue
          # Score the models and select the best one
          model, inliers, model_score = self.verify(
              kp1, kp2, models, self.inl_th
          )
          # Store far-the-best model and (optionally) do a local optimization
          if model_score > best_score_total:
              # Local optimization
              for lo_step in range(self.max_lo_iters):
                  model_lo = self.polish_model(kp1, kp2, inliers)
                  if (model_lo is None) or (len(model_lo) == 0):
                      continue
                  _, inliers_lo, score_lo = self.verify(
                      kp1, kp2, model_lo, self.inl_th
                  )
                  # print (f"Orig score = {best_model_score}, LO score = {score_lo} TC={num_tc}")
                  if score_lo > model_score:
                      model = model_lo.clone()[0]
                      inliers = inliers_lo.clone()
                      model_score = score_lo
                  else:
                      break
              # Now storing the best model
              best_model_total = model.clone()
              inliers_best_total = inliers.clone()
              best_score_total = model_score
  
              # Should we already stop?
              new_max_iter = int(
                  self.max_samples_by_conf(
                      int(best_score_total),
                      num_tc,
                      self.minimal_sample_size,
                      self.confidence,
                  )
              )
              # print (f"New max_iter = {new_max_iter}")
              # Stop estimation, if the model is very good
              if (i + 1) * self.batch_size >= new_max_iter:
                  break
      # local optimization with all inliers for better precision
      return best_model_total, inliers_best_total
  
file_path: kornia/kornia/geometry/ransac.py
imports: import math
  from functools import partial
  from typing import Callable, Optional, Tuple
  import torch
  from kornia.core import Device, Module, Tensor, zeros
  from kornia.core.check import KORNIA_CHECK_SHAPE
  from kornia.geometry import find_fundamental, find_homography_dlt, find_homography_dlt_iterated, find_homography_lines_dlt, find_homography_lines_dlt_iterated, symmetrical_epipolar_distance
  from kornia.geometry.homography import line_segment_transfer_error_one_way, oneway_transfer_error, sample_is_valid_for_homography
label_desc: Use image node_id 10 for calling the RANSAC obj's underlying member method code with example usage: obj.forward(kp1, kp2, weights) and returns: best_model_total,  inliers_best_total