This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn as nn | |
class WeightedEMDLossWithConfidencePenalty(nn.Module): | |
""" | |
Original Idea of why this Loss: | |
1. If the actual class was "0" and model predicted class "4", then I want it to penalise more than if it would have predicted it class "2": Addressed by the Vanilla EMD Loss itself | |
2. Penalization based on classes. For example, if the weights are [2,2,1,1,1] then it penalizes twice if the wrong prediction is from Class "0" or "1" vs when the wrong predictions were from the remaining classes: Addressed by class_weights | |
3. If the model is correctly predicting the right class but with a Low confidence, penalise it. For example if the True class was class 0" and my model predicted class "0" BUT I want to penalise it more when it predicted with a probability of 0.6 than when it predicted with a probability of 0.9: Addressed by the `correct_pred_low_prob_penalty` logic | |
4. If the model is Wrongly predicting the class and that too with a high confidence, penalise it ev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install selenium | |
from selenium import webdriver | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.common.by import By | |
import time | |
from selenium.webdriver.common.action_chains import ActionChains | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium.webdriver.common.keys import Keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process(sentence,use_lemmetization:False, use_stemming:False, add_pos: False, remove_length:bool = False): | |
if not isinstance(sentence,str): | |
return '' | |
# convert the characters into lower case | |
a = sentence.lower() | |
# remomve newline character | |
a = re.sub(r"\n+", " ", a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from PIL import Image | |
import numpy as np | |
import glob | |
def select_box(results:np.ndarray,method:str)->int: | |
''' | |
Select a Single BB based on Max Probability or Max area logic | |
args: | |
results: Pass in the results by detection module in (classes, scores, boxes) format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get top-K accuracy from results. Given a query and its related results, it'll find if any of the Ground Truth are in results. | |
# Or How many of the results are in Ground Truth | |
import numpy as np | |
def get_relative_acc(test_result_indices:[np.ndarray,list],similar_image_indices:[np.ndarray,list])->float: | |
''' | |
Check HOW MANY similar images are in returned results for single test image | |
''' | |
# because then only it'll be relative. If an image has 2,3,4 similar images, it won't matter. It'll normalize relative acc |