Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- from sklearn.metrics import accuracy_score, recall_score, f1_score, precision_score
- def training_overview(correct, predictions):
- print("Accuracy: ", accuracy_score(correct, predictions))
- # za ako se povekje od 2 klasi average='macro'.
- # labels=np.unique(predictions) dodadeno vo sluchaj da ima nekoi labeli vo correct koi gi nema vo predictions
- print("Precision: ", precision_score(correct, predictions, average='macro', labels=np.unique(predictions)))
- print("Recall score: ", recall_score(correct, predictions, average='macro'))
- print("F1 score: ", f1_score(correct, predictions, average='macro', labels=np.unique(predictions)))
- print()
- def create_dict():
- classes_pd = pd.read_csv("./visual_genome_objects.csv", sep=',')
- classes = dict()
- for row in classes_pd.values:
- classes[row[0]] = row[1]
- return classes
- def create_classes_one_hot_encoded(classes_dict):
- one_hot_encoded = dict()
- for key, value in classes_dict.items():
- if value == 'tree':
- one_hot_encoded[key] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- elif value == 'car':
- one_hot_encoded[key] = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
- elif value == 'man':
- one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
- elif value == 'road':
- one_hot_encoded[key] = [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
- elif value == 'building':
- one_hot_encoded[key] = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
- elif value == 'window':
- one_hot_encoded[key] = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]
- elif value == 'desk':
- one_hot_encoded[key] = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
- elif value == 'chair':
- one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 1, 0, 0]
- elif value == 'shelf':
- one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
- elif value == 'glass':
- one_hot_encoded[key] = [0, 0, 1, 0, 0, 0, 0, 0, 0, 1]
- return one_hot_encoded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement