Skip to content
Snippets Groups Projects
Commit 8dde7790 authored by Chrol-Cannon, Joseph Dr (Computer Science)'s avatar Chrol-Cannon, Joseph Dr (Computer Science)
Browse files

combine smth-else predictions

parent b1cd423f
No related branches found
No related tags found
No related merge requests found
File added
File added
...@@ -174,9 +174,29 @@ def probs_baseline(): ...@@ -174,9 +174,29 @@ def probs_baseline():
return baseline return baseline
def predict_all(): def probs_smthelse():
with open('./cnn_comparison/exp_test_results_ground.pkl', "rb") as f:
[logits_matrix, targets_list, class_to_idx, video_ids] = pickle.load(f)
with open('./features_validation/ids.txt', 'r') as f:
ids = [int(line.rstrip()) for line in f.readlines()]
ids = np.asarray(ids)
flat_list = [item for sublist in video_ids for item in sublist]
baseline_ids = list(int(item.strip()) for item in flat_list)
lookup = dict(zip(baseline_ids, logits_matrix))
# build baseline prediction lookup ordered by our video ids
baseline = np.zeros((len(ids),logits_matrix.shape[1]))
for i in range(len(ids)):
if ids[i] in lookup:
baseline[i,:] = lookup[ids[i]]
return baseline
def predict_all0():
# combine external predictions for 20bn cnn baseline # combine external predictions for 20bn cnn baseline
baseline = probs_baseline() baseline = probs_smthelse()
#baseline = np.zeros((len(mtest),17)) #baseline = np.zeros((len(mtest),17))
# default to null class prediction # default to null class prediction
...@@ -211,6 +231,43 @@ def predict_all(): ...@@ -211,6 +231,43 @@ def predict_all():
return Y return Y
def predict_all():
# combine external predictions for 20bn cnn baseline
baseline = probs_smthelse()
#baseline = np.zeros((len(mtest),17))
# default to null class prediction
Y = np.zeros((len(mtest),), dtype=int)
# generate predictions and probabilities per-model
preds = {}
probs = {}
for idx in rf:
preds[idx] = rf[idx].predict(xtest[idx])
probs[idx] = rf[idx].predict_proba(xtest[idx])
# for each test sample
for i in range(len(mtest)):
mlabel = 0
max_prob = 0.0
# for each model
for idx in rf:
if preds[idx][i] and baseline[i,idx-1] > max_prob:
mlabel = idx
max_prob = baseline[i,idx-1]
# force a guess based on prob if all RF miss detection
if mlabel == 0:
for idx in rf:
if baseline[i,idx-1] > max_prob:
mlabel = idx
max_prob = baseline[i,idx-1]
Y[i] = mlabel
return Y
if __name__ == "__main__": if __name__ == "__main__":
load_labels() load_labels()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment