Image classification in Pytorch
I'm working on facenet-pytorch library in Pytorch, I want to know

the data augmentation should be in train dataset or test data set?

how many images should I put to test data set at least (I've used 2% of images in test data set)

I have 21 classes(21 persons face) and with (vggface2 dataset ) with evaluation mode , does it enough for training and test data set?

how to visualize the images in test dataset to display if a face matched or not
I tried this but it will rise this error :



TypeError: Invalid shape (3, 160, 160) for image data

The shape of images are : (10, 3, 160, 160)
dataiter = iter(test_loader)
images, labels = dataiter.next()
# get predictions
preds = np.squeeze(net(images).data.max(1, keepdim=True)[1].numpy())
images = images.numpy()

# plot the images in the batch, along with predicted and true labels
fig = plt.figure(figsize=(25, 4))
for idx in np.arange(batch_size):
    ax = fig.add_subplot(2, batch_size/2, idx+1, xticks=[], yticks=[])
    ax.imshow(np.squeeze(images[idx]), cmap='gray')
    ax.set_title(&quot;{} ({})&quot;.format(classes[preds[idx]], classes[labels[idx]]),
             color=(&quot;green&quot; if preds[idx]==labels[idx] else &quot;red&quot;))


how to take input faces from webcam after detected the face (prediction function)?

cap = cv.VideoCapture(0)
while True:
    ret, frame = cap.read()
    frame = cv.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
    image = predict_draw_bounding_box(frame)
    cv.imshow('Output', image)
    c = cv.waitKey(1)
    if c == 27:
        break
cap.release()
cv.destroyAllWindows()

But I don't know to implement predict_draw_bounding_box function?
Thanks for any advice

That's a lot of questions; you should probably split those up into multiple questions. In any case, I'll try answering some.


Data augmentation should generally be done on the train dataset
only. Typical augmentations include random rotation, resized crops,
horizontal flips, cutout etc. All of these only go on the train set.

Other than this, off the top of my head, I can only think of channel
normalization as the only augmentation you usually apply to both
training and testing set. You compute x-x_mean/sigma channelwise
for all images in a dataset.
The percentage of images in your test dataset is entirely empirical, and depends on how many images you actually have. For very large datasets with a million plus images, small percentages like 2% is okay. However if your number of images is in the ten thousands, thousands, or even less, it's good practice to keep around 20% as the test set.
Can't understand your question.
Your images are in the shape (3, 160, 160). It's the channel-first syntax used by pytorch's nn.Module system, but plotting an RGB image in matplotlib requires it to have the channel in the last dimension, ie, (160,160,3). If images is a batch of images of shape (10,3,160,160), then do:

...
images = images.numpy()
images = images.swapaxes(1,2).swapaxes(2,3)
...


This will reshape it to (10,160,160,3), without harming the axes order.
No clue.

