Giter Club home page Giter Club logo

dcam's Introduction

dCAM

Dimension-wise Class Activation Map for Explaining Multivariate Time Series Classification

GitHub GitHub issues

Abstract

Data series classification is an important and challenging problem in data science. Explaining the classification decisions by finding the discriminant parts of the input that led the algorithm to some decision is a real need in many applications. Convolutional neural networks perform well for the data series classification task; though,the explanations provided by this type of algorithms are poor for the specific case of multivariate data series. Solving this important limitation is a significant challenge. We propose a novel method that addresses the above challenge by highlighting both the temporal and dimensional discriminant information. Our contribution is two-fold: we first describe a new convolutional architecture that enables the comparison of dimensions; then, we propose a novel method that returns dCAM, a Dimension-wise ClassActivation Map specifically designed for multivariate time series.

drawing

This repository is dedicated to our paper titled "dCAM : Dimension-wise Class Activation Map for Explaining Multivariate Time Series Classification" published in the Proceedings of the 2022 International Conference on Management of Data also available on here.

dCAM in Practice:

Here are interesting papers that use dCAM.

Data

The data used in this project comes from two sources:

  • The UCR/UEA archive. Informations are provided in the data folder in order to download our datasets.

Code

The code is divided as follows:

  • The src/ folder that contains:

    • CNN_models.py:

      • CNN architecture (class ConvNet)
      • dCNN/cCNN architecture (class ConvNet2D)
      • ResNet architecture (class ResNet)
      • dResNet/cResNet architecture (class dResNet)
      • Inception Time architecture (class inceptiontime)
      • dInception Time/cInception Time architecture (class dinceptiontime)
      • CNN-MTEX architecture (class ConvNetMTEX)
    • RNN_models.py:

      • LSTM architecture (class LSTMClassifier)
      • RNN architecture (class RNNClassifier)
      • GRU architecture (class GRUClassifier)
    • the explanation/ folder:

      • CAM code (class CAM)
      • cCAM code (class cCAM)
      • dCAM code (class DCAM)
      • grad-CAM code used for CNN-MTEX (class GradCAM)
  • The examples/ folder that contains:

  • The experiments/ folder that contains:

    • classification/: scripts in order to reproduce our classification results.
    • explanation/: scripts in order to reproduce our explanation results.
    • execution_time/: scripts in order to reproduce our execution_time results.
  • Results_overview.ipynb: Notebook containing all the informations and the procedures to run the experiments/ scripts and generate the figures in our paper.

Prerequisites

First, to download the datasets (unzip and move the content in the corresponding folder), please run the following commands:

  • Go to the following folder:
cd data/UCR_UEA
  • Download and unzip the following archive:
https://helios2.mi.parisdescartes.fr/~themisp/dCAM/data/UCR_UEA_datasets.zip
  • Then, go to the following folder:
cd data/synthetic
  • Download and unzip the following archive:
https://helios2.mi.parisdescartes.fr/~themisp/dCAM/data/Synthetic_datasets.zip

All python packages needed are listed in requirements.txt file and can be installed simply using the pip command:

pip install -r requirements_version.txt

If the version are not compatible in your environement, please run the following command:

pip install -r requirements.txt

Jupyter notebook should be installed. To do so, please run the following command:

pip install notebook

Overall, the required python packages are listed as follows:

Reference

If you re-use this work, please cite:

@inproceedings{DBLP:conf/sigmod/BoniolMRP22,
  author    = {Paul Boniol and
               Mohammed Meftah and
               Emmanuel Remy and
               Themis Palpanas},
  editor    = {Zachary Ives and
               Angela Bonifati and
               Amr El Abbadi},
  title     = {dCAM: Dimension-wise Class Activation Map for Explaining Multivariate
               Data Series Classification},
  booktitle = {{SIGMOD} '22: International Conference on Management of Data, Philadelphia,
               PA, USA, June 12 - 17, 2022},
  pages     = {1175--1189},
  publisher = {{ACM}},
  year      = {2022},
  url       = {https://doi.org/10.1145/3514221.3526183},
  doi       = {10.1145/3514221.3526183},
  timestamp = {Tue, 14 Jun 2022 18:31:24 +0200},
  biburl    = {https://dblp.org/rec/conf/sigmod/BoniolMRP22.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}

dcam's People

Contributors

boniolp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bae-sohee

dcam's Issues

Unable to run dInceptionModel or dResNetBaseline

Running dInception or dResNetBaseline leaves me with an error RuntimeError: Expected 2D (unbatched) or 3D (batched) input to conv1d, but got input of size: [<batch size>, <nr of dimensions>, <nr of dimensions>, <time series length>]. I tried this with the FingerMovements dataset.

Here is a minimally reproducible example following the flow of script_exp.py:

from CNN_models import *
from DCAM import *
from sklearn.model_selection import train_test_split

with open("FingerMovements.pickle",'rb') as f:
    X,y = pickle.load(f)
    
# Convert the UCR-UEA format into a list of list
def generate_list_instance(x):
    res = []
    for i in range(len(x)):
        res.append(list(x[i]))
    return np.array(res)

dict_label = {}
count = 0
for val in set(y.values):
    dict_label[val] = count
    count += 1

all_class_all = []
all_label = []
for i in range(len(X)):
    all_class_all.append(generate_list_instance(X.values[i]))
    all_label.append(dict_label[y.values[i]])

original_length = len(all_class_all[0][0])
num_classes = len(set(y.values)) 
original_dim = len(all_class_all[0])
nb_instance = len(all_class_all) 

all_class, all_class_test, label, label_test = train_test_split(all_class_all, all_label,stratify=all_label, test_size=1-0.8,random_state=11081994)

# Generate C-wised input for d-based models (i.e., dCNN, dResNet, and dInceptionTime)
def gen_cube(instance):
    result = []
    for i in range(len(instance)):
        result.append([instance[(i+j)%len(instance)] for j in range(len(instance))])
    return result 

x = np.array([gen_cube(acl) for acl in all_class])
dataset_mat = TSDataset(x,label)
dataloader_cl1 = data.DataLoader(dataset_mat, batch_size=32, shuffle=True)

x = np.array([gen_cube(acl) for acl in all_class_test])
dataset_mat_test = TSDataset(x,label_test)
dataloader_cl1_test = data.DataLoader(dataset_mat_test, batch_size=1, shuffle=True)

# This is dInceptionTime
modelarch = dInceptionModel(num_blocks=3, in_channels=original_dim, out_channels=64,
                           bottleneck_channels=64, kernel_sizes=[10,20,40],
                           use_residuals=True, num_pred_classes=num_classes).to('cuda')

# dResNet gives the same error
# modelarch = dResNetBaseline(original_dim,mid_channels=128,num_pred_classes=num_classes).to(device)

model = ModelCNN(modelarch,'cuda')

model.train(num_epochs=70,dataloader_cl1=dataloader_cl1,dataloader_cl1_test=dataloader_cl1_test)

When I swap the modelarch to modelarch = ConvNet2D(original_length,original_dim,original_dim,num_classes).to('cuda'), as in Synthetic_experiment_DCAM.ipynb, training works fine.

ablation/occlusion vs dCAM

Hi, thank you for your paper! I read your paper, and I was wondering if you had any thoughts as to why dCAM was not compared with a gradCAM channel ablation/occlusion approach (setting one or a combination of input channels to zero)? Channel ablation seems like such a simple idea to extend gradCAM for multivariate time-series. So I'm wondering if there is a reason that dCAM results were not compared with a gradCAM feature ablation approach? A recent paper tried ablation for gradCAM, but they did not compare with dCAM.

Thanks for your feedback!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.