Skip to content

Commit

Permalink
Update image_sscd.py with comments describing of normalization and re…
Browse files Browse the repository at this point in the history
…sizing of the image
  • Loading branch information
ahmednasserswe committed Nov 29, 2023
1 parent cd191d8 commit 5697bee
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/model/image_sscd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ def compute_sscd(self, iobytes: io.BytesIO) -> str:
:param im: Numpy.ndarray #FIXME
:returns: Imagehash.ImageHash #FIXME
"""
# from SSCD-copy-detection readme https://github.com/facebookresearch/sscd-copy-detection/tree/main#preprocessing
# Normalization using the mean and std of Imagenet
normalize = transforms.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225],
)
# It is recommended by publishers of SSCD-copy-detection to preprocess images for inference either resizing the small edge to 288 or resizing the image to a square tensor.
# resizing the image to a square tensor is more effecient on gpus but can lead to skewed images and so loss of information. So, we are resizing the small edge to 288
small_288 = transforms.Compose([
transforms.Resize(288),
transforms.ToTensor(),
normalize,
])
skew_320 = transforms.Compose([
transforms.Resize([320, 320]),
transforms.ToTensor(),
normalize,
])
# Keeping the code example of resizing the image to a square tensor
# skew_320 = transforms.Compose([
# transforms.Resize([320, 320]),
# transforms.ToTensor(),
# normalize,
# ])

image = Image.open(iobytes)
batch = small_288(image).unsqueeze(0)
Expand Down

0 comments on commit 5697bee

Please sign in to comment.