This project implements a complete pipeline for rolling element ball bearing fault detection using vibration signals stored in .mat files and a 1D CNN in PyTorch.
utils.py: Scans folders, loads.matfiles, extracts vibration signals (Data1_AI_1_Xaxis), segments signals into overlapping windows, and builds NumPy datasets.dataset.py: Defines the PyTorchDatasetand helpers to split, scale (StandardScaler), and buildDataLoaders.model.py: Implements the 1D CNN architecture for fault classification.train.py: Entry point for training, evaluation, and plotting.requirements.txt: Python dependencies.
- The workspace (or a given
--data_dir) must contain.matfiles. - Each
.matfile should contain a key namedData1_AI_1_Xaxiswith a long 1D vibration signal. - File names encode the fault type:
Normal→ label0BF(Ball Fault) → label1IF(Inner Race Fault) → label2OF(Outer Race Fault) → label3
Matching is case-insensitive and based on substrings in the file name.
Create and activate a virtual environment, then install dependencies:
pip install -r requirements.txtFrom the project root:
python train.py --data_dir path/to/your/datasetArguments:
--data_dir(default.): Root directory to scan recursively for.matfiles.--epochs(default20): Number of training epochs.--batch_size(default64): Batch size.--lr(default1e-3): Learning rate for Adam optimizer.
Running train.py will:
- Print training loss per epoch.
- Print final test accuracy.
- Save a training loss plot as
loss_curve.png. - Save a confusion matrix plot as
confusion_matrix.png.