-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_new.py
37 lines (30 loc) · 1002 Bytes
/
utils_new.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
"""
DESCRIPTION: this file contains general utilities that are used in this project
AUTHOR: Lou Chenfei
INSTITUTE: Shanghai Jiao Tong University, UM-SJTU Joint Institute
PROJECT: ECE4730J Advanced Embedded System Capstone Project
"""
import torch
class Namespace():
'''
a data structure to efficiently pass numerous parameters between function calls
'''
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def calculate_average_activations( param:torch.Tensor ):
assert len( param.shape ) == 2
return param.sum().item() / param.numel()
def create_model_file_name( args ):
'''
the file name should include information for:
1. model name
2. train mode
3. early_exit_configurations
4. task
'''
name = 'models_new/' + \
args.model_name + '_' + \
args.task + '_' + \
args.train_mode + '_' + \
args.trained_file_suffix
return name + '.pt'