Unsupervised segmentation for defect detection

I would like to train a network for defect detection, on the same type of object (i.e. a production line for plastic caps); I have an image set good with parts and an image set with defective parts. I know that someone is able to do it using a sliding window of patch_size to process the entire image, with a certain overlap, just using the two datasets. Does someone know if there is anything similar in pytorch or give me some hint for this?