This notebook plots accuracy curves on the CIFAR10 test set for each combination of model parameters (different combinations of retinal bottleneck and ventral stream depth). It corresponds to Figure 4 in the Appendix.
Note: The easiest way to use this is as a colab notebook, which allows you to dive in with no setup.
from os.path import exists
if not exists('opponency.zip'):
!wget -O opponency.zip https://github.com/ecs-vlc/opponency/archive/master.zip
!unzip -qq opponency.zip
!mv opponency-master/* ./
!rm -r opponency-master
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import matplotlib.font_manager
rc('font',**{'family':'serif','serif':['Computer Modern Roman'],'size':13})
rc('text', usetex=True)
import csv
bottlenecks = [1,2,4,8,16,32]
ventral_depths = [0,1,2,3,4]
cmodes=['grey', 'colour']
def read_csv(n_bn, d_vvs, t, cmode):
log_file = f'./logs/{cmode}/model_{n_bn}_{d_vvs}_{t}.csv'
with open(log_file) as csvfile:
reader = csv.DictReader(csvfile)
data = []
for row in reader:
data.append(row)
return data
def get_acc_avg_sem(n_bn, d_vvs, cmode, epoch=19, n_trials=10):
# get the mean and standard error of the test accuracy across the trials
accs = []
for t in range(n_trials):
data = read_csv(n_bn, d_vvs, t, cmode)
data = list(filter(lambda r: r['epoch']==str(epoch), data))[0]
test_acc = data['val_acc']
accs.append(float(test_acc))
arr = np.array(accs)
return arr.mean(), arr.std() / np.sqrt(arr.shape[0])
plt.figure(figsize=(3,4))
lines = [':', '-.', '--', ':', '-.', '--']
for n_bn in bottlenecks:
means = []
sems = []
for d_vvs in ventral_depths:
mu, se = get_acc_avg_sem(n_bn, d_vvs, 'grey')
means.append(mu)
sems.append(se)
sems = np.array(sems)
plt.plot(ventral_depths, means, linestyle=lines.pop()) # marker=markers.pop()
plt.fill_between(ventral_depths, means - sems, means + sems, alpha=0.2)
plt.xlabel('Ventral Depth')
plt.ylabel('CIFAR-10 Test Set Performance')
plt.xticks(range(len(ventral_depths)), ventral_depths)
plt.xlim(0, 4)
plt.ylim(0.5,0.8)
plt.savefig("figures/greyscale_accuracy.pdf", bbox_inches='tight')
plt.show()
markers = ['o', 's', 'v', 'P', 'D', '^']
lines = [':', '-.', '--', ':', '-.', '--']
plt.figure(figsize=(3,4))
for n_bn in bottlenecks:
means = []
sems = []
for d_vvs in ventral_depths:
mu, se = get_acc_avg_sem(n_bn, d_vvs, 'colour-ch')
means.append(mu)
sems.append(se)
sems = np.array(sems)
plt.plot(ventral_depths, means, linestyle=lines.pop()) # marker=markers.pop()
plt.fill_between(ventral_depths, means - sems, means + sems, alpha=0.2)
plt.legend(['$N_{BN} = ' + str(w) + '$' for w in bottlenecks], frameon=False)
plt.xlabel('Ventral Depth')
plt.ylabel('CIFAR-10 Test Set Performance')
plt.xticks(range(len(ventral_depths)), ventral_depths)
plt.xlim(0, 4)
plt.ylim(0.5,0.8)
plt.savefig('figures/accuracy.pdf', bbox_inches='tight')
plt.show()
markers = ['o', 's', 'v', 'P', 'D', '^']
lines = [':', '-.', '--', ':', '-.', '--']
plt.figure(figsize=(3,4))
for n_bn in bottlenecks:
means = []
sems = []
for d_vvs in ventral_depths:
mu, se = get_acc_avg_sem(n_bn, d_vvs, 'imagenet', n_trials=3)
means.append(mu)
sems.append(se)
sems = np.array(sems)
plt.plot(ventral_depths, means, linestyle=lines.pop()) # marker=markers.pop()
plt.fill_between(ventral_depths, means - sems, means + sems, alpha=0.2)
plt.legend(['$N_{BN} = ' + str(w) + '$' for w in bottlenecks], frameon=False)
plt.xlabel('Ventral Depth')
plt.ylabel('ImageNet Test Set Performance')
plt.xticks(range(len(ventral_depths)), ventral_depths)
plt.xlim(0, 4)
# plt.ylim(0.5,0.8)
plt.savefig('figures/imagenet_accuracy.pdf', bbox_inches='tight')
plt.show()