DTW-CNN battery degradation diagnosis

Original trained models from Li-ion battery degradation modes diagnosis via Convolutional Neural Networks, by N. Costa, L. Sánchez, D. Anseán and M. Dubarry. Journal of Energy Storage 55 (2022), 105558.

This repository contains only the DTW-CNN models for the three battery chemistries from the study. These are supervised diagnosis models, not foundation models or self-supervised encoders.

Checkpoints

Select one chemistry. Each checkpoint takes a 128 × 128 DTW image with one channel.

Chemistry Checkpoint
LFP weights/LFP/model-DTWCNN.h5
NCA weights/NCA/model-DTWCNN.h5
NMC weights/NMC/model-DTWCNN.h5

All three checkpoints retain their original HDF5 bytes.

Input and output

The helper accepts charge voltage curves in volts, with matching normalized-capacity coordinates in percent. Use slow-charge curves consistent with the C/25 data and the study protocol. qnorm is not measured capacity in Ah.

The output columns are lli, lampe and lamne, in that order. The helper returns percentages, so 5.0 means 5%. The saved models themselves predict fractions. There is no qloss output. Predictions are not clipped.

Loading

Use Python 3.12 and the pinned requirements. The validation environment uses Python 3.12.11, TensorFlow 2.21.0 and Keras 3.15.1. The original HDF5 checkpoints load directly, with no weight conversion or retraining. Download this repository, enter its directory, then run the following commands.

python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install datasets==5.1.0

Use the complete-test-group example below to preserve the original DTW scaling. BatteryDiagnosis.from_pretrained downloads the selected checkpoint and reference curves from a Hugging Face model repository. The Python helper must already be installed or available on your import path. This is not a Transformers AutoModel or a hosted inference pipeline.

Preprocessing

battery_diagnosis.py implements the source inference operations.

  1. Interpolate normalized capacity on the chemistry-specific voltage grid with a 0.5 mV step.
  2. Compute capacity increments with np.diff. These features are ΔQ, not ΔQ/ΔV.
  3. Reduce to 127 points with PCHIP interpolation.
  4. Apply the fixed chemistry-specific IC scaling used by the original inference notebook.
  5. Compute the accumulated warping-path matrix against the pristine reference for C0, C1, C2 or C3. Use window 64 and psi=2, mask unfilled cells to zero, then scale the complete group by one maximum.
Chemistry Voltage grid, start inclusive and stop exclusive IC minimum IC maximum
LFP 3.20–3.50 V 0.0031566024955984595 2.736867845392978
NCA 3.20–4.23 V 0 0.2682065162447511
NMC 3.44–4.28 V 0 0.1914037352896408

The helper does not sort, trim, impute or remove NaNs from the source curves. It follows the original np.interp behavior. A nonfinite IC result raises an error before model inference. A finite result does not establish that an arbitrary curve with NaNs is suitable input.

DTW batch scaling and references

The original DTW code normalizes all images in each call by one shared maximum. Predictions can therefore change when the group of curves changes. Preparing one curve at a time does not reproduce preprocessing of a complete test configuration.

For a matched evaluation, prepare all 6,000 curves in one test configuration together. Do not mix configurations or chemistries in the same group. Use configuration="C1", "C2" or "C3" for the corresponding test split. Use "C0" for train records. The C0 reference is the first published pristine train record for each chemistry, with curve_id=0 and zero lli, lampe and lamne. C1–C3 references come from the original V_references.mat files. References for other cell configurations must be established separately and are not supplied here.

import numpy as np
from datasets import load_dataset
from battery_diagnosis import BatteryDiagnosis

test_stream = load_dataset(
    "HNEI-PakaLi-Lab/synthetic-battery-diagnosis",
    "lfp", split="test_c1", streaming=True,
    revision="75a7e1332750058ca3f53f8176c2b2fbd07239cf",
)
test = list(test_stream)
model = BatteryDiagnosis(".", chemistry="lfp")
inputs, scale = model.prepare_inputs(
    np.asarray([record["voltage"] for record in test]),
    np.asarray([record["qnorm"] for record in test]),
    configuration="C1",
)
predictions_percent = model.predict_inputs(inputs, batch_size=32)

Image preparation can require several GB of RAM for 6,000 curves. To prepare chunks with the same scale, first determine the maximum across the complete group, then supply that value as dtw_normalization_scale for every chunk. Changing the neural prediction batch_size after image preparation does not change this normalization group.

The example streams only the requested test split. It does not materialize the much larger train split.

Evaluation scope

These are the original released checkpoints. They have not been retrained on the current Hugging Face dataset split. Use a fresh training run with the current splits for a new train/test benchmark.

Validation uses files downloaded from HNEI-PakaLi-Lab/synthetic-battery-diagnosis at revision 75a7e1332750058ca3f53f8176c2b2fbd07239cf.

  • All 54,000 published test voltage curves, capacity coordinates and four label columns match the original MATLAB test data exactly, including NaN positions. All produce finite 127-point IC inputs.
  • Prediction checks cover 64 records per test chemistry/configuration, or 576 test records in total. A further 64 streamed train records per chemistry, or 192 in total, check C0 preprocessing and inference. Train samples are the first 64 rows, not a random sample or a full-train audit.
  • Each environment reproduces the original preprocessing functions on the sampled DTW inputs. Across Python 3.10/TensorFlow 2.15.1 and Python 3.12/TensorFlow 2.21.0, the maximum IC difference is about 1.01e-13, the float32 DTW images match exactly, and the maximum prediction difference is 1.1444091796875e-5 percentage points. Shared-scale chunk preprocessing also matches.
  • These checks use sampled normalization groups. They do not reproduce the full-test DTW normalization groups or the paper scores. The paper's reported RMSPE uses a fixed 100% denominator, which corresponds to RMSE in percentage points for percentage-valued labels. It is not a sample-wise division by each label.

Keras 3 can emit warnings about the legacy input-shape declaration and the original mask passing into a convolution. The original graph is retained; the validated loader does not remove layers or alter weights.

References

@article{costa2022diagnosis,
  title = {Li-ion battery degradation modes diagnosis via Convolutional Neural Networks},
  author = {Costa, N. and S{\'a}nchez, L. and Anse{\'a}n, D. and Dubarry, M.},
  journal = {Journal of Energy Storage},
  volume = {55},
  pages = {105558},
  year = {2022},
  doi = {10.1016/j.est.2022.105558}
}
Downloads last month
28
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train HNEI-PakaLi-Lab/dtw-cnn-battery-diagnosis