How to validate autoencoder model after training

I want to detect the fabric defect using autoencoder.
Actually, data size is too small to do ML, so I cropped images to patches.
number of nodefect images: 85
number of patch of a image: 172
Then I trained the autoencoder.

During training time, loss is computed for every patches, maybe # of losses are (num_epoch * # of images * # of patches).
<loss_torch = np.empty((1, num_epoch, 85, 172)) > with this code, I made the np place for losses, then convert to tensor.

During test time, if computed loss (for every patch) > threshold then the image to which this patch belongs will be detected as a defect.

As I divided image into patches and trained Autoencoder, I called Dataloader with (# of batches = 1).
Then I wonder how I can draw a graph that reduces loss as the epoch progresses.
Also, I wonder if I stop training with the status that has [1, # of epochs, # of images, # of patches] shape of losses, and then do model.eval(), proceed with the model evaluation(validate).

Thank you for reading long sentences.

I’m not sure I understand the question correctly, so please feel free to correct me.

Assuming you are calculating the loss for each patch, then you should be able to print this loss during training directly or alternatively calculate the mean of all patches for the particular image.
However, based on your data loading implementation and shuffling, it might be challenging.

For evaluation you could compute the loss in the same way as during training.
However, for the prediction of each image, I would recommend to process all patches of the image sequentially, so that you can yield the right class after classifying all patches.

1 Like

Thank you for reading long question and reply me.

So you mean that during training, compute loss for every patches and then do mean(all losses).
After that, during validating, compute loss and make to classify whether the image is defect or not.

Am I following you?

I’m not sure if you really need to compute the mean of the losses of all patches from the same image and I would assume that you could directly use each patch separately.

During validation you would have to use all patches from the image, apply your threshold, and classify the image based on the classification of all patches corresponding to this image.

1 Like

thank you.I’ll try as you say.