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: Compute the color averages and return them. Also display a histogram comparing train and test.
docstr_tok: ["Compute","the","color","averages","and","return","them",".","Also","display","a","histogram","comparing","train","and","test","."]
code: def compute(self, context: Context):
      """Compute the color averages and return them. Also display a histogram comparing train and test."""
      # Divide by the number of pixels to get the average pixel value per color channel
      for dataset_kind in DatasetKind:
          self._color_averages[dataset_kind.value] /= self._pixel_count[
              dataset_kind.value
          ]
      # Return the color averages in a dict by channel name
      return_value = {
          d_kind: dict(zip(self.channel_names, color_averages))
          for d_kind, color_averages in self._color_averages.items()
      }
  
      # Display a histogram comparing train and test
      color_averages_df = (
          pd.DataFrame(return_value).unstack().reset_index()
      )
      color_averages_df.columns = ["Dataset", "Channel", "Pixel Value"]
      fig = px.histogram(
          color_averages_df,
          x="Dataset",
          y="Pixel Value",
          color="Channel",
          barmode="group",
          histfunc="avg",
          color_discrete_sequence=[
              "rgb(255,0,0)",
              "rgb(0,255,0)",
              "rgb(0,0,255)",
          ],
          title="Color Averages Histogram",
      )
      return CheckResult(return_value, display=[fig])
  
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 4 for calling the ColorAveragesCheck obj's underlying member method code with example usage: obj.compute(context) and returns: CheckResult