Skip to content

fix(training): raise when a class has no samples instead of training on NaN centroids - #21

Open
AnKiT-GaRG2 wants to merge 1 commit into
ML4SCI:mainfrom
AnKiT-GaRG2:fix-centroid-empty-class
Open

AnKiT-GaRG2 wants to merge 1 commit into
ML4SCI:mainfrom
AnKiT-GaRG2:fix-centroid-empty-class

Conversation

@AnKiT-GaRG2

Copy link
Copy Markdown

Problem

load_dataset skips a class that has no <class>_*.npy files without complaint. CentroidTrainBackend.train then takes xn[y == c].mean(axis=0) over an empty slice, which gives a NaN centroid (only a RuntimeWarning: Mean of empty slice). argmin treats NaN as the minimum, so every sample is assigned to the missing class and training "succeeds" with train_accuracy: 0.0 and a centroids.npz full of NaNs. A wrong root, a typo in a class name, or a simulation run that produced no samples for one class all end up this way.

Reproduction (two classes on disk, three in class_names):

RuntimeWarning: Mean of empty slice
RESULT {'train_accuracy': 0.0}

Fix

Count the samples per class before computing centroids and raise a RuntimeError naming the classes without samples, before anything is written to output_root. Inference (CentroidInferBackend) is unchanged, since evaluating a subset of classes is still meaningful there.

Tests

Added test_centroid_train_rejects_class_without_samples to tests/test_downstream_agents.py; it fails on main and passes with this change. The rest of that file still passes (8 passed).

…on NaN centroids

CentroidTrainBackend computed the mean of an empty slice for a class without .npy files, giving a NaN centroid. argmin treats NaN as the minimum, so training reported train_accuracy 0.0 as if it had succeeded, with only a NumPy warning. Check the per-class sample counts first and raise a RuntimeError naming the missing classes.

Signed-off-by: Ankit Garg <146389256+AnKiT-GaRG2@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant