code: def test_calculate_plot_attention_ctc(module, num_encs, model_dict):
      args = make_arg(num_encs=num_encs, **model_dict)
      m = importlib.import_module(module)
      model = m.E2E([2 for _ in range(num_encs)], 2, args)
  
      # test attention plot
      dummy_json = make_dummy_json(
          num_encs, [2, 3], [2, 3], idim=2, odim=2, num_inputs=num_encs
      )
      batchset = make_batchset(
          dummy_json, 2, 2**10, 2**10, shortest_first=True
      )
      att_ws = model.calculate_all_attentions(
          *convert_batch(
              batchset[0],
              "pytorch",
              idim=2,
              odim=2,
              num_inputs=num_encs,
          )
      )
      from espnet.asr.asr_utils import PlotAttentionReport
  
      tmpdir = tempfile.mkdtemp()
      plot = PlotAttentionReport(
          model.calculate_all_attentions,
          batchset[0],
          tmpdir,
          None,
          None,
          None,
      )
      for i in range(num_encs):
          # att-encoder
          att_w = plot.trim_attention_weight("utt_%d" % 0, att_ws[i][0])
          plot._plot_and_save_attention(
              att_w, "{}/att{}.png".format(tmpdir, i)
          )
      # han
      att_w = plot.trim_attention_weight(
          "utt_%d" % 0, att_ws[num_encs][0]
      )
      plot._plot_and_save_attention(
          att_w, "{}/han.png".format(tmpdir), han_mode=True
      )
  
      # test CTC plot
      ctc_probs = model.calculate_all_ctc_probs(
          *convert_batch(
              batchset[0],
              "pytorch",
              idim=2,
              odim=2,
              num_inputs=num_encs,
          )
      )
      from espnet.asr.asr_utils import PlotCTCReport
  
      tmpdir = tempfile.mkdtemp()
      plot = PlotCTCReport(
          model.calculate_all_ctc_probs,
          batchset[0],
          tmpdir,
          None,
          None,
          None,
      )
      if args.mtlalpha > 0:
          for i in range(num_encs):
              # ctc-encoder
              plot._plot_and_save_ctc(
                  ctc_probs[i][0], "{}/ctc{}.png".format(tmpdir, i)
              )
  
imports: from __future__ import division
  import argparse
  import importlib
  import os
  import tempfile
  from test.utils_test import make_dummy_json
  import numpy
  import pytest
  import torch
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.utils.training.batchfy import make_batchset
label_desc: Use image node_id 14 for calling a global function with example usage: test_calculate_plot_attention_ctc(module, num_encs, model_dict) without return types