In [2]:
import sys
import os
sys.path.append("/home/nakamura/network_dissection/NetDissect/src")
os.chdir("/home/nakamura/network_dissection/NetDissect/")
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn
from viewprobe import NetworkProbe
from category_info import category_info
script = "/home/nakamura/network_dissection/NetDissect/research/top_iou_detected_ratio_1227.ipynb"
% matplotlib inline
In [3]:
# define models
alex = {}
alex["name"] = "alexnet_imagenet"
alex["directory"] = "./dissection/alexnet_imagenet_full_conv_384/"
alex["blobs"] = ["conv1", "conv2", "conv3", "conv4", "conv5", "fc6-conv", "fc7-conv", "fc8-conv"]
vgg_material = {}
vgg_material["name"] = "vgg_material"
vgg_material["directory"] = "./dissection/vgg_material_full_conv/"
vgg_material["blobs"] = ["conv1_2", "conv2_2","conv3_3", "conv4_3", "conv5_3", "fc6-conv", "fc7-conv", "fc8-conv"]
sentibank = {}
sentibank["name"] = "sentibank"
sentibank["directory"] = "./dissection/caffe_sentibank_full_conv/"
sentibank["blobs"] = ["conv1", "conv2","conv3", "conv4", "conv5", "fc6-conv", "fc7-conv", "fc8-conv"]
vgg_face = {}
vgg_face["name"] = "vgg_face"
vgg_face["directory"] = "./dissection/VGG_FACE_full_conv/"
vgg_face["blobs"] = ["conv1_2", "conv2_2","conv3_3", "conv4_3", "conv5_3", "fc6-conv", "fc7-conv", "fc8-conv"]
models = [alex, vgg_material, sentibank, vgg_face]
In [4]:
def n_detec(model, blob, threshold=0.05):
"""return ordered_iou averaged in a layer as pandas.Series"""
path= os.path.join(model["directory"], blob + "-iou.csv")
iou = pd.read_csv(path, index_col=0)
iou_threshold = iou > threshold
num_detec = iou_threshold.mean(axis=0)
return num_detec
In [62]:
n_alex = n_detec(alex, "fc7-conv")
n_vgg = n_detec(vgg_material, "fc7-conv")
ratio = n_vgg / n_alex
ratio = ratio[ratio > 1]
fc7_ = set(ratio.index.tolist())
ratio.sort_values(ascending=False).head(200)
Out[62]:
In [63]:
n_alex = n_detec(alex, "fc6-conv")
n_vgg = n_detec(vgg_material, "fc6-conv")
ratio = n_vgg / n_alex
ratio = ratio[ratio > 1]
fc6_ = set(ratio.index.tolist())
ratio.sort_values(ascending=False).head(50)
Out[63]:
In [43]:
n_alex = n_detec(alex, "conv5")
n_vgg = n_detec(vgg_material, "conv5_3")
ratio = n_alex / n_vgg
ratio = ratio[ratio > 1.0]
conv5_ = set(ratio.index.tolist())
print(ratio.sort_values(ascending=False))
In [58]:
concepts_ = conv5_
In [57]:
models = [alex, vgg_material, vgg_face]
result={}
concept = "book"
result[concept] = {}
fig, ax = plt.subplots(figsize=(12,8))
for model in models:
n_detec_list = n_detec_summary(model, concept)
result[concept][model["name"]] = n_detec_list
ax.plot(n_detec_list, label=model["name"])
ax.set_xlim(0,6)
ax.set_xticklabels(vgg_material["blobs"])
ax.legend(loc="best")
ax.set_ylabel("number of detectors")
ax.set_title("number of detectors for {}".format(concept))
plt.show()
In [15]:
result
Out[15]:
In [59]:
models = [alex, vgg_material, vgg_face]
concepts = ["dog", "cat", "bicycle", "grass", "water", "lacelike", "waterfall-fan-s", "head", "hair"]
result={}
for concept in concepts_:
result[concept] = {}
fig, ax = plt.subplots(figsize=(12,8))
for model in models:
n_detec_list = n_detec_summary(model, concept)
result[concept][model["name"]] = n_detec_list
ax.plot(n_detec_list, label=model["name"])
ax.set_xticklabels(vgg_material["blobs"])
ax.legend(loc="best")
ax.set_ylabel("number of detectors")
ax.set_title("number of detectors for {}".format(concept))
plt.show()
In [55]:
def plot():
models = [alex, vgg_material, vgg_face]
concepts = ["dog", "cat", "bicycle", "grass", "water", "lacelike", "waterfall-fan-s", "head", "hair"]
result={}
for concept in concepts_:
result[concept] = {}
fig, ax = plt.subplots(figsize=(12,8))
ax.set_xlim(0, 6)
for model in models:
n_detec_list = n_detec_summary(model, concept)
result[concept][model["name"]] = n_detec_list
ax.plot(n_detec_list, label=model["name"])
ax.set_xticklabels(vgg_material["blobs"])
ax.legend(loc="best")
ax.set_ylabel("number of detectors")
ax.set_title("number of detectors for {}".format(concept))
plt.show()
In [ ]: