Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/pixr.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/train.cpython-312.pyc
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/originals/Screenshot 2025-04-29 191007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/test/meme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/test/meme1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
torch
torchvision
numpy
Pillow
scikit-learn
25 changes: 25 additions & 0 deletions test_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from sklearn.metrics.pairwise import cosine_similarity
from train import originals, names, get_embedding
import numpy as np

def test_images(test_path,originals,names,threshold=0.88):
#originals, names = load_original_embeddings(original_folder)
test_emb = get_embedding(test_path)
sims = cosine_similarity(test_emb, originals)[0]
best_idx = np.argmax(sims)
best_score = sims[best_idx]

print(f"Best match: {names[best_idx]}")
print(f"Similarity score: {best_score:.3f}")

if best_score >= threshold:
print(" Match found !")
else:
print(" No match found.")

test_images(
test_path=r"C:\\Users\\LENOVO\\Documents\\PROJECTS\\pixel-peep\\images\\test\\meme.png",
originals=originals,
names=names,
threshold=0.80
)
66 changes: 66 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
import torch
import numpy as np
from PIL import Image
from torchvision import models, transforms
#from sklearn.metrics.pairwise import cosine_similarity


resnet = models.resnet50(pretrained=True)
resnet = torch.nn.Sequential(*list(resnet.children())[:-1]) # Remove layer because it is not needed (last layers) only needs features//classifier
resnet.eval()


transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),

])

def get_embedding(image_path):
image = Image.open(image_path).convert("RGB")
image = transform(image).unsqueeze(0)
with torch.no_grad():
embedding = resnet(image).squeeze().numpy()
return embedding.reshape(1, -1)


def train_images(folder_path):
embeddings = []
filenames = []
for file in os.listdir(folder_path):
if file.lower().endswith((".jpg", ".png")):
path = os.path.join(folder_path, file)
emb = get_embedding(path)
embeddings.append(emb)
filenames.append(file)
return np.vstack(embeddings), filenames

original_folder=r"C:\\Users\\LENOVO\\Documents\\PROJECTS\\pixel-peep\\images\\originals"
originals, names = train_images(original_folder)

#never mind this part
'''
# Match test image to originals
def test_images(test_path,originals,names,threshold=0.88):
#originals, names = load_original_embeddings(original_folder)
test_emb = get_embedding(test_path)
sims = cosine_similarity(test_emb, originals)[0]
best_idx = np.argmax(sims)
best_score = sims[best_idx]

print(f"Best match: {names[best_idx]}")
print(f"Similarity score: {best_score:.3f}")

if best_score >= threshold:
print(" Match found !")
else:
print(" No match found.")
#original_folder=r"C:\\Users\\LENOVO\\Documents\\PROJECTS\\pixel-peep\\images\\originals"
#originals, names = load_original_embeddings(original_folder)
#test_images(
test_path=r"C:\\Users\\LENOVO\\Documents\\PROJECTS\\pixel-peep\\images\\test\\meme.png",
originals=originals,
names=names,
threshold=0.88
#)'''