class_docstr: Abstract base class to build Keras callbacks for model prediction visualization.
  
  You can build callbacks for visualizing model predictions `on_epoch_end`
  that can be passed to `model.fit()` for classification, object detection,
  segmentation, etc. tasks.
  
  To use this, inherit from this base callback class and implement the
  `add_ground_truth` and `add_model_prediction` methods.
  
  The base class will take care of the following:
  - Initialize `data_table` for logging the ground truth and
      `pred_table` for predictions.
  - The data uploaded to `data_table` is used as a reference for the
      `pred_table`. This is to reduce the memory footprint. The `data_table_ref`
      is a list that can be used to access the referenced data.
      Check out the example below to see how it's done.
  - Log the tables to W&B as W&B Artifacts.
  - Each new `pred_table` is logged as a new version with aliases.
  
  Example:
      ```python
      class WandbClfEvalCallback(WandbEvalCallback):
          def __init__(self, validation_data, data_table_columns, pred_table_columns):
              super().__init__(data_table_columns, pred_table_columns)
  
              self.x = validation_data[0]
              self.y = validation_data[1]
  
          def add_ground_truth(self):
              for idx, (image, label) in enumerate(zip(self.x, self.y)):
                  self.data_table.add_data(idx, wandb.Image(image), label)
  
          def add_model_predictions(self, epoch):
              preds = self.model.predict(self.x, verbose=0)
              preds = tf.argmax(preds, axis=-1)
  
              data_table_ref = self.data_table_ref
              table_idxs = data_table_ref.get_index()
  
              for idx in table_idxs:
                  pred = preds[idx]
                  self.pred_table.add_data(
                      epoch,
                      data_table_ref.data[idx][0],
                      data_table_ref.data[idx][1],
                      data_table_ref.data[idx][2],
                      pred,
                  )
  
  
      model.fit(
          x,
          y,
          epochs=2,
          validation_data=(x, y),
          callbacks=[
              WandbClfEvalCallback(
                  validation_data=(x, y),
                  data_table_columns=["idx", "image", "label"],
                  pred_table_columns=["epoch", "idx", "image", "label", "pred"],
              )
          ],
      )
      ```
  
  To have more fine-grained control, you can override the `on_train_begin` and
  `on_epoch_end` methods. If you want to log the samples after N batched, you
  can implement `on_train_batch_end` method.
class_docstr_tok: ["Abstract","base","class","to","build","Keras","callbacks","for","model","prediction","visualization",".","You","can","build","callbacks","for","visualizing","model","predictions","`","on_epoch_end","`","that","can","be","passed","to","`","model.fit","(",")","`","for","classification",",","object","detection",",","segmentation",",","etc",".","tasks",".","To","use","this",",","inherit","from","this","base","callback","class","and","implement","the","`","add_ground_truth","`","and","`","add_model_prediction","`","methods",".","The","base","class","will","take","care","of","the","following",":","-","Initialize","`","data_table","`","for","logging","the","ground","truth","and","`","pred_table","`","for","predictions",".","-","The","data","uploaded","to","`","data_table","`","is","used","as","a","reference","for","the","`","pred_table","`",".","This","is","to","reduce","the","memory","footprint",".","The","`","data_table_ref","`","is","a","list","that","can","be","used","to","access","the","referenced","data",".","Check","out","the","example","below","to","see","how","it","'s","done",".","-","Log","the","tables","to","W","&","B","as","W","&","B","Artifacts",".","-","Each","new","`","pred_table","`","is","logged","as","a","new","version","with","aliases",".","Example",":","``","`","python","class","WandbClfEvalCallback","(","WandbEvalCallback",")",":","def","__init__","(","self",",","validation_data",",","data_table_columns",",","pred_table_columns",")",":","super","(",")",".__init__","(","data_table_columns",",","pred_table_columns",")","self.x","=","validation_data","[","0","]","self.y","=","validation_data","[","1","]","def","add_ground_truth","(","self",")",":","for","idx",",","(","image",",","label",")","in","enumerate","(","zip","(","self.x",",","self.y",")",")",":","self.data_table.add_data","(","idx",",","wandb.Image","(","image",")",",","label",")","def","add_model_predictions","(","self",",","epoch",")",":","preds","=","self.model.predict","(","self.x",",","verbose=0",")","preds","=","tf.argmax","(","preds",",","axis=-1",")","data_table_ref","=","self.data_table_ref","table_idxs","=","data_table_ref.get_index","(",")","for","idx","in","table_idxs",":","pred","=","preds","[","idx","]","self.pred_table.add_data","(","epoch",",","data_table_ref.data","[","idx","]","[","0","]",",","data_table_ref.data","[","idx","]","[","1","]",",","data_table_ref.data","[","idx","]","[","2","]",",","pred",",",")","model.fit","(","x",",","y",",","epochs=2",",","validation_data=","(","x",",","y",")",",","callbacks=","[","WandbClfEvalCallback","(","validation_data=","(","x",",","y",")",",","data_table_columns=","[","``","idx","''",",","``","image","''",",","``","label","''","]",",","pred_table_columns=","[","``","epoch","''",",","``","idx","''",",","``","image","''",",","``","label","''",",","``","pred","''","]",",",")","]",",",")","``","`","To","have","more","fine-grained","control",",","you","can","override","the","`","on_train_begin","`","and","`","on_epoch_end","`","methods",".","If","you","want","to","log","the","samples","after","N","batched",",","you","can","implement","`","on_train_batch_end","`","method","."]
docstr: Add ground truth data to `data_table`.
  
  Use this method to write the logic for adding validation/training data to
  `data_table` initialized using `init_data_table` method.
  
  Example:
      ```python
      for idx, data in enumerate(dataloader):
          self.data_table.add_data(idx, data)
      ```
  This method is called once `on_train_begin` or equivalent hook.
docstr_tok: ["Add","ground","truth","data","to","`","data_table","`",".","Use","this","method","to","write","the","logic","for","adding","validation\/training","data","to","`","data_table","`","initialized","using","`","init_data_table","`","method",".","Example",":","``","`","python","for","idx",",","data","in","enumerate","(","dataloader",")",":","self.data_table.add_data","(","idx",",","data",")","``","`","This","method","is","called","once","`","on_train_begin","`","or","equivalent","hook","."]
code: def add_ground_truth(
      self, logs: Optional[Dict[str, float]] = None
  ) -> None:
      """Add ground truth data to `data_table`.
  
      Use this method to write the logic for adding validation/training data to
      `data_table` initialized using `init_data_table` method.
  
      Example:
          ```python
          for idx, data in enumerate(dataloader):
              self.data_table.add_data(idx, data)
          ```
      This method is called once `on_train_begin` or equivalent hook.
      """
      raise NotImplementedError(
          f"{self.__class__.__name__}.add_ground_truth"
      )
  
file_path: wandb/wandb/integration/keras/callbacks/tables_builder.py
imports: import abc
  from typing import Any, Dict, List, Optional
  from tensorflow.keras.callbacks import Callback
  import wandb
  from wandb.sdk.lib import telemetry
label_desc: Use image node_id 4 for calling the WandbEvalCallback obj's underlying member method code with example usage: obj.add_ground_truth(logs) without return types