class_docstr: Check if the average of each color channel is the same between the train and test dataset.
class_docstr_tok: ["Check","if","the","average","of","each","color","channel","is","the","same","between","the","train","and","test","dataset","."]
docstr: Add a condition verifying that the color averages haven't changed by more than change_ratio%.
docstr_tok: ["Add","a","condition","verifying","that","the","color","averages","have","n't","changed","by","more","than","change_ratio","%","."]
code: def add_condition_color_average_change_not_greater_than(
      self, change_ratio: float = 0.1
  ) -> ConditionResult:
      """Add a condition verifying that the color averages haven't changed by more than change_ratio%."""
  
      def condition(check_result: CheckResult) -> ConditionResult:
          failing_channels = []
          # Iterate over the color averages and verify that they haven't changed by more than change_ratio
          for channel in check_result.value[
              DatasetKind.TRAIN.value
          ].keys():
              if (
                  abs(
                      check_result.value[DatasetKind.TRAIN.value][
                          channel
                      ]
                      - check_result.value[DatasetKind.TEST.value][
                          channel
                      ]
                  )
                  > change_ratio
              ):
                  failing_channels.append(channel)
  
          # If there are failing channels, return a condition result with the failing channels
          if failing_channels:
              return ConditionResult(
                  ConditionCategory.FAIL,
                  f"The color averages have changes by more than threshold in the channels"
                  f" {failing_channels}.",
              )
          else:
              return ConditionResult(ConditionCategory.PASS)
  
      return self.add_condition(
          f"Change in color averages not greater than {change_ratio:.2%}",
          condition,
      )
  
imports: import typing
  import numpy
  from deepchecks.core.check_result import CheckResult
  from deepchecks.core.checks import DatasetKind
  from deepchecks.core.condition import ConditionCategory
  from deepchecks.vision.base_checks import TrainTestCheck
  from deepchecks.vision.context import Context
  from deepchecks.vision.vision_data.batch_wrapper import BatchWrapper
  from deepchecks.vision.datasets.detection.coco_torch import load_dataset
  import pandas
  import plotly.express
  from deepchecks.core import ConditionResult
label_desc: Use image node_id 5 for calling the ColorAveragesCheck obj's underlying member method code with example usage: obj.add_condition_color_average_change_not_greater_than(change_ratio) and returns: self, ConditionResult, ConditionResult