{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9119f12a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import autoreload\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%reload_ext autoreload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "569a8332",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/anaconda3/lib/python3.8/site-packages/scipy/__init__.py:138: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.0)\n",
      "  warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion} is required for this version of \"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "importing Jupyter notebook from utils.ipynb\n",
      "importing Jupyter notebook from bandERB.ipynb\n",
      "importing Jupyter notebook from params.ipynb\n",
      "importing Jupyter notebook from loss.ipynb\n",
      "importing Jupyter notebook from dataloader.ipynb\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import tensorflow.keras as keras\n",
    "from tensorflow.keras import backend as K\n",
    "\n",
    "import numpy as np\n",
    "import random\n",
    "import os\n",
    "\n",
    "import import_ipynb\n",
    "\n",
    "from utils import mask_operations, df_operations, synthesis_frame, df_operations_wo_alpha\n",
    "from params import model_params\n",
    "from dataloader import read_tfrecod_data\n",
    "from bandERB import ERBBand, ERB_pro_matrix\n",
    "\n",
    "import librosa\n",
    "from soundfile import write\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "09c0924b",
   "metadata": {},
   "outputs": [],
   "source": [
    "os.environ[\"CUDA_DEVICE_ORDER\"] = \"PCI_BUS_ID\"   # see issue #152\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"\"\n",
    "# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "aaba553e",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = model_params('config.ini')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "19fc9862",
   "metadata": {},
   "outputs": [],
   "source": [
    "def band_unit_norm(x, s, alpha=0.99):\n",
    "    s = np.linalg.norm(x) * (1-alpha) + s * alpha\n",
    "    x = x / (np.sqrt(s)+1e-12)\n",
    "    return x, s\n",
    "def band_mean_norm_erb(x, s, alpha=0.99):\n",
    "    s = x * (1-alpha) + s * alpha\n",
    "    x = (x-s) / 40\n",
    "    return x, s\n",
    "\n",
    "def erb_norm(x, mean_init=[-60.0,-90.0]):\n",
    "    # x : [T,F,C]\n",
    "    # state: [F,C]\n",
    "    x = np.reshape(x,(x.shape[0],x.shape[1],1))\n",
    "    shape = x.shape\n",
    "    state = np.linspace(mean_init[0],mean_init[1],shape[-2]) # [F,]\n",
    "    state *= 0\n",
    "    state = np.reshape(state, (1, shape[-2]))\n",
    "    state = np.tile(state, (1, shape[-1])) # [C,F]\n",
    "    \n",
    "    x_i_list = []\n",
    "    state_list = []\n",
    "    \n",
    "    for i in range(shape[-1]):\n",
    "        x_i = np.split(x, shape[-1], axis=-1) \n",
    "        state_i = np.split(state, shape[-1], axis=-1)\n",
    "        \n",
    "        x_ij_list = []\n",
    "        state_tmp = state_i[i]\n",
    "        for j in range(shape[-3]):\n",
    "            x_ij = np.split(x_i[i], shape[0], axis=0) \n",
    "            x_tmp, state_tmp = band_mean_norm_erb(np.squeeze(x_ij[j],-1), state_tmp)\n",
    "            x_ij_list.append(x_tmp)\n",
    "        \n",
    "        x_i_list.append(np.stack(x_ij_list,1))\n",
    "        state_list.append(state_tmp)\n",
    "    x = np.squeeze(np.stack(x_i_list,-1),0)\n",
    "    return x\n",
    "\n",
    "def unit_norm(x, unit_init=[0.001, 0.0001]):\n",
    "    # x : [T,F,C]\n",
    "    # state: [F,C]\n",
    "    x = np.reshape(x,(x.shape[0],x.shape[1],1))\n",
    "    shape = x.shape\n",
    "    state = np.linspace(unit_init[0],unit_init[1],shape[-2]) # [F,]\n",
    "    state *= 0\n",
    "    state = np.reshape(state, (1, shape[-2]))\n",
    "    state = np.tile(state, (1, shape[-1])) # [C,F]\n",
    "    \n",
    "    x_i_list = []\n",
    "    state_list = []\n",
    "    \n",
    "    for i in range(shape[-1]):\n",
    "        x_i = np.split(x, shape[-1], axis=-1) \n",
    "        state_i = np.split(state, shape[-1], axis=-1)\n",
    "        \n",
    "        x_ij_list = []\n",
    "        state_tmp = state_i[i]\n",
    "        for j in range(shape[-3]):\n",
    "            x_ij = np.split(x_i[i], shape[0], axis=0) \n",
    "            x_tmp, state_tmp = band_unit_norm(np.squeeze(x_ij[j],-1), state_tmp)\n",
    "            x_ij_list.append(x_tmp)\n",
    "        \n",
    "        x_i_list.append(np.stack(x_ij_list,1))\n",
    "        state_list.append(state_tmp)\n",
    "    \n",
    "    x = np.squeeze(np.stack(x_i_list,-1))\n",
    "#     print('done spec')\n",
    "    return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6ea2a593",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import tensorflow as tf\n",
    "def vorbis_window(FRAME_SIZE, transpose=True):\n",
    "    FRAME_SIZE = FRAME_SIZE//2\n",
    "    win = np.zeros((FRAME_SIZE,))\n",
    "    for i in range(FRAME_SIZE):\n",
    "        win[i] = np.sin(.5*np.pi*np.sin(.5*np.pi*(i+.5)/FRAME_SIZE) * np.sin(.5*np.pi*(i+.5)/FRAME_SIZE))\n",
    "\n",
    "    win = np.concatenate((win,np.flip(win)),0)\n",
    "    if transpose: win = win.T\n",
    "    return win\n",
    "\n",
    "def analysis_frame(x, nfft=p.fft_size, hop=p.hop_size, normalize=False):\n",
    "    length = len(x)\n",
    "    n_frames = length // hop\n",
    "    out = np.empty((n_frames, p.fft_size//2+1),dtype=complex)\n",
    "    if not length % hop == 0:\n",
    "        x = np.pad(x,(0, nfft - length%hop))\n",
    "    for frame_idx in range(0, n_frames * hop, hop):\n",
    "        frame = x[frame_idx : frame_idx + nfft]\n",
    "        if len(frame)<nfft: frame = np.pad(frame,(0,nfft-len(frame)))\n",
    "        win = vorbis_window(nfft)\n",
    "        frame = frame.reshape(win.shape)\n",
    "        frame_win = np.multiply(frame, win)\n",
    "        x_fft = np.fft.rfft(frame_win, n=p.fft_size) \n",
    "        if normalize: x_fft *= (p.fft_size ** -0.5)\n",
    "        out[frame_idx//hop,:] = x_fft\n",
    "    return out \n",
    "\n",
    "def synthesis_frame(x, nfft=p.fft_size, hop=p.hop_size, windowing=False, normalize=False):\n",
    "    n_frames, _ = x.shape\n",
    "    length = (n_frames+1)*hop\n",
    "    out = np.zeros((length,))\n",
    "\n",
    "    win = vorbis_window(nfft, transpose=False)\n",
    "    if normalize: x /= (p.fft_size ** -0.5)\n",
    "    for frame_idx in range(0, n_frames * hop, hop):\n",
    "        frame = np.fft.irfft(x[frame_idx//hop] , n=p.fft_size)\n",
    "        \n",
    "        if windowing:\n",
    "            frame = frame.reshape(win.shape)\n",
    "            out[frame_idx : frame_idx + nfft] += np.multiply(frame, win)\n",
    "        else:\n",
    "            out[frame_idx : frame_idx + nfft] += frame\n",
    "    return out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bd2e8b6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def as_complex(x):\n",
    "    if x.dtype == np.complex64 or x.dtype == np.complex128:\n",
    "        return x\n",
    "    else:\n",
    "        return np.complex(x[...,-2], x[..., -1])\n",
    "\n",
    "def as_real(x):\n",
    "    if x.dtype == np.complex64 or x.dtype == np.complex128:\n",
    "        return np.concatenate([np.expand_dims(np.real(x),axis=-1), \n",
    "                               np.expand_dims(np.imag(x),axis=-1)],axis=-1)\n",
    "    else: return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df2736a7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5046761f",
   "metadata": {},
   "outputs": [],
   "source": [
    "process_path = '/home/myhsueh/DeepFilterNet/wav/proc/'\n",
    "audiofile = [ \n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample3_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample1_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample2_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample6_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample7_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample9_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_sample11_01.wav',\n",
    "              \n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_usbmicrophone_APPND34J4EDS3_typing_near_fileid_5.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_speaker_A33BAVCUPSMTWJ_Typing_near_fileid_11.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_openspeaker_ASEW6NZHLI41K_typing_far_fileid_9.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_openspeaker_ASEW6NZHLI41K_openingchipspacket_near_fileid_1.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_openspeaker_A338ZXK723N9UH_dogbarking_near_fileid_si2192.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_openspeaker_A338ZXK723N9UH_babycrying_far_fileid_si1687.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_openspeaker_A338ZXK723N9UH_ArConditioner_near_fileid_si2313.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_english_laptopmic_A9AP3ED0K8LS8_heavybreathing_near_fileid_6.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/DNS_testset/ms_realrec_emotional_Desktopstandmic_AHLK9SWDJHBBZ_clatternoise_near_crying_fileid_8.wav',\n",
    "    \n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/conference_01.wav',\n",
    "              '/home/myhsueh/DeepFilterNet/wav/orig/02-V4K-220511_record.wav',\n",
    "#               '/home/myhsueh/DeepFilterNet/wav/orig/enc_01.wav',\n",
    "            ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f303d532",
   "metadata": {},
   "outputs": [],
   "source": [
    "ERBB = ERBBand(N=p.nb_erb, high_lim=p.sr//2, NFFT=p.fft_size)\n",
    "ERB_Matrix = ERB_pro_matrix(ERBB, NFFT=p.fft_size, mode=0)\n",
    "iERB_Matrix = ERB_pro_matrix(ERBB, NFFT=p.fft_size, mode=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0e24060d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from tqdm import tqdm\n",
    "buffer_frame = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec451f1b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "349161e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def squeeze_fuc(x):\n",
    "    if len(x.shape)==3: \n",
    "        if x.shape[1] == 1: x=np.squeeze(x,1)\n",
    "        else: x=np.squeeze(x,2)\n",
    "    else:\n",
    "        pass\n",
    "    return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "38062fc9",
   "metadata": {},
   "outputs": [],
   "source": [
    "def inference_func_interpreter(interpreter, erb, spec, state0, state10, state11, state20, state21):\n",
    "\n",
    "    ### state ### \n",
    "    state0_input_data = np.array(state0, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[6]['index'], state0_input_data)\n",
    "    state10_input_data = np.array(state10, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[2]['index'], state10_input_data)\n",
    "    state11_input_data = np.array(state11, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[1]['index'], state11_input_data)\n",
    "    state20_input_data = np.array(state20, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[4]['index'], state20_input_data)\n",
    "    state21_input_data = np.array(state21, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[3]['index'], state21_input_data)\n",
    "    ### other\n",
    "    erb_input_data = np.array(erb, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[5]['index'], erb_input_data)\n",
    "    spec_input_data = np.array(spec, dtype=np.float32)\n",
    "    interpreter.set_tensor(interpreter.get_input_details()[0]['index'], spec_input_data)\n",
    "\n",
    "    interpreter.invoke()\n",
    "    \n",
    "    ### output\n",
    "#     mask = interpreter.get_tensor(interpreter.get_output_details()[7]['index'])\n",
    "#     coeff = interpreter.get_tensor(interpreter.get_output_details()[3]['index'])\n",
    "#     alpha = interpreter.get_tensor(interpreter.get_output_details()[6]['index'])\n",
    "    \n",
    "#     state0_output_data = interpreter.get_tensor(interpreter.get_output_details()[2]['index'])\n",
    "#     state10_output_data = interpreter.get_tensor(interpreter.get_output_details()[5]['index'])\n",
    "#     state11_output_data = interpreter.get_tensor(interpreter.get_output_details()[0]['index'])\n",
    "#     state20_output_data = interpreter.get_tensor(interpreter.get_output_details()[1]['index'])\n",
    "#     state21_output_data = interpreter.get_tensor(interpreter.get_output_details()[4]['index'])\n",
    "    mask = interpreter.get_tensor(interpreter.get_output_details()[7]['index'])\n",
    "    coeff = interpreter.get_tensor(interpreter.get_output_details()[5]['index'])\n",
    "    alpha = interpreter.get_tensor(interpreter.get_output_details()[6]['index'])\n",
    "    \n",
    "    state0_output_data = interpreter.get_tensor(interpreter.get_output_details()[4]['index'])\n",
    "    state10_output_data = interpreter.get_tensor(interpreter.get_output_details()[0]['index'])\n",
    "    state11_output_data = interpreter.get_tensor(interpreter.get_output_details()[3]['index'])\n",
    "    state20_output_data = interpreter.get_tensor(interpreter.get_output_details()[1]['index'])\n",
    "    state21_output_data = interpreter.get_tensor(interpreter.get_output_details()[2]['index'])\n",
    "    \n",
    "    \n",
    "    return mask, alpha, coeff, state0_output_data, state10_output_data, \\\n",
    "            state11_output_data, state20_output_data, state21_output_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6c6bfe86",
   "metadata": {},
   "outputs": [],
   "source": [
    "def inference_func(erb, spec, state0, state10, state11, state20, state21, \\\n",
    "                   interpreter):\n",
    "    mask, alpha, coeff, state0, state10, state11, state20, state21 \\\n",
    "    = inference_func_interpreter(interpreter, erb, spec, state0, state10, state11, state20, state21)\n",
    "\n",
    "    return mask, alpha, coeff, state0, state10, state11, state20, state21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "53f0db58",
   "metadata": {},
   "outputs": [],
   "source": [
    "def process(audiofile, interpreter, \n",
    "            process_path='/home/myhsueh/DeepFilterNet/wav/proc/dfn2_lite/'):\n",
    "    y, sr = librosa.load(audiofile, sr=None)\n",
    "    \n",
    "    new_filename = os.path.basename(audiofile)\n",
    "    new_filename = new_filename.replace('.wav','_lite_dfn'+str(buffer_frame)+'.wav')\n",
    "\n",
    "    Y = analysis_frame(y, normalize=True)\n",
    "    \n",
    "    state0, state10, state11, state20, state21 = np.zeros((1,256), dtype=np.float32), \\\n",
    "                                                 np.zeros((1,256), dtype=np.float32), \\\n",
    "                                                 np.zeros((1,256), dtype=np.float32), \\\n",
    "                                                 np.zeros((1,256), dtype=np.float32), \\\n",
    "                                                 np.zeros((1,256), dtype=np.float32)\n",
    "    progress = tqdm(total=Y.shape[0])\n",
    "    \n",
    "    Y_erb = (np.real(Y)**2 + np.imag(Y)**2) @ ERB_Matrix\n",
    "    Y_erb_norm = erb_norm(np.sqrt(Y_erb))\n",
    "    Y_spec_norm = as_real(unit_norm(Y[:,:p.nb_df]))\n",
    "                            \n",
    "    buffer = np.zeros((buffer_frame,p.fft_size//2+1), dtype=complex)\n",
    "    buffer_erb = np.zeros((buffer_frame+2,32,1), dtype=np.float32)\n",
    "    buffer_spec = np.zeros((buffer_frame+2,96,2), dtype=np.float32)\n",
    "    Z = np.zeros_like(Y, dtype=complex)\n",
    "    mask_recoed = np.zeros_like(Y, dtype=float)\n",
    "    \n",
    "    for i in range(Y.shape[0]-1):\n",
    "        buffer = np.roll(buffer, -1, axis=0)\n",
    "        buffer[-1] = Y[i]\n",
    "        if buffer_frame==1:\n",
    "            buffer[0] = Y[i]\n",
    "        \n",
    "        buffer_erb = np.roll(buffer_erb, -1, axis=0)\n",
    "        buffer_erb[-1] = Y_erb_norm[i]\n",
    "        \n",
    "        buffer_spec = np.roll(buffer_spec, -1, axis=0)\n",
    "        buffer_spec[-1] = Y_spec_norm[i]\n",
    "\n",
    "        buffer_feature = [np.expand_dims(buffer_erb,0), np.expand_dims(buffer_spec,0)]\n",
    "        \n",
    "        state0 = squeeze_fuc(state0)\n",
    "        state10 = squeeze_fuc(state10)\n",
    "        state11 = squeeze_fuc(state11)\n",
    "        state20 = squeeze_fuc(state20)\n",
    "        state21 = squeeze_fuc(state21)\n",
    "        \n",
    "        mask_out, df_alpha, df_coeff, \\\n",
    "        state0, state10, state11, state20, state21 = inference_func(buffer_feature[0], \n",
    "                                                                    buffer_feature[1], \n",
    "                                                                    state0, \n",
    "                                                                    state10, state11, \n",
    "                                                                    state20, state21,\n",
    "                                                                    interpreter)\n",
    "\n",
    "        buffer_real = np.concatenate((np.expand_dims(np.real(buffer),-1),np.expand_dims(np.imag(buffer),-1)),axis=-1)\n",
    "        buffer_spec_proc, mask = mask_operations(buffer_real, mask_out, training=True, return_mask=True) # mask gain\n",
    "\n",
    "        enhanced = df_operations(buffer_spec_proc, df_coeff, df_alpha) # deep filter\n",
    "    \n",
    "        enhanced = np.squeeze(enhanced)\n",
    "        enhanced_complex = np.squeeze(enhanced[..., 0]+1j*enhanced[..., 1])\n",
    "        \n",
    "        if buffer_frame==1:\n",
    "            Z[i,:] = enhanced_complex\n",
    "        else:\n",
    "            Z[i,:] = enhanced_complex[-1]\n",
    "        mask_recoed[i,:] = np.reshape(mask,(481,)).astype(np.float32)\n",
    "            \n",
    "        progress.update(1)\n",
    "    progress.close()     \n",
    "    \n",
    "    z = synthesis_frame(Z, windowing=True, normalize=True)\n",
    "\n",
    "    if not os.path.exists(process_path): os.makedirs(process_path)\n",
    "    y = np.reshape(y,(y.shape[0],1))\n",
    "    z = np.reshape(z,(z.shape[0],1))\n",
    "    \n",
    "    if y.shape[0]>z.shape[0]:\n",
    "        z = np.concatenate((np.zeros((y.shape[0]-z.shape[0],1)),z),axis=0)\n",
    "    if y.shape[0]<z.shape[0]:\n",
    "        y = np.concatenate((np.zeros((z.shape[0]-y.shape[0],1)),y),axis=0)\n",
    "        \n",
    "    write(os.path.join(process_path,new_filename), np.concatenate((y,z),axis=1), 48000)\n",
    "    \n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.plot(y, color = 'b')\n",
    "    plt.plot(z, color = 'r')\n",
    "    plt.legend(['unproc','proc'])\n",
    "    plt.show()\n",
    "    \n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.imshow(np.fliplr(mask_recoed).T, vmin=0, vmax=1)\n",
    "    plt.show()\n",
    "    \n",
    "    plt.figure(figsize=(10,5))\n",
    "    plt.imshow(20*np.log10(np.abs(np.fliplr(Z).T)+1e-12))\n",
    "    plt.show()\n",
    "    \n",
    "    return Y.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "35a38c0d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'serving_default_spec_input:0', 'index': 909, 'shape': array([ 1,  3, 96,  2], dtype=int32), 'shape_signature': array([ 1,  3, 96,  2], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_state11:0', 'index': 910, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_state10:0', 'index': 911, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_state21:0', 'index': 912, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_state20:0', 'index': 913, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_ERB_input:0', 'index': 914, 'shape': array([ 1,  3, 32,  1], dtype=int32), 'shape_signature': array([ 1,  3, 32,  1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'serving_default_state0:0', 'index': 915, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "=============================================================\n",
      "{'name': 'StatefulPartitionedCall:1', 'index': 916, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:3', 'index': 917, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:4', 'index': 918, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:2', 'index': 919, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:0', 'index': 920, 'shape': array([  1, 256], dtype=int32), 'shape_signature': array([  1, 256], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:6', 'index': 921, 'shape': array([ 1,  1,  5, 96,  2], dtype=int32), 'shape_signature': array([ 1,  1,  5, 96,  2], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:5', 'index': 922, 'shape': array([1, 1, 1], dtype=int32), 'shape_signature': array([1, 1, 1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n",
      "{'name': 'StatefulPartitionedCall:7', 'index': 923, 'shape': array([ 1,  1, 32], dtype=int32), 'shape_signature': array([ 1,  1, 32], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}\n"
     ]
    }
   ],
   "source": [
    "interpreter = tf.lite.Interpreter('/home/myhsueh/DeepFilterNet/Keras_DeepFilterNet2/quantized_INT8_wholemodel.tflite')\n",
    "for information in interpreter.get_input_details():\n",
    "    print(information)\n",
    "print('=============================================================')\n",
    "for information in interpreter.get_output_details():\n",
    "    print(information)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3dd67296",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1471/1472 [00:11<00:00, 133.55it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 38812 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 173464 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 160240 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009424023654149927\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1207/1208 [00:08<00:00, 147.48it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 40696 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 133996 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 207492 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.008327567024736216\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 999/1000 [00:06<00:00, 155.65it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 38624 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 150984 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 248200 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00814018702507019\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1161/1162 [00:07<00:00, 153.21it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 41484 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 199904 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 216508 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.008444828749113361\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1623/1624 [00:12<00:00, 131.03it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 44604 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 151972 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 143356 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009388829980577742\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 999/1000 [00:06<00:00, 161.70it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 34304 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 208524 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 251732 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.007996217250823974\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 999/1000 [00:06<00:00, 157.32it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 36520 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 167640 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 236408 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.008413425922393799\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1686/1687 [00:13<00:00, 128.22it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 40300 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 158204 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 160388 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009406208638686998\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1367/1368 [00:09<00:00, 136.81it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 39552 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 140480 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 209196 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009804768171923899\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1698/1699 [00:13<00:00, 127.44it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45580 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 110756 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 157956 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009473591849970917\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1243/1244 [00:09<00:00, 135.18it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 43276 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 117624 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 215388 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009097877039403394\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1181/1182 [00:08<00:00, 145.42it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28660 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 75524 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 222128 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.008493874883893783\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1274/1275 [00:09<00:00, 140.83it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 42532 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 171612 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 220484 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.00922659855262906\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1294/1295 [00:09<00:00, 139.39it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 36200 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 74384 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 200416 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.011006449916648129\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1366/1367 [00:10<00:00, 133.96it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32288 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 125276 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 185420 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009200277691264178\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 1566/1567 [00:12<00:00, 127.02it/s]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 37356 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 109180 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 166732 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.009586056403164355\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 3412/3413 [00:40<00:00, 83.35it/s] \n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 33052 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 67560 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 62588 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.013894355230725408\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|█████████▉| 14202/14203 [08:48<00:00, 26.88it/s]  \n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 40372 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23388 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24004 characters]\n",
      "text/plain": [
       "<Figure size 720x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.039008527408726894\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "for file in audiofile:\n",
    "    interpreter = tf.lite.Interpreter('/home/myhsueh/DeepFilterNet/Keras_DeepFilterNet2/quantized_INT8_wholemodel.tflite')\n",
    "\n",
    "    interpreter.allocate_tensors()\n",
    "    \n",
    "    start = time.time()\n",
    "    num_frame=process(file,interpreter)\n",
    "    end = time.time()\n",
    "    \n",
    "    print((end-start)/num_frame)\n",
    "    \n",
    "    interpreter.reset_all_variables()\n",
    "    \n",
    "    del interpreter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "359a8244",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
