code: def namedtuple_to_dict(obj):
      if isinstance(obj, Tensor):
          return obj.item()
      if hasattr(obj, "_asdict"):  # detect namedtuple
          return dict(
              zip(
                  obj._fields,
                  (namedtuple_to_dict(item) for item in obj),
              )
          )
      elif isinstance(obj, str):  # iterables - strings
          return obj
      elif hasattr(obj, "keys"):  # iterables - mapping
          return dict(
              zip(
                  obj.keys(),
                  (namedtuple_to_dict(item) for item in obj.values()),
              )
          )
      elif hasattr(obj, "__iter__"):  # iterables - sequence
          return type(obj)((namedtuple_to_dict(item) for item in obj))
      else:  # non-iterable cannot contain namedtuples
          return obj
  
file_path: captum/captum/insights/attr_vis/server.py
imports: import logging
  import os
  import socket
  import threading
  from time import sleep
  from typing import Optional
  from captum.log import log_usage
  from flask import Flask, jsonify, render_template, request
  from flask_compress import Compress
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: namedtuple_to_dict(obj) and returns: obj, dict, obj, dict, type, obj