In [108]:
import numpy as np
import matplotlib.pyplot as plt
import time
import tools.my_io as my_io
%matplotlib inline
import caffe
# Set the right path to your model definition file, pretrained model weights,
# and the image you would like to classify.
MODEL_FILE = '/media/raid_arr/data/ndsb/config/deploy_cnn_v3_maxout_supersparse.prototxt'
PRETRAINED = '/media/raid_arr/data/ndsb/models/zoomed_out_vanilla_smallmaxout/simple_fold0_iter_3000.caffemodel'
MEAN_VALUE = 23
IMAGE_FILE = '/afs/ee.cooper.edu/user/t/a/tam8/data/ndsb/train/acantharia_protist/100224.jpg'
VALIDATION_DB = '/media/raid_arr/tmp/test0_norm_lmdb'
In [120]:
import numpy as np
# DUMMY DATA
n_obs = 615
# 0 8
# 1 59
# 2 14
# 3 33
# 4 7
fine_preds = {
0: np.random.uniform(size=(n_obs, 8)),
1: np.random.uniform(size=(n_obs, 59)),
2: np.random.uniform(size=(n_obs, 14)),
3: np.random.uniform(size=(n_obs, 33)),
4: np.random.uniform(size=(n_obs, 7)),
}
for k, v in fine_preds.items():
fine_preds[k] = v/np.tile(v.sum(axis=1), (v.shape[1], 1)).T
coarse_pred = np.random.uniform(size=(n_obs, 5))
coarse_pred = coarse_pred/np.tile(coarse_pred.sum(axis=1),
(coarse_pred.shape[1], 1)).T
In [136]:
# each column scales the corresponding fine prediction
# final_pred = np.zeros((n_obs, 121))
def aggregate_fine_pred(coarse_pred, fine_pred_d):
"""
fine_pred_d should have keys corresponding to coarse weight index
"""
pred_list = []
for col in range(coarse_pred.shape[1]):
pred_list.append(coarse_pred[:, col][:, None] * fine_preds[col])
final_pred = np.concatenate(pred_list, axis=1)
return final_pred
final_pred = aggregate_fine_pred(coarse_pred, fine_preds)
In [123]:
import specialism as sp
from le import le
import itertools
# Sort by the column labels
zz = [sp.coarse_to_fine[k] for k in sorted(sp.coarse_to_fine.keys())]
qq = list(itertools.chain(*zz))
In [137]:
final_pred
Out[137]:
In [125]:
ordered = []
for col in qq:
ordered.append(final_pred[:, col])
In [127]:
ordered_pred = np.array(ordered).T
In [129]:
ordered_pred.shape
Out[129]: