concept label in category deep learning

appears as: labels, labels, The label, label, label
Deep Learning with Python, Second Edition

This is an excerpt from Manning's book Deep Learning with Python, Second Edition.

train_images and train_labels form the training set, the data that the model will learn from. The model will then be tested on the test set, test_images and test_labels. The images are encoded as NumPy arrays, and the labels are an array of digits, ranging from 0 to 9. The images and labels have a one-to-one correspondence.

The input data is vectors, and the labels are scalars (1s and 0s): this is one of the simplest problem setups you’ll ever encounter. A type of model that performs well on such a problem is a plain stack of densely-connected (Dense) layers with relu activations.

To vectorize the labels, there are two possibilities: you can cast the label list as an integer tensor, or you can use one-hot encoding. One-hot encoding is a widely used format for categorical data, also called categorical encoding. For a more detailed explanation of one-hot encoding, see section TODO. In this case, one-hot encoding of the labels consists of embedding each label as an all-zero vector with a 1 in the place of the label index. Here’s an example:

Listing 4.14. Encoding the labels
def to_one_hot(labels, dimension=46):
    results = np.zeros((len(labels), dimension))
    for i, label in enumerate(labels):
        results[i, label] = 1.
    return results
one_hot_train_labels = to_one_hot(train_labels)        #1
one_hot_test_labels = to_one_hot(test_labels)          #2
Deep Learning Design Patterns

This is an excerpt from Manning's book Deep Learning Design Patterns.

#E Multi-class example, determine the label predicted from the softmax output.

#C Unsupervised training where the labels are the input.

Deep Learning with PyTorch

This is an excerpt from Manning's book Deep Learning with PyTorch.

In this chapter, we will explore three popular pretrained models: a model that can label an image according to its content, another that can fabricate a new image from a real image, and a model that can describe the content of an image using proper English sentences. We will learn how to load and run these pretrained models in PyTorch, and we will introduce PyTorch Hub, a set of tools through which PyTorch models like the pretrained ones we’ll discuss can be easily made available through a uniform interface. Along the way, we’ll discuss data sources, define terminology like label, and attend a zebra rodeo.

# In[13]:
with open('../data/p1ch2/imagenet_classes.txt') as f:
    labels = [line.strip() for line in f.readlines()]

The output array candidateLabel_a is the same shape as clean_a, which we used for input, but it has 0 where the background voxels are, and increasing integer labels 1, 2, ..., with one number for each of the connected blobs of voxels making up a nodule candidate. Note that the labels here are not the same as labels in a classification sense! These are just saying “This blob of voxels is blob 1, this blob over here is blob 2, and so on.”

SciPy also sports a function to get the centers of mass of the nodule candidates: scipy.ndimage.measurements.center_of_mass. It takes an array with per-voxel densities, the integer labels from the label function we just called, and a list of which of those labels need to have a center calculated. To match the function’s expectation that the mass is non-negative, we offset the (clipped) ct.hu_a by 1,001. Note that this leads to all flagged voxels carrying some weight, since we clamped the lowest air value to -1,000 HU in the native CT units.

Deep Learning with R

This is an excerpt from Manning's book Deep Learning with R.

Listing 2.5. Preparing the labels
train_labels <- to_categorical(train_labels) test_labels <- to_categorical(test_labels)

train_images and train_labels form the training set: the data from which the model will learn. The model will then be tested on the test set: test_images and test_labels. The images are encoded as 3D arrays, and the labels are a 1D array of digits, ranging from 0 to 9. The images and labels have a one-to-one correspondence.

The input data is vectors, and the labels are scalars (1s and 0s): this is the easiest setup you’ll ever encounter. A type of network that performs well on such a problem is a simple stack of fully connected (dense) layers with relu activations: layer_dense (units = 16, activation = "relu").

3.5.6. A different way to handle the labels and the loss

We mentioned earlier that another way to encode the labels would be to preserve their integer values. The only thing this approach would change is the choice of the loss function. The previous loss function, categorical_crossentropy, expects the labels to follow a categorical encoding. With integer labels, you should use sparse_categorical_crossentropy:

Deep Learning with Python

This is an excerpt from Manning's book Deep Learning with Python.

train_images and train_labels form the training set, the data that the model will learn from. The model will then be tested on the test set, test_images and test_labels. The images are encoded as Numpy arrays, and the labels are an array of digits, ranging from 0 to 9. The images and labels have a one-to-one correspondence.

The input data is vectors, and the labels are scalars (1s and 0s): this is the easiest setup you’ll ever encounter. A type of network that performs well on such a problem is a simple stack of fully connected (Dense) layers with relu activations: Dense(16, activation='relu').

3.5.6. A different way to handle the labels and the loss

We mentioned earlier that another way to encode the labels would be to cast them as an integer tensor, like this:

y_train = np.array(train_labels)
y_test = np.array(test_labels)

The only thing this approach would change is the choice of the loss function. The loss function used in listing 3.21, categorical_crossentropy, expects the labels to follow a categorical encoding. With integer labels, you should use sparse_categorical_crossentropy: