Skip to main content

Images and the label each of them carries, which may be a set

Description

The data block for task = “classification”. This title said the one label each of them carries until labels_from arrived, and the field-prose ledger is what asked: the engine rewrote its own one-line description of this block to name all three labellings, and re-reading R’s prose for it turned up a heading that had become false rather than a sentence that had.

Usage

classification_data(
  train,
  validation = NULL,
  classes,
  labels_from = NULL,
  test = NULL,
  split = NULL,
  mode = c("nested_dirs", "config_file"),
  strict_labels = TRUE,
  window = NULL,
  subdirs = NULL,
  column_sep = ";",
  shuffle = TRUE
)

Arguments

train Path to the training data: a directory of class directories in “nested_dirs” mode, or a CSV in “config_file” mode.
validation Path to the validation data, or FALSE to train without one.
classes

The class names, in class order. Position is the class index the model learns, which is why it is written rather than read off the directory listing: taken from the filesystem the order would be alphabetical - reproducible, and unrelated to anything - so a model trained where index 1 meant “benign” and used where it means “malignant” reports plausible probabilities and nothing downstream can tell.

In “nested_dirs” mode these are the directory names. At least two, where detection_data() allows one: a detector with one class answers where are the cells, which is a question, and a classifier with one class answers is this a cell with the only answer it has.

There is no background entry. An image is one of these, and a picture of nothing in particular is a class somebody has to name.
labels_from

One CSV column per class, in class order, each cell 0 or 1 - the layout for a label that is a set. Position in this list is paired with classes, so the headers may be called whatever the dataset calls them and the model still learns the classes in the order you named; stated rather than read off the header row for channels_from’s reason, that sorting is reproducible and clinically meaningless.

“config_file” mode only, and that is a refusal rather than a gap: an image cannot sit in two directories without being two files, so nested_dirs cannot express a set of labels at all. strict_labels has nothing to choose between here - the columns are the classes - and is refused rather than ignored.

A cell that is not 0, 1, 0.0 or 1.0 is refused by name, and the case that is written for is -1: the datasets shaped this way write -1 for uncertain and leave the cell empty for not mentioned, both of which have a defensible mapping to 0 or to 1, which is exactly why the reader must not pick one for you. An image with none of the findings is an ordinary labelled row, written as a line of zeros.

There is no threshold, and metric_accuracy() is refused. Each class decides for itself at a probability of 0.5, and a threshold is a number about your data rather than one this format should invent. Accuracy is refused outright rather than redefined: measured on 4000 images with findings at 10%, 5%, 3% and 2%, a model answering no to everything scores 0.8137 on exact match and 0.9507 per class, above a model holding half the available signal - so neither reading can be what a monitor watches. Use metric_balanced_accuracy(), metric_f1() or metric_auc().
test Path to a held-out set, scored but never trained on.
split A split() block, to cut a validation and test set out of the training data. For this task the cut is stratified by the engine, so every class reaches every side - a random 70/15/15 of 100 images at a 3% prevalence leaves some part with none of the rare class 91% of the time, and a per-class metric cannot average over a class its pass never held.
mode “nested_dirs” or “config_file”.
strict_labels

Refuse an image whose label is not in classes. FALSE skips it instead, which is how to train on two of a dataset’s three classes without moving any files. It matters more here than it does for a box: a skipped object leaves the rest of its image in the training set, while a skipped image leaves nothing, so the same setting quietly changes how much data there is.

Refused beside labels_from, where the state it chooses between cannot arise: the columns are the classes, so there is no cell that could hold a class nobody named.
window How values in real units reach the model, for DICOM and NIfTI - see segmentation_data(), which documents the named windows. Ignored for ordinary pictures.
subdirs Refused, and named rather than dropped because every sibling data constructor has it. For segmentation and detection a sample is a directory with the image in one subdirectory and what labels it in the other; a classification sample is one image whose label is the directory it sits in, so there is no second subdirectory.
column_sep For config_file, what separates several paths in one cell.
shuffle Shuffle the training data between epochs.

Details

What this constructor is for is as much the fields it has not got as the two it adds: colormap, labels, regions, classes_from, channels_from and target_spacing all describe a mask or a grid, and a label is neither.

Where the labelling is written follows from mode rather than being said twice. In “nested_dirs” mode the directories under train are the classes, with the images inside them - the layout nearly every image dataset ships in. In “config_file” mode the CSV’s label column holds the class name.

And labels_from is the third way, for a label that is a set rather than one of a list of alternatives - a chest film with four findings is four independent questions. It is a naming rather than a switch, for the reason regions and classes_from are on the mask side: the target changes and not only the activation, so there is nothing a multilabel = TRUE could have meant on a label column that structurally cannot say an image has two findings.

Value

A data specification, to be passed to platypus_spec().

See Also

classifier(), class_balance(), available_metrics()

Examples

library("rplatypus")

classification_data("train/", "valid/", classes = c("benign", "malignant"))
$train_path
[1] "train/"

$validation_path
[1] "valid/"

$validation
NULL

$test_path
NULL

$split
NULL

$mode
NULL

$classes
[1] "benign"    "malignant"

$labels_from
NULL

$strict_labels
NULL

$window
NULL

$column_sep
NULL

$shuffle
NULL

attr(,"class")
[1] "platypus_classification_data" "list"                        
attr(,"task")
[1] "classification"