Repository navigation
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
Open
AnKiT-GaRG2 wants to merge 1 commit into
AnKiT-GaRG2 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
load_datasetskips a class that has no<class>_*.npyfiles without complaint.CentroidTrainBackend.trainthen takesxn[y == c].mean(axis=0)over an empty slice, which gives a NaN centroid (only aRuntimeWarning: Mean of empty slice).argmintreats NaN as the minimum, so every sample is assigned to the missing class and training "succeeds" withtrain_accuracy: 0.0and acentroids.npzfull of NaNs. A wrongroot, 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):Fix
Count the samples per class before computing centroids and raise a
RuntimeErrornaming the classes without samples, before anything is written tooutput_root. Inference (CentroidInferBackend) is unchanged, since evaluating a subset of classes is still meaningful there.Tests
Added
test_centroid_train_rejects_class_without_samplestotests/test_downstream_agents.py; it fails onmainand passes with this change. The rest of that file still passes (8 passed).