Skip to main content

ClassificationEngine

ClassificationEngine(spec, *, device=None, num_workers=0, strict_data=True)

Fit, score and answer, for one label per image.

Methods

Name Description
answers One row per image: its key, its answer, and how sure the model was.
balance How many images each class has in a split, and how lopsided that is.
best_model The model with the highest score on key.
dataset One split’s samples, as a dataset for one model.
evaluate One row per model: the loss and every metric it was asked for.
fit Every model in the run, in the order the specification names them.
loader Ordered and complete unless the caller says otherwise, which only fit does.
predict Probabilities, (images, classes), in the split’s own order.
predict_labels The class names, because a name is what a reader wanted.
write_history One CSV per model, in output_dir unless told otherwise.

answers

ClassificationEngine.answers(model_name=None, split='test')

One row per image: its key, its answer, and how sure the model was.

The key is what makes this joinable to anything else the caller holds, and it is the thing rplatypus#223 was filed about on the segmentation side - a prediction returned as a bare sequence has to be paired by position.

A set of labels is a different row and not the same row with a longer string. labels holds the findings the image actually carries and predicted the ones the model says it does, both as lists in classes order, and there is no probability column at all: that column is the chosen class’s own number, and with independent questions nothing was chosen - the p_<class> columns are each class’s answer and they are the whole of it. Inventing a single figure here would mean picking a finding to call the answer, which is the thing predict_labels refuses to do one layer down.

balance

ClassificationEngine.balance(split='train')

How many images each class has in a split, and how lopsided that is.

Public, and on the engine rather than only on the dataset, because it is the number every decision about this task’s metrics turned on - and the person who most needs it is the one who has just written a specification and not yet run anything.

An unlabelled split is refused rather than counted, which became reachable with pyplatypus#320: a test set of images alone counted this way reports every class at zero, never lists all of them, and labels_are_a_set reads False whatever the specification says - three readings that look like findings about a dataset and are findings about there being no labels. §4 of the workbench’s notes: a zero in a table is read as a result.

The sentence is this method’s own rather than _needs_labels’s, because that one says there is nothing to score against and is about asking a model for a number. This is a question about the data with no model in it, and the reading somebody needs here is the zero they would otherwise have believed.

best_model

ClassificationEngine.best_model(key='auc', split='validation')

The model with the highest score on key.

auc rather than accuracy as the default, for the reason it is the default metric: measured at a prevalence of 3%, accuracy spans 0.0100 across models whose AUC spans 0.4631 and is not even monotone in their discrimination, so choosing on it is choosing on noise with a model that has no signal in the lead.

dataset

ClassificationEngine.dataset(model_name, split, *, augment=None)

One split’s samples, as a dataset for one model.

augment defaults to augmenting the training split and nothing else, which is the rule every other engine here follows: a validation score measured on transformed images is a score for a dataset nobody has.

evaluate

ClassificationEngine.evaluate(split='validation')

One row per model: the loss and every metric it was asked for.

A row rather than a number, and no _worst column, because a case here is one image - a split’s worst case would be 0 for any model that gets one image wrong, which is the shape of a number that carries no information.

The metric columns carry bare names and the split column says which split, which is the segmentation table’s shape rather than a new one: a row reading split: test beside a column called val_loss is a row that has to be explained. The trainer prefixes everything val_ because an epoch has two passes to tell apart; a table has a column for that instead.

loss_function sits beside loss for the reason it does there: a loss column is only comparable between models trained on the same one. architecture is read plainly rather than through .value - for this task it is a string, plain_cnn or the backbone’s name, and there is no enum to take a value off.

best_epoch is the epoch these very scores came from, which is what a reader of a row of scores takes it for, and it is None when they came from no single epoch - an average, or a run that selected nothing and therefore ended on its last epoch, which epochs_run already names. It was the lowest val_loss whatever the run was watching until pyplatypus#398, so a run monitored on anything else named one epoch and scored another. The epoch that was best by some other quantity is History.best(key), which is now the only way to ask that question.

fit

ClassificationEngine.fit(verbose=False)

Every model in the run, in the order the specification names them.

loader

ClassificationEngine.loader(
    model_name,
    split,
    *,
    augment=None,
    shuffle=False,
    drop_last=False,
)

Ordered and complete unless the caller says otherwise, which only fit does.

Both flags used to be derived from split == "train" here, and that was pyplatypus#321. A method that asks what the model said got the loader built for optimising over, so predict came back in the shuffled order its own docstring promises the split’s own order, and answers paired each key with another image’s probabilities. Measured: two predict(split="train") calls on one split are a permutation of each other - the same multiset of rows, not one row in place - and at 16 samples with batch_size: 8 nothing is dropped, so no count disagreed and nothing refused.

The three other engines take shuffle from the caller and every asking site passes False; this one derived it. So this is not a new parameter but the shape its siblings already have, which is also what makes the defect legible: one question answered four times, three the same way, and the odd one out is the bug. _has_any_labels was the same shape one release earlier.

The two flags stay separate rather than travelling under one name, and that is measured rather than tidy: drop_last was training and len(base) > batch_size, independent of data.shuffle, so keying it to shuffling would stop dropping the ragged last batch for anybody running shuffle: false - and a last batch of one is a batch-norm with nothing to normalise over, which is the whole reason the flag is here. This task’s batches are images rather than tiles, so a dropped one costs a single example.

The len(base) > batch_size guard stays inside rather than moving to the caller: a split smaller than one batch would otherwise be emptied by the flag fit always passes, and that is a property of the data rather than a decision fit is making.

predict

ClassificationEngine.predict(model_name=None, split='test')

Probabilities, (images, classes), in the split’s own order.

predict_labels

ClassificationEngine.predict_labels(model_name=None, split='test')

The class names, because a name is what a reader wanted.

Read off data.classes, whose order is the class index - so this is the one place where the engine knows the right names and a caller passing their own could be wrong without anything saying so.

A list of names per image when the label is a set, which is the trainer’s own shape and is there for its reason: one name per image would have to pick which of the findings is the one, and the model was not asked that.

write_history

ClassificationEngine.write_history(out_dir=None)

One CSV per model, in output_dir unless told otherwise.