Coder Social home page Coder Social logo

2d_cnn_ecg's Introduction

Arrhythmia detection based on ECG Signal by Image using 2D Deep CNN

ECG 데이터를 그래프로 변환하여 2D CNN에 심전도를 구별하는 모델이다. 해당 모델은 위 논문에서 2D CNN 의 모델 구조를 참고하였다. 논문에서 입력되는 데이터와 실제 데이터가 차이가 존재하여 이를 명확히 따라하지는 않는다. 어디까지나 참고 일 뿐.

Data

그래프로 변환한 이미지 데이터가 2GB가 넘어 LFS을 통해서도 업로드가 어렵다. 코드와 원본 데이터를 올려두었으니 cutting_graph.py 파일을 사용하면 파일을 구할 수 있다. 그 과정이 너무 오래걸린다 싶으면 아래 링크를 통해서 다운로드를 받을 수 있다.

Input data의 예시를 하나 보여주면 아래와 같은 이미지가 들어가게 된다. Normal_beat_sliced_image

이미지 크기가 좀 크긴하다만 어차피 모델에 들어가기 이전에 조정을 하고 들어간다. 256 * 256 사이즈로 입력값으로 들어가게 된다. 기존에는 plot title 을 실수로 추가를 해버려서 불필요한 데이터가 들어갔다만 그 부분도 수정하여 이제는 그래프만 저장 되도록 수정하였다. 위 사진은 Normal 비트 예시 일 뿐, 모든 비트가 저리 이쁘진 않다... 사실 노이즈도 있어서 그렇게 이쁘다고는 못하지만 그래도 곱게 봐달라.

Model 구성

2D_CNN_Model_Structure 차이가 있다면 끝단에서 출력하는 나오는 Class의 개수가 다르다. 우리는 5개 (N, S, V, F, Q) 를 갖고 했으나 해당 논문에서는 8개로 분류를 진행하였다. 거의 사실상 CNN과 Maxpool layer를 통과하여 특징을 뽑아내는데 고급지고 똑똑한 야바위라고 해도 되지 않을까 싶다. Grayscale로 들어가게 되니 결과적으로는 모델이 보는건 이미지의 특징이다.

Result

Confusion Matrix

Confusion Matrix Fig.1 Confusion Matrix Fig.2

데이터의 비중에 따라 다른 결과 값으로 예상된다. S, F 클래스가 다른 클래스에 비해 확연히 비중이 적다보니 잘 잡아내지 못하는 것으로 생각된다. Summary Report 는 아래와 같다.

              precision    recall  f1-score   support

       0 = N       0.99      0.99      0.99     20059
       1 = S       0.94      0.86      0.90       610
       2 = V       0.95      0.96      0.95      1553
       3 = F       0.88      0.80      0.84       182
       4 = Q       0.98      0.98      0.98      2491

    accuracy                           0.99     24895
   macro avg       0.95      0.92      0.93     24895
weighted avg       0.99      0.99      0.99     24895

GoogLeNet (Inception)

Inception 을 활용한 GoogLeNet 을 구성하여 2D CNN 모델로 구성하였다. 모델의 Shape 및 크기는 아래와 같이 구성되어 있다. GoogLeNet Shape 꽤나 복잡한데 간단히 GoogLeNet과 Inception을 설명을 하고 가면 Inception은 현재 까지 v3 까지 나온 모델이다. 블록 모델처럼 쓰이는데 Inception을 활용한 모델이 GoogLeNet 이다. GoogLeNet != Inception 이니 헷갈리지 않길 바란다.

Inception은 아래와 같이 구성되어 있다.

Inception

보이는 바와 같이 Convolution Layer와 MaxPooling Layer의 연속이다. 이를 여러번 합치고 합친 모델이 GoogLeNet 인거고. 영화 Inception 처럼 깊이 들어가고 들어가게 되는데 MaxPooling은 Convolution Layer의 연산량을 줄이기 위함이다. 워낙에 너무 연산량이 많아지면 시간이 너무 오래 걸리게 되면서 이를 줄이기 위한 방법이다.

Result

  • Train and Validation Accuracy, Loss

Train and Validation Loss Train and validation accuracy

  • Confusion Matrix

Confusion Matrix as count Confusion Matrix as ratio

             precision    recall  f1-score   support

       0 = N       0.98      1.00      0.99     20059
       1 = S       0.91      0.86      0.89       610
       2 = V       0.97      0.90      0.94      1553
       3 = F       0.70      0.80      0.75       182
       4 = Q       0.99      0.94      0.97      2491

    accuracy                           0.98     24895
   macro avg       0.91      0.90      0.90     24895
weighted avg       0.98      0.98      0.98     24895

Result

해당 결과값은 스펙토그램을 입력으로 한 결과 값이다. 기존에는 Raw 그래프 이미지를 넣었던 모델에 스펙토그램으로 변경하였다. GrayScale이 아닌 RGB 그대로 들어간다.

  • Train and Validation Accuracy, Loss

Train and Validation Loss Train and validation accuracy

  • Confusion Matrix

Confusion Matrix as count Confusion Matrix as ratio

            precision    recall  f1-score   support

       0 = N       0.99      0.99      0.99     20059
       1 = S       0.92      0.89      0.90       610
       2 = V       0.94      0.96      0.95      1553
       3 = F       0.86      0.77      0.81       182
       4 = Q       0.99      0.99      0.99      2491

    accuracy                           0.99     24895
   macro avg       0.94      0.92      0.93     24895
weighted avg       0.99      0.99      0.99     24895

2d_cnn_ecg's People

Contributors

insung3511 avatar imgbotapp avatar restyled-commits avatar

Watchers

 avatar

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.