# xiaohan-chen/bear_fault_diagnosis architecture

> Architecture diagram of the GitHub repository xiaohan-chen/bear_fault_diagnosis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xiaohan-chen/bear_fault_diagnosis
- Repository: https://github.com/xiaohan-chen/bear_fault_diagnosis
- Video tour (about a minute): https://gitdiagram.com/xiaohan-chen/bear_fault_diagnosis/video

## Overview

This repository provides a bearing-fault diagnosis baseline: vibration data from CWRU `.mat` files is segmented, prepared for classification, passed through a multi-scale CNN–LSTM, and used to train and evaluate a model whose weights are saved. The current PyTorch implementation is the principal workflow; the README identifies the notebook as an unmaintained Keras version. `generate_data.py` is a separate legacy data-loading utility. Some orchestration details fall in omitted excerpts, so those links are marked unverified rather than inferred as direct calls.

Main entry points: [`cnn_lstm_model.py`](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py) (Training entry point), [`generate_data.py`](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/generate_data.py) (Legacy MAT loader), [`cnn_lstm_model.ipynb`](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.ipynb) (Keras notebook baseline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_loader["MAT data loader<br/>[cnn_lstm_model.py]"]
  node_prep["Label and sample preparation<br/>[cnn_lstm_model.py]"]
end

subgraph group_diagnosis["Diagnosis model"]
  node_entry["Training entry point<br/>[cnn_lstm_model.py]"]
  node_model["Multi-scale CNN–LSTM<br/>[cnn_lstm_model.py]"]
  node_trainer["Training and evaluation<br/>[cnn_lstm_model.py]"]
  node_weights["Saved model weights"]
end

subgraph group_legacy["Legacy implementation"]
  node_legacyloader["Legacy MAT loader<br/>[generate_data.py]"]
  node_keras["Keras notebook baseline"]
end

node_user(("Researcher"))
node_cwru[("CWRU MAT files")]

node_user -->|"runs"| node_entry
node_cwru -->|"provides MAT files"| node_loader
node_entry -.->|"loads data"| node_loader
node_loader -.->|"returns samples and labels"| node_prep
node_entry -->|"prepares training data"| node_prep
node_entry -.->|"trains and evaluates"| node_trainer
node_trainer -->|"calls forward"| node_model
node_entry -->|"saves weights"| node_weights
node_cwru -->|"reads MAT files"| node_legacyloader
node_user -->|"can use"| node_keras

click node_entry "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py"
click node_loader "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py"
click node_prep "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py"
click node_model "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py"
click node_trainer "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py"
click node_legacyloader "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/generate_data.py"
click node_keras "https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_prep toneBlue
class node_entry,node_model,node_trainer,node_weights,node_cwru toneAmber
class node_legacyloader,node_keras toneMint
class node_user toneIndigo
```

## Components

### Data preparation

- [MAT data loader](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py): `cnn_lstm_model.py`
- [Label and sample preparation](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py): `cnn_lstm_model.py`

### Diagnosis model

- [Training entry point](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py): `cnn_lstm_model.py`
- [Multi-scale CNN–LSTM](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py): `cnn_lstm_model.py`
- [Training and evaluation](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.py): `cnn_lstm_model.py`
- **Saved model weights**

### Legacy implementation

- [Legacy MAT loader](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/generate_data.py): `generate_data.py`
- [Keras notebook baseline](https://github.com/xiaohan-chen/bear_fault_diagnosis/blob/master/cnn_lstm_model.ipynb): `cnn_lstm_model.ipynb`

### Other components

- **Researcher**
- **CWRU MAT files**

## Connections

- Researcher → Training entry point: runs (evidence: `cnn_lstm_model.py`)
- CWRU MAT files → MAT data loader: provides MAT files (evidence: `README.md`)
- Training entry point → MAT data loader: loads data (evidence: `cnn_lstm_model.py`)
- MAT data loader → Label and sample preparation: returns samples and labels (evidence: `cnn_lstm_model.py`)
- Training entry point → Label and sample preparation: prepares training data (evidence: `cnn_lstm_model.py`)
- Training entry point → Training and evaluation: trains and evaluates (evidence: `cnn_lstm_model.py`)
- Training and evaluation → Multi-scale CNN–LSTM: calls forward (evidence: `cnn_lstm_model.py`)
- Training entry point → Saved model weights: saves weights (evidence: `cnn_lstm_model.py`)
- CWRU MAT files → Legacy MAT loader: reads MAT files (evidence: `generate_data.py`)
- Researcher → Keras notebook baseline: can use (evidence: `README.md`)
