C1W4: Understanding the code for classifier

We are provided the above code for updating noise by using classifier. How could one knows that classifier(fake)[:, target_indices] is the feature vector for smiling?

This may be a basic question. But I am really confused on this magic index.

Thank you!

It is because of this previous line of code:

target_indices = feature_names.index("Smiling")

In other words, they specifically looked up the index of the feature “Smiling” in order to use that. As they say in the comment, you are welcome to change this to some other feature name.

I understand target_indices (=31 in this assignment) is the feature index of smiling. The output of classifier has a shape of (hidden_dim * 4, n_classes). But, how could one knows that the feature vector of smiling is exactly the 31st column of the output? I thought we cannot understand the output as Classifier is a deep neural network.

I think it may be related to train_classifier function as highlighted and shown above. I am not sure how this training process passes the index information to the output of classifier.

I would appreciate it if any deep exploration could be provided.


You can arrange the labels in that array in whatever order you want, but the point is that the “real” images are labeled using those labels in whatever order you define them. The algorithm has no intrinsic or “a priori” idea what “Smiling” looks like: you have to tell it by labeling the real training images. That’s what that labels tensor is: the “samples” dimension of that maps to the same dimension the tensor of the “real” images. You can see how it is used by the criterion to compare to the predicted labels from the classifier.

It makes sense for me. Thank you!