LibMTL.utils
¶
- set_random_seed(seed)[source]¶
Set the random seed for reproducibility.
- Parameters
seed (int, default=0) – The random seed.
- set_device(gpu_id)[source]¶
Set the device where model and data will be allocated.
- Parameters
gpu_id (str, default='0') – The id of gpu.
- count_parameters(model)[source]¶
Calculate the number of parameters for a model.
- Parameters
model (torch.nn.Module) – A neural network module.
- count_improvement(base_result, new_result, weight)[source]¶
Calculate the improvement between two results as
\[\Delta_{\mathrm{p}}=100\%\times \frac{1}{T}\sum_{t=1}^T \frac{1}{M_t}\sum_{m=1}^{M_t}\frac{(-1)^{w_{t,m}}(B_{t,m}-N_{t,m})}{N_{t,m}}.\]- Parameters
base_result (dict) – A dictionary of scores of all metrics of all tasks.
new_result (dict) – The same structure with
base_result
.weight (dict) – The same structure with
base_result
while each element is binary integer representing whether higher or lower score is better.
- Returns
The improvement between
new_result
andbase_result
.- Return type
float
Examples:
base_result = {'A': [96, 98], 'B': [0.2]} new_result = {'A': [93, 99], 'B': [0.5]} weight = {'A': [1, 0], 'B': [1]} print(count_improvement(base_result, new_result, weight))