In [1]:
Copied!
import pickle
import numpy as np
import matplotlib.pyplot as plt
import seaborn as snst
from tslearn.datasets import UCR_UEA_datasets
import tensorflow as tf
import pickle
import numpy as np
import matplotlib.pyplot as plt
import seaborn as snst
from tslearn.datasets import UCR_UEA_datasets
import tensorflow as tf
/home/jacqueline/.local/share/virtualenvs/TSInterpret-x4eqnPOt/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm 2023-09-18 12:06:18.348758: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-09-18 12:06:19.269948: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Parameters¶
In [2]:
Copied!
dataset='Coffee'
dataset='Coffee'
Load Data¶
In [3]:
Copied!
train_x,train_y, test_x, test_y=UCR_UEA_datasets().load_dataset(dataset)
train_x,train_y, test_x, test_y=UCR_UEA_datasets().load_dataset(dataset)
Model Training¶
In [4]:
Copied!
import tensorflow as tf
#model = Classifier_CNN(f'./ClassificationModels/models/{dataset}', (train_x.shape[1], train_x.shape[2]), train_y.shape[-1], True)
#y_true = np.argmax(test_y, axis=1)
#model.fit(train_x,train_y,test_x,test_y)
model_to_explain = tf.keras.models.load_model(f'../../ClassificationModels/models/{dataset}/cnn/last_model.hdf5')
import tensorflow as tf
#model = Classifier_CNN(f'./ClassificationModels/models/{dataset}', (train_x.shape[1], train_x.shape[2]), train_y.shape[-1], True)
#y_true = np.argmax(test_y, axis=1)
#model.fit(train_x,train_y,test_x,test_y)
model_to_explain = tf.keras.models.load_model(f'../../ClassificationModels/models/{dataset}/cnn/last_model.hdf5')
2023-09-18 12:06:20.361423: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:995] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero. See more at https://github.com/torvalds/linux/blob/v6.0/Documentation/ABI/testing/sysfs-bus-pci#L344-L355 2023-09-18 12:06:20.362034: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1960] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices...
Explanation Algo¶
In [5]:
Copied!
from TSInterpret.InterpretabilityModels.Saliency.TSR import TSR
int_mod=TSR(model_to_explain, train_x.shape[-2],train_x.shape[-1], method='IG',mode='time')
from TSInterpret.InterpretabilityModels.Saliency.TSR import TSR
int_mod=TSR(model_to_explain, train_x.shape[-2],train_x.shape[-1], method='IG',mode='time')
Mode in TF Saliency time
In [6]:
Copied!
print(np.array([test_x[0,:,:]]).shape)
print(np.array([test_x[0,:,:]]).shape)
(1, 286, 1)
In [7]:
Copied!
item= np.array([test_x[0,:,:]])
label=int(np.argmax(test_y[0]))
item= np.array([test_x[0,:,:]])
label=int(np.argmax(test_y[0]))
In [8]:
Copied!
exp=int_mod.explain(item,labels=label,TSR =True)
exp=int_mod.explain(item,labels=label,TSR =True)
Plot Item¶
In [9]:
Copied!
%matplotlib inline
int_mod.plot(np.array([test_x[0,:,:]]),exp)
%matplotlib inline
int_mod.plot(np.array([test_x[0,:,:]]),exp)
time mode
In [10]:
Copied!
%matplotlib inline
int_mod.plot(np.array([test_x[0,:,:]]),exp, heatmap = True)
%matplotlib inline
int_mod.plot(np.array([test_x[0,:,:]]),exp, heatmap = True)
time mode