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 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 |
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 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) |
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 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) |
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
from googletrans import Translator | |
translator = Translator() | |
result = translator.translate('description in any language', dest='en') |
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
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) |
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
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']) |
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
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: |
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
# 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) |
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
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' |
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
# 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 | |