code: def _alert_to_json(alert):
      # TODO(cais): Replace this with Alert.to_json() when supported by the
      # backend.
      from tensorflow.python.debug.lib import debug_events_monitors
  
      if isinstance(alert, debug_events_monitors.InfNanAlert):
          return {
              "alert_type": "InfNanAlert",
              "op_type": alert.op_type,
              "output_slot": alert.output_slot,
              # TODO(cais): Once supported by backend, add 'op_name' key
              # for intra-graph execution events.
              "size": alert.size,
              "num_neg_inf": alert.num_neg_inf,
              "num_pos_inf": alert.num_pos_inf,
              "num_nan": alert.num_nan,
              "execution_index": alert.execution_index,
              "graph_execution_trace_index": alert.graph_execution_trace_index,
          }
      else:
          raise TypeError(
              "Unrecognized alert subtype: %s" % type(alert)
          )
  
imports: import threading
  from tensorboard import errors
label_desc: Use image node_id 2 for calling a global function with example usage: _alert_to_json(alert) and returns: dict