peal.global_utils.get_predictions

peal.global_utils.get_predictions(args)[source]

Predict a whole dataset and write the labels to a csv file.

Runs args.classifier over args.dataset with gradients disabled, accepting the several sample layouts used in PEAL and in the vendored code ((img, lab, file) triples, dicts with x/y/url and (img, y) pairs whose y bundles label, hint, index and filename). Multi-logit outputs are argmaxed, single-logit outputs thresholded at 0. The accuracy against the dataset labels is printed.

Parameters:

args (object) – Needs dataset, classifier, batch_size and label_path; optionally max_samples to stop early and is_image_to_class, which prefixes each filename with its class directory so the csv matches an ImageFolder layout.

Returns:

A csv with the columns idx and prediction is written to args.label_path; idx falls back to the running sample number when the dataset yields no filenames. Note that a directory named utils is created in the working directory as a side effect.

Return type:

None