Merge pull request #6 from 20kaushik02/phase3_task3

Phase3 task 3 and 4
This commit is contained in:
Pranav Borikar 2023-11-24 10:58:38 -07:00 committed by GitHub
commit 1b1dc90236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 4964 additions and 2 deletions

View File

@ -1311,7 +1311,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.11.4"
}
},
"nbformat": 4,

View File

@ -432,7 +432,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.11.4"
}
},
"nbformat": 4,

4661
Phase 3/task_3.ipynb Normal file

File diff suppressed because it is too large Load Diff

233
Phase 3/task_4.ipynb Normal file

File diff suppressed because one or more lines are too long

68
Phase 3/utils.py Normal file
View File

@ -0,0 +1,68 @@
# All imports
# Math
import math
import random
import cv2
import numpy as np
from scipy.stats import pearsonr
# from scipy.sparse.linalg import svds
# from sklearn.decomposition import NMF
from sklearn.decomposition import LatentDirichletAllocation
# from sklearn.cluster import KMeans
# Torch
import torch
import torchvision.transforms as transforms
from torchvision.datasets import Caltech101
from torchvision.models import resnet50, ResNet50_Weights
import tensorly as tl
# OS and env
import json
import os
from os import getenv
from dotenv import load_dotenv
import warnings
from joblib import dump, load
load_dotenv()
# MongoDB
from pymongo import MongoClient
# Visualizing
import matplotlib.pyplot as plt
valid_classification_methods = {
"m-nn": 1,
"decision-tree": 2,
"ppr": 3,
}
def getCollection(db, collection):
"""Load feature descriptor collection from MongoDB"""
client = MongoClient("mongodb://localhost:27017")
return client[db][collection]
def euclidean_distance_measure(img_1_fd, img_2_fd):
img_1_fd_reshaped = img_1_fd.flatten()
img_2_fd_reshaped = img_2_fd.flatten()
# Calculate Euclidean distance
return math.dist(img_1_fd_reshaped, img_2_fd_reshaped)
valid_feature_models = {
"cm": "cm_fd",
"hog": "hog_fd",
"avgpool": "avgpool_fd",
"layer3": "layer3_fd",
"fc": "fc_fd",
"resnet": "resnet_fd",
}