class_docstr: A DoFn that loads tfjs models and predicts.
class_docstr_tok: ["A","DoFn","that","loads","tfjs","models","and","predicts","."]
code: def setup(self):
      super().setup()
      self._binary_path = get_tfjs_binary()
  
      base_path = tempfile.mkdtemp()
      base_model_path = os.path.join(base_path, _MODELS_SUBDIR)
  
      self._model_properties = {}
      for model_name, model_path in self._src_model_paths.items():
          with tf.io.gfile.GFile(
              os.path.join(model_path, _MODEL_JSON)
          ) as f:
              model_json = json.load(f)
              if (
                  "userDefinedMetadata" in model_json
                  and "signature" in model_json["userDefinedMetadata"]
              ):
                  model_signature = model_json["userDefinedMetadata"][
                      "signature"
                  ]
              else:
                  model_signature = model_json["signature"]
              model_inputs = {}
              for k, v in model_signature["inputs"].items():
                  model_inputs[k] = _InputSpec(
                      [int(d["size"]) for d in v["tensorShape"]["dim"]],
                      v["dtype"],
                  )
  
              model_outputs = {}
              for k, v in model_signature["outputs"].items():
                  model_outputs[k] = [
                      int(i["size"]) for i in v["tensorShape"]["dim"]
                  ]
  
          cur_model_path = os.path.join(base_model_path, model_name)
          self._model_properties[model_name] = {
              "inputs": model_inputs,
              "outputs": model_outputs,
              "path": cur_model_path,
          }
  
          # We copy models to local tmp storage so that the tfjs binary can
          # access them.
          tf.io.gfile.makedirs(cur_model_path)
          for directory, _, files in tf.io.gfile.walk(model_path):
              cur_path = os.path.join(
                  cur_model_path, os.path.relpath(directory, model_path)
              )
              tf.io.gfile.makedirs(cur_path)
              for f in files:
                  src_path = os.path.join(directory, f)
                  tf.io.gfile.copy(src_path, os.path.join(cur_path, f))
  
imports: import collections
  import copy
  import json
  import os
  import subprocess
  import tempfile
  from typing import Dict, List, NamedTuple, Sequence, Union
  import uuid
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.extractors.tfjs_predict_extractor_util import get_tfjs_binary
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 2 for calling the _TFJSPredictionDoFn obj's underlying member method code with example usage: obj.setup() without return types