Skip to content

Instantly share code, notes, and snippets.

View AdroitAnandAI's full-sized avatar

Anand P V AdroitAnandAI

View GitHub Profile
@AdroitAnandAI
AdroitAnandAI / preprocess_output_landmark.py
Created September 20, 2020 14:47
Landmarks Output Preprocessing
def preprocess_output(self, outputs, image):
'''
Before feeding the output of this model to the next model,
you might have to preprocess the output. This function is where you can do that.
'''
# https://docs.openvinotoolkit.org/latest/omz_models_intel_facial_landmarks_35_adas_0002_description_facial_landmarks_35_adas_0002.html
h, w = image.shape[0:2]
paddingConstant = 10
@AdroitAnandAI
AdroitAnandAI / output_process_gaze.py
Created September 20, 2020 14:45
Gaze Output Preprocessing
def preprocess_output(self, output, head_position):
'''
Before feeding the output of this model to the next model,
you might have to preprocess the output. This function is where you can do that.
'''
roll = head_position[2]
gaze_vector = output / cv2.norm(output)
cosValue = math.cos(roll * math.pi / 180.0)
sinValue = math.sin(roll * math.pi / 180.0)
@AdroitAnandAI
AdroitAnandAI / moveMouse.py
Created September 20, 2020 14:43
To move mouse with gaze and head
def moveWithGaze(self, x, y):
# To bound the x, y coordinates within screen.dimensions.
x = max(min(x, self.x_max), self.x_min)
y = max(min(y, self.y_max), self.y_min)
# To compute the x, y coordinates in the screen.
x_cord = self.w * (1 - (x - self.x_min) / (self.x_max - self.x_min))
y_cord = self.h * (y - self.y_min) / (self.y_max - self.y_min)
from googletrans import Translator
translator = Translator()
result = translator.translate('description in any language', dest='en')
@AdroitAnandAI
AdroitAnandAI / topic_conf.py
Created August 18, 2020 12:09
Topic_Confidence
LDA_df = pd.DataFrame(v,columns=df_topic_keywords.T.columns)
NMF_df = pd.DataFrame(d,columns=df_topic_keywords1.T.columns)
LDA_normalized = normalize(LDA_df)
NMF_normalized = normalize(NMF_df)
LDANMF = pd.concat([NMF_normalized,LDA_normalized],axis=1)
dominant_topic = np.argmax(LDANMF.values, axis=1)
vectorizer = CountVectorizer(analyzer='word',
min_df=3, # minimum required occurences of a word
stop_words='english', # remove stop words
lowercase=True, # convert all words to lowercase
token_pattern='[a-zA-Z0-9]{3,}', # num chars > 3
max_features=5000, # max number of unique words. Build a vocabulary that only consider the top max_features ordered by term frequency across the corpus
)
data_vectorized = vectorizer.fit_transform(data['description'])
@AdroitAnandAI
AdroitAnandAI / merger_logic.py
Created August 17, 2020 17:40
Merger_Logic
result = []
for idx in artClassifier.index:
if (artClassifier['confidence'][idx] > 0.05):
result.append([artClassifier['id'][idx], str(artClassifier['category'][idx])[6:-2].replace("/", "^")])
elif (urlClassifier['confidence'][idx] > 0.4):
result.append([urlClassifier['id'][idx], str(urlClassifier['category'][idx])[6:-2].replace("/", "^")])
else:
@AdroitAnandAI
AdroitAnandAI / w2v.py
Created August 17, 2020 17:36
word2vec
# from gensim.models import Word2Vec
from gensim.models.word2vec import Word2Vec
from gensim.models import KeyedVectors
model = KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin.gz', binary=True)
onlineNode = find_by_attr(root, 'Online Services')
onlineNode.name = 'Online'
family = find_by_attr(root, 'Family and Relationships')
family.name = 'Family Relationships'
career = find_by_attr(root, 'Career & Job')
career.name = 'Profession'
@AdroitAnandAI
AdroitAnandAI / compute_confidence.py
Created August 17, 2020 17:24
Compute Confidence
# To compute the confidence score of category prediction based on the numerical distribution of values in the list
def computeConfidence(similarityList):
similarScores = set(similarityList)
highest = max(similarScores)
similarScores.remove(highest)
if (len(similarScores) == 0):
return 0