-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_metrics.py
67 lines (54 loc) · 1.41 KB
/
exp_metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# coding: utf-8
bs = 64
import os
USE_GPUS = '3'
os.environ['CUDA_DEVICE_ORDER']='PCI_BUS_ID'
os.environ['CUDA_VISIBLE_DEVICES'] = USE_GPUS
N_GPUS = len(USE_GPUS.split(','))
from fastai.metrics import error_rate
import sys
import copy
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import torch.optim
from order_metrics import *
from model import *
from utils import *
from evaluation import *
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="torch.nn.functional")
log_folder = 'res'
log_suffix = 't5_metrics'
log_file = os.path.join(log_folder, f'{log_suffix}.txt')
matrix_path = os.path.join('matrixes', log_suffix)
data = load_dataset("cifar100", bs=bs)
lr = 1e-4
epochs = 80
its = 40
orders = [
total_variation_image_batch,
activation_sum_image_batch,
entropy_image_batch,
entropy_shannon_1diff_image_batch,
max_activation_image_batch,
median_activation_image_batch
]
for order in orders:
config = {
'type': 'layer',
'data': data,
'model': create_small_model,
'matrixpath': matrix_path,
'lr': lr,
'epochs': epochs,
'its': its,
'pos': {3: 64},
'order': order,
'aggregate': 'imagenette',
'constrainmode': 'full_owa',
'init_denominator': 64,
'metric': top_k_accuracy
}
log_results(run_config(config), log_file)