def compute_channel_distances(mean_train_channel_vector, features, category_name):
"""
Input:
---------
mean_train_channel_vector : mean activation vector for a given class.
It can be computed using MAV_Compute.py file
features: features for the category under consideration
category_name: synset_id
Output:
---------
channel_distances: dict of distance distribution from MAV for each channel.
distances considered are eucos, cosine and euclidean
"""
eucos_dist, eu_dist, cos_dist = [], [], []
for channel in range(features[0].shape[0]):
eu_channel, cos_channel, eu_cos_channel = [], [], []
# compute channel specific distances
for feat in features:
eu_channel += [spd.euclidean(mean_train_channel_vector[channel, :], feat[channel, :])]
cos_channel += [spd.cosine(mean_train_channel_vector[channel, :], feat[channel, :])]
eu_cos_channel += [spd.euclidean(mean_train_channel_vector[channel, :], feat[channel, :])/200. +
spd.cosine(mean_train_channel_vector[channel, :], feat[channel, :])]
eu_dist += [eu_channel]
cos_dist += [cos_channel]
eucos_dist += [eu_cos_channel]
# convert all arrays as scipy arrays
eucos_dist = sp.asarray(eucos_dist)
eu_dist = sp.asarray(eu_dist)
cos_dist = sp.asarray(cos_dist)
# assertions for length check
assert eucos_dist.shape[0] == 10
assert eu_dist.shape[0] == 10
assert cos_dist.shape[0] == 10
assert eucos_dist.shape[1] == len(features)
assert eu_dist.shape[1] == len(features)
assert cos_dist.shape[1] == len(features)
channel_distances = {'eucos': eucos_dist, 'cosine': cos_dist, 'euclidean':eu_dist}
return channel_distances
#------------------------------------------------------------------------------------------
评论列表
文章目录