rsp-ml


Namersp-ml JSON
Version 0.0.66 PyPI version JSON
download
home_pagehttps://github.com/SchulzR97/rsp-ml
SummaryMachine Learning
upload_time2024-11-15 12:23:47
maintainerNone
docs_urlNone
authorRobert Schulz
requires_pythonNone
licenseMIT
keywords python machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RSProduction MachineLearning

This project provides some usefull machine learning functionality.

# Table of Contents

- [1 metrics](#1-metrics)
  - [1.1 AUROC](#11-auroc)
  - [1.2 F1\_Score](#12-f1\_score)
  - [1.3 FN](#13-fn)
  - [1.4 FP](#14-fp)
  - [1.5 FPR](#15-fpr)
  - [1.6 ROC](#16-roc)
  - [1.7 TN](#17-tn)
  - [1.8 TP](#18-tp)
  - [1.9 TPR](#19-tpr)
  - [1.10 confusion\_matrix](#110-confusion\_matrix)
  - [1.11 plot\_ROC](#111-plot\_roc)
  - [1.12 plot\_confusion\_matrix](#112-plot\_confusion\_matrix)
  - [1.13 precision](#113-precision)
  - [1.14 recall](#114-recall)
  - [1.15 top\_10\_accuracy](#115-top\_10\_accuracy)
  - [1.16 top\_1\_accuracy](#116-top\_1\_accuracy)
  - [1.17 top\_2\_accuracy](#117-top\_2\_accuracy)
  - [1.18 top\_3\_accuracy](#118-top\_3\_accuracy)
  - [1.19 top\_5\_accuracy](#119-top\_5\_accuracy)
  - [1.20 top\_k\_accuracy](#120-top\_k\_accuracy)
- [2 model](#2-model)
  - [2.2 Constants](#22-constants)
  - [2.1 load\_model](#21-load\_model)
- [3 multi\_transforms](#3-multi\_transforms)
  - [3.1 BGR2GRAY : MultiTransform](#31-bgr2gray--multitransform)
    - [3.1.1 \_\_call\_\_](#311-\_\_call\_\_)
    - [3.1.2 \_\_init\_\_](#312-\_\_init\_\_)
  - [3.2 BGR2RGB : MultiTransform](#32-bgr2rgb--multitransform)
    - [3.2.1 \_\_call\_\_](#321-\_\_call\_\_)
    - [3.2.2 \_\_init\_\_](#322-\_\_init\_\_)
  - [3.3 Brightness : MultiTransform](#33-brightness--multitransform)
    - [3.3.1 \_\_call\_\_](#331-\_\_call\_\_)
    - [3.3.2 \_\_init\_\_](#332-\_\_init\_\_)
  - [3.4 CenterCrop : MultiTransform](#34-centercrop--multitransform)
    - [3.4.1 \_\_call\_\_](#341-\_\_call\_\_)
    - [3.4.2 \_\_init\_\_](#342-\_\_init\_\_)
  - [3.5 Color : MultiTransform](#35-color--multitransform)
    - [3.5.1 \_\_call\_\_](#351-\_\_call\_\_)
    - [3.5.2 \_\_init\_\_](#352-\_\_init\_\_)
  - [3.6 Compose : builtins.object](#36-compose--builtinsobject)
    - [3.6.1 \_\_call\_\_](#361-\_\_call\_\_)
    - [3.6.2 \_\_init\_\_](#362-\_\_init\_\_)
  - [3.7 GaussianNoise : MultiTransform](#37-gaussiannoise--multitransform)
    - [3.7.1 \_\_call\_\_](#371-\_\_call\_\_)
    - [3.7.2 \_\_init\_\_](#372-\_\_init\_\_)
  - [3.8 MultiTransform : builtins.object](#38-multitransform--builtinsobject)
    - [3.8.1 \_\_call\_\_](#381-\_\_call\_\_)
    - [3.8.2 \_\_init\_\_](#382-\_\_init\_\_)
  - [3.9 Normalize : MultiTransform](#39-normalize--multitransform)
    - [3.9.1 \_\_call\_\_](#391-\_\_call\_\_)
    - [3.9.2 \_\_init\_\_](#392-\_\_init\_\_)
  - [3.10 RGB2BGR : BGR2RGB](#310-rgb2bgr--bgr2rgb)
    - [3.10.1 \_\_call\_\_](#3101-\_\_call\_\_)
    - [3.10.2 \_\_init\_\_](#3102-\_\_init\_\_)
  - [3.11 RandomCrop : MultiTransform](#311-randomcrop--multitransform)
    - [3.11.1 \_\_call\_\_](#3111-\_\_call\_\_)
    - [3.11.2 \_\_init\_\_](#3112-\_\_init\_\_)
  - [3.12 RandomHorizontalFlip : MultiTransform](#312-randomhorizontalflip--multitransform)
    - [3.12.1 \_\_call\_\_](#3121-\_\_call\_\_)
    - [3.12.2 \_\_init\_\_](#3122-\_\_init\_\_)
  - [3.13 RandomVerticalFlip : MultiTransform](#313-randomverticalflip--multitransform)
    - [3.13.1 \_\_call\_\_](#3131-\_\_call\_\_)
    - [3.13.2 \_\_init\_\_](#3132-\_\_init\_\_)
  - [3.14 Resize : MultiTransform](#314-resize--multitransform)
    - [3.14.1 \_\_call\_\_](#3141-\_\_call\_\_)
    - [3.14.2 \_\_init\_\_](#3142-\_\_init\_\_)
  - [3.15 Rotate : MultiTransform](#315-rotate--multitransform)
    - [3.15.1 \_\_call\_\_](#3151-\_\_call\_\_)
    - [3.15.2 \_\_init\_\_](#3152-\_\_init\_\_)
  - [3.16 Satturation : MultiTransform](#316-satturation--multitransform)
    - [3.16.1 \_\_call\_\_](#3161-\_\_call\_\_)
    - [3.16.2 \_\_init\_\_](#3162-\_\_init\_\_)
  - [3.17 Scale : MultiTransform](#317-scale--multitransform)
    - [3.17.1 \_\_call\_\_](#3171-\_\_call\_\_)
    - [3.17.2 \_\_init\_\_](#3172-\_\_init\_\_)
  - [3.18 Stack : MultiTransform](#318-stack--multitransform)
    - [3.18.1 \_\_call\_\_](#3181-\_\_call\_\_)
    - [3.18.2 \_\_init\_\_](#3182-\_\_init\_\_)
  - [3.19 ToCVImage : MultiTransform](#319-tocvimage--multitransform)
    - [3.19.1 \_\_call\_\_](#3191-\_\_call\_\_)
    - [3.19.2 \_\_init\_\_](#3192-\_\_init\_\_)
  - [3.20 ToNumpy : MultiTransform](#320-tonumpy--multitransform)
    - [3.20.1 \_\_call\_\_](#3201-\_\_call\_\_)
    - [3.20.2 \_\_init\_\_](#3202-\_\_init\_\_)
  - [3.21 ToPILImage : MultiTransform](#321-topilimage--multitransform)
    - [3.21.1 \_\_call\_\_](#3211-\_\_call\_\_)
    - [3.21.2 \_\_init\_\_](#3212-\_\_init\_\_)
  - [3.22 ToTensor : MultiTransform](#322-totensor--multitransform)
    - [3.22.1 \_\_call\_\_](#3221-\_\_call\_\_)
    - [3.22.2 \_\_init\_\_](#3222-\_\_init\_\_)
- [4 run](#4-run)
  - [4.1 Run : builtins.object](#41-run--builtinsobject)
    - [4.1.1 \_\_init\_\_](#411-\_\_init\_\_)
    - [4.1.2 append](#412-append)
    - [4.1.3 get\_avg](#413-get\_avg)
    - [4.1.4 get\_val](#414-get\_val)
    - [4.1.5 len](#415-len)
    - [4.1.6 load\_best\_state\_dict](#416-load\_best\_state\_dict)
    - [4.1.7 load\_state\_dict](#417-load\_state\_dict)
    - [4.1.8 pickle\_dump](#418-pickle\_dump)
    - [4.1.9 pickle\_load](#419-pickle\_load)
    - [4.1.10 plot](#4110-plot)
    - [4.1.11 recalculate\_moving\_average](#4111-recalculate\_moving\_average)
    - [4.1.12 save](#4112-save)
    - [4.1.13 save\_best\_state\_dict](#4113-save\_best\_state\_dict)
    - [4.1.14 save\_state\_dict](#4114-save\_state\_dict)


# 1 metrics

[TOC](#table-of-contents)

The module `rsp.ml.metrics` provides some functionality to quantify the quality of predictions.

## 1.1 AUROC

[TOC](#table-of-contents)

**Description**

Calculates the Area under the Receiver Operation Chracteristic Curve.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| num_thresholds | int, default = 100 | Number of thresholds to compute. |

**Returns**

Receiver Operation Chracteristic Area under the Curve : float

## 1.2 F1\_Score

[TOC](#table-of-contents)

**Description**

F1 Score. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

F1 Score : float

**Equations**

$precision = \frac{TP}{TP + FP}$

$recall = \frac{TP}{TP + FN}$

$F_1 = \frac{2 \cdot precision \cdot recall}{precision + recall} = \frac{2 \cdot TP}{2 \cdot TP + FP + FN}$



**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

f1score = m.F1_Score(Y, T)

print(f1score) --> 0.5
```

## 1.3 FN

[TOC](#table-of-contents)

**Description**

False negatives. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

False negatives : int

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

fn = m.FN(Y, T)
print(fn) -> 1
```

## 1.4 FP

[TOC](#table-of-contents)

**Description**

False positives. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

False positives : int

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

fp = m.FP(Y, T)
print(fp) -> 1
```

## 1.5 FPR

[TOC](#table-of-contents)

**Description**

False positive rate. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

False positive rate : float

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

fpr = m.FPR(Y, T)
print(fpr) -> 0.08333333333333333
```

## 1.6 ROC

[TOC](#table-of-contents)

**Description**

Calculates the receiver operating characteristic: computes False Positive Rates and True positive Rates for `num_thresholds` aligned between 0 and 1

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| num_thresholds | int, default = 100 | Number of thresholds to compute. |

**Returns**

(False Positive Rates, True Positive Rates) for 100 different thresholds : (List[float], List[float])

**Example**

```python
import rsp.ml.metrics as m
import torch
import torch.nn.functional as F

num_elements = 100000
num_classes = 7

T = []
for i in range(num_elements):
  true_class = torch.randint(0, num_classes, (1,))
  t = F.one_hot(true_class, num_classes=num_classes)
  T.append(t)
T = torch.cat(T)

dist = torch.normal(T.float(), 1.5)
Y = F.softmax(dist, dim = 1)
FPRs, TPRs = m.ROC(Y, T)
```

## 1.7 TN

[TOC](#table-of-contents)

**Description**

True negatives. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

True negatives : int

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

tn = m.TN(Y, T)
print(tn) -> 11
```

## 1.8 TP

[TOC](#table-of-contents)

**Description**

True positives. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

True positives : int

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

tp = m.TP(Y, T)
print(tp) -> 5
```

## 1.9 TPR

[TOC](#table-of-contents)

**Description**

True positive rate. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

True positive rate : float

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

tpr = m.TPR(Y, T)
print(tpr) -> 0.8333333333333334
```

## 1.10 confusion\_matrix

[TOC](#table-of-contents)

**Description**

Calculates the confusion matrix. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Confusion matrix : torch.Tensor

**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

conf_mat = m.confusion_matrix(Y, T)
print(conf_mat) -> tensor([
  [1, 1, 0],
  [0, 2, 0],
  [0, 0, 2]
])
```

## 1.11 plot\_ROC

[TOC](#table-of-contents)

**Description**

Plot the receiver operating characteristic.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| num_thresholds | int, default = 100 | Number of thresholds to compute. |
| title | str, optional, default = 'Confusion Matrix' | Title of the plot |
| class_curves | bool, default = False | Plot ROC curve for each class |
| labels | str, optional, default = None | Class labels -> automatic labeling C000, ..., CXXX if labels is None |
| plt_show | bool, optional, default = False | Set to True to show the plot |
| save_file_name | str, optional, default = None | If not None, the plot is saved under the specified save_file_name. |

**Returns**

Image of the confusion matrix : np.array

![](documentation/image/ROC_AUC.jpg)
## 1.12 plot\_confusion\_matrix

[TOC](#table-of-contents)

**Description**

Plot the confusion matrix

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| confusion_matrix | torch.Tensor | Confusion matrix |
| labels | str, optional, default = None | Class labels -> automatic labeling C000, ..., CXXX if labels is None |
| cmap | str, optional, default = 'Blues' | Seaborn cmap, see https://r02b.github.io/seaborn_palettes/ |
| xlabel | str, optional, default = 'Predicted label' | X-Axis label |
| ylabel | str, optional, default = 'True label' | Y-Axis label |
| title | str, optional, default = 'Confusion Matrix' | Title of the plot |
| plt_show | bool, optional, default = False | Set to True to show the plot |
| save_file_name | str, optional, default = None | If not None, the plot is saved under the specified save_file_name. |

**Returns**

Image of the confusion matrix : np.array

![](documentation/image/confusion_matrix.jpg)
## 1.13 precision

[TOC](#table-of-contents)

**Description**

Precision. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

Precision : float

**Equations**

$precision = \frac{TP}{TP + FP}$



**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

precision = m.precision(Y, T)
print(precision) -> 0.8333333333333334
```

## 1.14 recall

[TOC](#table-of-contents)

**Description**

Recall. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |
| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |

**Returns**

Recall : float

**Equations**

$recall = \frac{TP}{TP + FN}$



**Example**

```python
import rsp.ml.metrics as m
import torch

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

recall = m.recall(Y, T)
print(recall) -> 0.8333333333333334
```

## 1.15 top\_10\_accuracy

[TOC](#table-of-contents)

**Description**

Top 10 accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top 10 accuracy -> top k accuracy | k = 10 : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_10_accuracy = m.top_10_accuracy(Y, T, k = 3)

print(top_10_accuracy) --> 1.0
```

## 1.16 top\_1\_accuracy

[TOC](#table-of-contents)

**Description**

Top 1 accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top 1 accuracy -> top k accuracy | k = 1 : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_1_accuracy = m.top_1_accuracy(Y, T, k = 3)

print(top_1_accuracy) --> 0.8333333333333334
```

## 1.17 top\_2\_accuracy

[TOC](#table-of-contents)

**Description**

Top 2 accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top 2 accuracy -> top k accuracy | k = 2 : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_2_accuracy = m.top_2_accuracy(Y, T, k = 3)

print(top_2_accuracy) --> 1.0
```

## 1.18 top\_3\_accuracy

[TOC](#table-of-contents)

**Description**

Top 3 accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top 3 accuracy -> top k accuracy | k = 3 : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_3_accuracy = m.top_3_accuracy(Y, T, k = 3)

print(top_3_accuracy) --> 1.0
```

## 1.19 top\_5\_accuracy

[TOC](#table-of-contents)

**Description**

Top 5 accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top 5 accuracy -> top k accuracy | k = 5 : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_5_accuracy = m.top_5_accuracy(Y, T, k = 3)

print(top_5_accuracy) --> 1.0
```

## 1.20 top\_k\_accuracy

[TOC](#table-of-contents)

**Description**

Top k accuracy. Expected input shape: (batch_size, num_classes)

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| Y | torch.Tensor | Prediction |
| T | torch.Tensor | True values |

**Returns**

Top k accuracy : float

**Example**

```python
import rsp.ml.metrics as m

Y = torch.tensor([
  [0.1, 0.1, 0.8],
  [0.03, 0.95, 0.02],
  [0.05, 0.9, 0.05],
  [0.01, 0.87, 0.12],
  [0.04, 0.03, 0.93],
  [0.94, 0.02, 0.06]
])
T = torch.tensor([
  [0, 0, 1],
  [1, 0, 0],
  [0, 1, 0],
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]
])

top_k_accuracy = m.top_k_accuracy(Y, T, k = 3)

print(top_k_accuracy) --> 1.0
```

# 2 model

[TOC](#table-of-contents)

The module `rsp.ml.model` provides some usefull functionality to store and load pytorch models.

## 2.2 Constants

[TOC](#table-of-contents)

| Name | Value | Description |
| -----|-------|------------ |
| TUC_ActionPrediction_model004 | TUC/ActionPrediction/Model4 | **TUC Action prediction model 4**<br>CNN with Multihead-Self-Attention<br>**Input**<br>- batch size<br>- sequence length = 30<br>- channels = 3<br>- width = 200<br>- height = 200<br>**Output**<br>- batch size<br>- number of classes = 10 |
| TUC_ActionPrediction_model005 | TUC/ActionPrediction/Model5 | **TUC Action prediction model 5**<br>CNN with Multihead-Self-Attention<br>**Input**<br>- batch size<br>- sequence length = 30<br>- channels = 3<br>- width = 300<br>- height = 300<br>**Output**<br>- batch size<br>- number of classes = 10 |
| URL | https://drive.google.com/drive/folders/1ulNnPqg-5wvenRl2CuJMxMMcaiYfHjQ9?usp=share_link | Google Drive URL |


## 2.1 load\_model

[TOC](#table-of-contents)

**Description**

Loads a model from an pretrained PyTorch external source into memory.

> See Constants for available models

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| model_id | str | ID of the model |
| force_reload | bool | Overwrite local file -> forces downlad. |

**Returns**

Pretrained PyTorch model : torch.nn.Module

**Example**

```python
import rsp.ml.model as model

model004 = model.load_model(model.TUC_ActionPrediction_model004)
```

# 3 multi\_transforms

[TOC](#table-of-contents)

The module `rsp.ml.multi_transforms` is based on `torchvision.transforms`, which is made for single images. `rsp.ml.multi_transforms` extends this functionality by providing transformations for sequences of images, which could be usefull for video augmentation.

## 3.1 BGR2GRAY : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts a sequence of BGR images to grayscale images.


### 3.1.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.1.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.2 BGR2RGB : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts sequence of BGR images to RGB images.


### 3.2.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.2.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.3 Brightness : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.3.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.3.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.4 CenterCrop : MultiTransform

[TOC](#table-of-contents)

**Description**

Crops Images at the center after upscaling them. Dimensions kept the same.

![](documentation/image/multi_transforms.CenterCrop.png)


### 3.4.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.4.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| max_scale | float | Images are scaled randomly between 1. and max_scale before cropping to original size. |
## 3.5 Color : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.5.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.5.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.6 Compose : builtins.object

[TOC](#table-of-contents)

**Description**

Composes several MultiTransforms together.

**Example**

```python
import rsp.ml.multi_transforms as t

transforms = t.Compose([
  t.BGR2GRAY(),
  t.Scale(0.5)
])
```
### 3.6.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

### 3.6.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| children | List[MultiTransform] | List of MultiTransforms to compose. |
## 3.7 GaussianNoise : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.7.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.7.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.8 MultiTransform : builtins.object

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.8.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.8.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.9 Normalize : MultiTransform

[TOC](#table-of-contents)

**Description**

Normalize images with mean and standard deviation. Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for n channels, this transform will normalize each channel of the input torch.*Tensor i.e., output[channel] = (input[channel] - mean[channel]) / std[channel]

> Based on torchvision.transforms.Normalize


### 3.9.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.9.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| mean | List[float] | Sequence of means for each channel. |
| std | List[float] | Sequence of standard deviations for each channel. |
| inplace | bool | Set to True make this operation in-place. |
## 3.10 RGB2BGR : BGR2RGB

[TOC](#table-of-contents)

**Description**

Converts sequence of RGB images to BGR images.


### 3.10.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.10.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.11 RandomCrop : MultiTransform

[TOC](#table-of-contents)

**Description**

Crops Images at a random location after upscaling them. Dimensions kept the same.

![](documentation/image/multi_transforms.RandomCrop.png)


### 3.11.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.11.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| max_scale | float | Images are scaled randomly between 1. and max_scale before cropping to original size. |
## 3.12 RandomHorizontalFlip : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.12.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.12.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.13 RandomVerticalFlip : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.13.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.13.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.14 Resize : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.14.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.14.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.15 Rotate : MultiTransform

[TOC](#table-of-contents)

**Description**

Randomly rotates images.

**Equations**

$angle = -max\_angle + 2 \cdot random() \cdot max\_angle$

![](documentation/image/multi_transforms.Rotate.png)


### 3.15.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.15.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Iitializes a new instance.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| max_angle | float | Maximal rotation in degrees | -max_angle <= rotate <= max_angle |
| auto_scale | bool, default = True | Image will be resized when auto scale is activated to avoid black margins. |
## 3.16 Satturation : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.16.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.16.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.17 Scale : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.17.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.17.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.18 Stack : MultiTransform

[TOC](#table-of-contents)

**Description**

MultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.

> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.


### 3.18.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.18.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.19 ToCVImage : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts a `torch.Tensor`to Open CV image by changing dimensions (d0, d1, d2) -> (d1, d2, d0) and converting `torch.Tensor` to `numpy`.


### 3.19.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.19.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.20 ToNumpy : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts a `torch.Tensor`to `numpy`


### 3.20.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.20.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.21 ToPILImage : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts sequence of images to sequence of `PIL.Image`.


### 3.21.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.21.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

## 3.22 ToTensor : MultiTransform

[TOC](#table-of-contents)

**Description**

Converts a sequence of images to torch.Tensor.


### 3.22.1 \_\_call\_\_

[TOC](#table-of-contents)

**Description**

Call self as a function.

**Parameters**

| Name | Type | Description |
|------|------|-------------|
| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |
### 3.22.2 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initializes a new instance.

# 4 run

[TOC](#table-of-contents)

The module `rsp.ml.run` provides some tools for storing, loading and visualizing data during training of models using PyTorch. 

## 4.1 Run : builtins.object

[TOC](#table-of-contents)


### 4.1.1 \_\_init\_\_

[TOC](#table-of-contents)

**Description**

Initialize self.  See help(type(self)) for accurate signature.

### 4.1.2 append

[TOC](#table-of-contents)

### 4.1.3 get\_avg

[TOC](#table-of-contents)

### 4.1.4 get\_val

[TOC](#table-of-contents)

### 4.1.5 len

[TOC](#table-of-contents)

### 4.1.6 load\_best\_state\_dict

[TOC](#table-of-contents)

### 4.1.7 load\_state\_dict

[TOC](#table-of-contents)

### 4.1.8 pickle\_dump

[TOC](#table-of-contents)

### 4.1.9 pickle\_load

[TOC](#table-of-contents)

### 4.1.10 plot

[TOC](#table-of-contents)

### 4.1.11 recalculate\_moving\_average

[TOC](#table-of-contents)

### 4.1.12 save

[TOC](#table-of-contents)

### 4.1.13 save\_best\_state\_dict

[TOC](#table-of-contents)

### 4.1.14 save\_state\_dict

[TOC](#table-of-contents)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SchulzR97/rsp-ml",
    "name": "rsp-ml",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, Machine Learning",
    "author": "Robert Schulz",
    "author_email": "schulzr256@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ad/8c/e4013233c7e28924927134dcc804b106ad767974b2c63724cc6fa944d165/rsp_ml-0.0.66.tar.gz",
    "platform": null,
    "description": "# RSProduction MachineLearning\n\nThis project provides some usefull machine learning functionality.\n\n# Table of Contents\n\n- [1 metrics](#1-metrics)\n  - [1.1 AUROC](#11-auroc)\n  - [1.2 F1\\_Score](#12-f1\\_score)\n  - [1.3 FN](#13-fn)\n  - [1.4 FP](#14-fp)\n  - [1.5 FPR](#15-fpr)\n  - [1.6 ROC](#16-roc)\n  - [1.7 TN](#17-tn)\n  - [1.8 TP](#18-tp)\n  - [1.9 TPR](#19-tpr)\n  - [1.10 confusion\\_matrix](#110-confusion\\_matrix)\n  - [1.11 plot\\_ROC](#111-plot\\_roc)\n  - [1.12 plot\\_confusion\\_matrix](#112-plot\\_confusion\\_matrix)\n  - [1.13 precision](#113-precision)\n  - [1.14 recall](#114-recall)\n  - [1.15 top\\_10\\_accuracy](#115-top\\_10\\_accuracy)\n  - [1.16 top\\_1\\_accuracy](#116-top\\_1\\_accuracy)\n  - [1.17 top\\_2\\_accuracy](#117-top\\_2\\_accuracy)\n  - [1.18 top\\_3\\_accuracy](#118-top\\_3\\_accuracy)\n  - [1.19 top\\_5\\_accuracy](#119-top\\_5\\_accuracy)\n  - [1.20 top\\_k\\_accuracy](#120-top\\_k\\_accuracy)\n- [2 model](#2-model)\n  - [2.2 Constants](#22-constants)\n  - [2.1 load\\_model](#21-load\\_model)\n- [3 multi\\_transforms](#3-multi\\_transforms)\n  - [3.1 BGR2GRAY : MultiTransform](#31-bgr2gray--multitransform)\n    - [3.1.1 \\_\\_call\\_\\_](#311-\\_\\_call\\_\\_)\n    - [3.1.2 \\_\\_init\\_\\_](#312-\\_\\_init\\_\\_)\n  - [3.2 BGR2RGB : MultiTransform](#32-bgr2rgb--multitransform)\n    - [3.2.1 \\_\\_call\\_\\_](#321-\\_\\_call\\_\\_)\n    - [3.2.2 \\_\\_init\\_\\_](#322-\\_\\_init\\_\\_)\n  - [3.3 Brightness : MultiTransform](#33-brightness--multitransform)\n    - [3.3.1 \\_\\_call\\_\\_](#331-\\_\\_call\\_\\_)\n    - [3.3.2 \\_\\_init\\_\\_](#332-\\_\\_init\\_\\_)\n  - [3.4 CenterCrop : MultiTransform](#34-centercrop--multitransform)\n    - [3.4.1 \\_\\_call\\_\\_](#341-\\_\\_call\\_\\_)\n    - [3.4.2 \\_\\_init\\_\\_](#342-\\_\\_init\\_\\_)\n  - [3.5 Color : MultiTransform](#35-color--multitransform)\n    - [3.5.1 \\_\\_call\\_\\_](#351-\\_\\_call\\_\\_)\n    - [3.5.2 \\_\\_init\\_\\_](#352-\\_\\_init\\_\\_)\n  - [3.6 Compose : builtins.object](#36-compose--builtinsobject)\n    - [3.6.1 \\_\\_call\\_\\_](#361-\\_\\_call\\_\\_)\n    - [3.6.2 \\_\\_init\\_\\_](#362-\\_\\_init\\_\\_)\n  - [3.7 GaussianNoise : MultiTransform](#37-gaussiannoise--multitransform)\n    - [3.7.1 \\_\\_call\\_\\_](#371-\\_\\_call\\_\\_)\n    - [3.7.2 \\_\\_init\\_\\_](#372-\\_\\_init\\_\\_)\n  - [3.8 MultiTransform : builtins.object](#38-multitransform--builtinsobject)\n    - [3.8.1 \\_\\_call\\_\\_](#381-\\_\\_call\\_\\_)\n    - [3.8.2 \\_\\_init\\_\\_](#382-\\_\\_init\\_\\_)\n  - [3.9 Normalize : MultiTransform](#39-normalize--multitransform)\n    - [3.9.1 \\_\\_call\\_\\_](#391-\\_\\_call\\_\\_)\n    - [3.9.2 \\_\\_init\\_\\_](#392-\\_\\_init\\_\\_)\n  - [3.10 RGB2BGR : BGR2RGB](#310-rgb2bgr--bgr2rgb)\n    - [3.10.1 \\_\\_call\\_\\_](#3101-\\_\\_call\\_\\_)\n    - [3.10.2 \\_\\_init\\_\\_](#3102-\\_\\_init\\_\\_)\n  - [3.11 RandomCrop : MultiTransform](#311-randomcrop--multitransform)\n    - [3.11.1 \\_\\_call\\_\\_](#3111-\\_\\_call\\_\\_)\n    - [3.11.2 \\_\\_init\\_\\_](#3112-\\_\\_init\\_\\_)\n  - [3.12 RandomHorizontalFlip : MultiTransform](#312-randomhorizontalflip--multitransform)\n    - [3.12.1 \\_\\_call\\_\\_](#3121-\\_\\_call\\_\\_)\n    - [3.12.2 \\_\\_init\\_\\_](#3122-\\_\\_init\\_\\_)\n  - [3.13 RandomVerticalFlip : MultiTransform](#313-randomverticalflip--multitransform)\n    - [3.13.1 \\_\\_call\\_\\_](#3131-\\_\\_call\\_\\_)\n    - [3.13.2 \\_\\_init\\_\\_](#3132-\\_\\_init\\_\\_)\n  - [3.14 Resize : MultiTransform](#314-resize--multitransform)\n    - [3.14.1 \\_\\_call\\_\\_](#3141-\\_\\_call\\_\\_)\n    - [3.14.2 \\_\\_init\\_\\_](#3142-\\_\\_init\\_\\_)\n  - [3.15 Rotate : MultiTransform](#315-rotate--multitransform)\n    - [3.15.1 \\_\\_call\\_\\_](#3151-\\_\\_call\\_\\_)\n    - [3.15.2 \\_\\_init\\_\\_](#3152-\\_\\_init\\_\\_)\n  - [3.16 Satturation : MultiTransform](#316-satturation--multitransform)\n    - [3.16.1 \\_\\_call\\_\\_](#3161-\\_\\_call\\_\\_)\n    - [3.16.2 \\_\\_init\\_\\_](#3162-\\_\\_init\\_\\_)\n  - [3.17 Scale : MultiTransform](#317-scale--multitransform)\n    - [3.17.1 \\_\\_call\\_\\_](#3171-\\_\\_call\\_\\_)\n    - [3.17.2 \\_\\_init\\_\\_](#3172-\\_\\_init\\_\\_)\n  - [3.18 Stack : MultiTransform](#318-stack--multitransform)\n    - [3.18.1 \\_\\_call\\_\\_](#3181-\\_\\_call\\_\\_)\n    - [3.18.2 \\_\\_init\\_\\_](#3182-\\_\\_init\\_\\_)\n  - [3.19 ToCVImage : MultiTransform](#319-tocvimage--multitransform)\n    - [3.19.1 \\_\\_call\\_\\_](#3191-\\_\\_call\\_\\_)\n    - [3.19.2 \\_\\_init\\_\\_](#3192-\\_\\_init\\_\\_)\n  - [3.20 ToNumpy : MultiTransform](#320-tonumpy--multitransform)\n    - [3.20.1 \\_\\_call\\_\\_](#3201-\\_\\_call\\_\\_)\n    - [3.20.2 \\_\\_init\\_\\_](#3202-\\_\\_init\\_\\_)\n  - [3.21 ToPILImage : MultiTransform](#321-topilimage--multitransform)\n    - [3.21.1 \\_\\_call\\_\\_](#3211-\\_\\_call\\_\\_)\n    - [3.21.2 \\_\\_init\\_\\_](#3212-\\_\\_init\\_\\_)\n  - [3.22 ToTensor : MultiTransform](#322-totensor--multitransform)\n    - [3.22.1 \\_\\_call\\_\\_](#3221-\\_\\_call\\_\\_)\n    - [3.22.2 \\_\\_init\\_\\_](#3222-\\_\\_init\\_\\_)\n- [4 run](#4-run)\n  - [4.1 Run : builtins.object](#41-run--builtinsobject)\n    - [4.1.1 \\_\\_init\\_\\_](#411-\\_\\_init\\_\\_)\n    - [4.1.2 append](#412-append)\n    - [4.1.3 get\\_avg](#413-get\\_avg)\n    - [4.1.4 get\\_val](#414-get\\_val)\n    - [4.1.5 len](#415-len)\n    - [4.1.6 load\\_best\\_state\\_dict](#416-load\\_best\\_state\\_dict)\n    - [4.1.7 load\\_state\\_dict](#417-load\\_state\\_dict)\n    - [4.1.8 pickle\\_dump](#418-pickle\\_dump)\n    - [4.1.9 pickle\\_load](#419-pickle\\_load)\n    - [4.1.10 plot](#4110-plot)\n    - [4.1.11 recalculate\\_moving\\_average](#4111-recalculate\\_moving\\_average)\n    - [4.1.12 save](#4112-save)\n    - [4.1.13 save\\_best\\_state\\_dict](#4113-save\\_best\\_state\\_dict)\n    - [4.1.14 save\\_state\\_dict](#4114-save\\_state\\_dict)\n\n\n# 1 metrics\n\n[TOC](#table-of-contents)\n\nThe module `rsp.ml.metrics` provides some functionality to quantify the quality of predictions.\n\n## 1.1 AUROC\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCalculates the Area under the Receiver Operation Chracteristic Curve.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| num_thresholds | int, default = 100 | Number of thresholds to compute. |\n\n**Returns**\n\nReceiver Operation Chracteristic Area under the Curve : float\n\n## 1.2 F1\\_Score\n\n[TOC](#table-of-contents)\n\n**Description**\n\nF1 Score. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nF1 Score : float\n\n**Equations**\n\n$precision = \\frac{TP}{TP + FP}$\n\n$recall = \\frac{TP}{TP + FN}$\n\n$F_1 = \\frac{2 \\cdot precision \\cdot recall}{precision + recall} = \\frac{2 \\cdot TP}{2 \\cdot TP + FP + FN}$\n\n\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nf1score = m.F1_Score(Y, T)\n\nprint(f1score) --> 0.5\n```\n\n## 1.3 FN\n\n[TOC](#table-of-contents)\n\n**Description**\n\nFalse negatives. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nFalse negatives : int\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nfn = m.FN(Y, T)\nprint(fn) -> 1\n```\n\n## 1.4 FP\n\n[TOC](#table-of-contents)\n\n**Description**\n\nFalse positives. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nFalse positives : int\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nfp = m.FP(Y, T)\nprint(fp) -> 1\n```\n\n## 1.5 FPR\n\n[TOC](#table-of-contents)\n\n**Description**\n\nFalse positive rate. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nFalse positive rate : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nfpr = m.FPR(Y, T)\nprint(fpr) -> 0.08333333333333333\n```\n\n## 1.6 ROC\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCalculates the receiver operating characteristic: computes False Positive Rates and True positive Rates for `num_thresholds` aligned between 0 and 1\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| num_thresholds | int, default = 100 | Number of thresholds to compute. |\n\n**Returns**\n\n(False Positive Rates, True Positive Rates) for 100 different thresholds : (List[float], List[float])\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\nimport torch.nn.functional as F\n\nnum_elements = 100000\nnum_classes = 7\n\nT = []\nfor i in range(num_elements):\n  true_class = torch.randint(0, num_classes, (1,))\n  t = F.one_hot(true_class, num_classes=num_classes)\n  T.append(t)\nT = torch.cat(T)\n\ndist = torch.normal(T.float(), 1.5)\nY = F.softmax(dist, dim = 1)\nFPRs, TPRs = m.ROC(Y, T)\n```\n\n## 1.7 TN\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTrue negatives. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nTrue negatives : int\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntn = m.TN(Y, T)\nprint(tn) -> 11\n```\n\n## 1.8 TP\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTrue positives. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nTrue positives : int\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntp = m.TP(Y, T)\nprint(tp) -> 5\n```\n\n## 1.9 TPR\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTrue positive rate. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nTrue positive rate : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntpr = m.TPR(Y, T)\nprint(tpr) -> 0.8333333333333334\n```\n\n## 1.10 confusion\\_matrix\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCalculates the confusion matrix. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nConfusion matrix : torch.Tensor\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nconf_mat = m.confusion_matrix(Y, T)\nprint(conf_mat) -> tensor([\n  [1, 1, 0],\n  [0, 2, 0],\n  [0, 0, 2]\n])\n```\n\n## 1.11 plot\\_ROC\n\n[TOC](#table-of-contents)\n\n**Description**\n\nPlot the receiver operating characteristic.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| num_thresholds | int, default = 100 | Number of thresholds to compute. |\n| title | str, optional, default = 'Confusion Matrix' | Title of the plot |\n| class_curves | bool, default = False | Plot ROC curve for each class |\n| labels | str, optional, default = None | Class labels -> automatic labeling C000, ..., CXXX if labels is None |\n| plt_show | bool, optional, default = False | Set to True to show the plot |\n| save_file_name | str, optional, default = None | If not None, the plot is saved under the specified save_file_name. |\n\n**Returns**\n\nImage of the confusion matrix : np.array\n\n![](documentation/image/ROC_AUC.jpg)\n## 1.12 plot\\_confusion\\_matrix\n\n[TOC](#table-of-contents)\n\n**Description**\n\nPlot the confusion matrix\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| confusion_matrix | torch.Tensor | Confusion matrix |\n| labels | str, optional, default = None | Class labels -> automatic labeling C000, ..., CXXX if labels is None |\n| cmap | str, optional, default = 'Blues' | Seaborn cmap, see https://r02b.github.io/seaborn_palettes/ |\n| xlabel | str, optional, default = 'Predicted label' | X-Axis label |\n| ylabel | str, optional, default = 'True label' | Y-Axis label |\n| title | str, optional, default = 'Confusion Matrix' | Title of the plot |\n| plt_show | bool, optional, default = False | Set to True to show the plot |\n| save_file_name | str, optional, default = None | If not None, the plot is saved under the specified save_file_name. |\n\n**Returns**\n\nImage of the confusion matrix : np.array\n\n![](documentation/image/confusion_matrix.jpg)\n## 1.13 precision\n\n[TOC](#table-of-contents)\n\n**Description**\n\nPrecision. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nPrecision : float\n\n**Equations**\n\n$precision = \\frac{TP}{TP + FP}$\n\n\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nprecision = m.precision(Y, T)\nprint(precision) -> 0.8333333333333334\n```\n\n## 1.14 recall\n\n[TOC](#table-of-contents)\n\n**Description**\n\nRecall. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n| threshold | float | All values that are greater than or equal to the threshold are considered a positive class. |\n\n**Returns**\n\nRecall : float\n\n**Equations**\n\n$recall = \\frac{TP}{TP + FN}$\n\n\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\nimport torch\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\nrecall = m.recall(Y, T)\nprint(recall) -> 0.8333333333333334\n```\n\n## 1.15 top\\_10\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop 10 accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop 10 accuracy -> top k accuracy | k = 10 : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_10_accuracy = m.top_10_accuracy(Y, T, k = 3)\n\nprint(top_10_accuracy) --> 1.0\n```\n\n## 1.16 top\\_1\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop 1 accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop 1 accuracy -> top k accuracy | k = 1 : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_1_accuracy = m.top_1_accuracy(Y, T, k = 3)\n\nprint(top_1_accuracy) --> 0.8333333333333334\n```\n\n## 1.17 top\\_2\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop 2 accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop 2 accuracy -> top k accuracy | k = 2 : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_2_accuracy = m.top_2_accuracy(Y, T, k = 3)\n\nprint(top_2_accuracy) --> 1.0\n```\n\n## 1.18 top\\_3\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop 3 accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop 3 accuracy -> top k accuracy | k = 3 : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_3_accuracy = m.top_3_accuracy(Y, T, k = 3)\n\nprint(top_3_accuracy) --> 1.0\n```\n\n## 1.19 top\\_5\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop 5 accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop 5 accuracy -> top k accuracy | k = 5 : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_5_accuracy = m.top_5_accuracy(Y, T, k = 3)\n\nprint(top_5_accuracy) --> 1.0\n```\n\n## 1.20 top\\_k\\_accuracy\n\n[TOC](#table-of-contents)\n\n**Description**\n\nTop k accuracy. Expected input shape: (batch_size, num_classes)\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| Y | torch.Tensor | Prediction |\n| T | torch.Tensor | True values |\n\n**Returns**\n\nTop k accuracy : float\n\n**Example**\n\n```python\nimport rsp.ml.metrics as m\n\nY = torch.tensor([\n  [0.1, 0.1, 0.8],\n  [0.03, 0.95, 0.02],\n  [0.05, 0.9, 0.05],\n  [0.01, 0.87, 0.12],\n  [0.04, 0.03, 0.93],\n  [0.94, 0.02, 0.06]\n])\nT = torch.tensor([\n  [0, 0, 1],\n  [1, 0, 0],\n  [0, 1, 0],\n  [0, 1, 0],\n  [0, 0, 1],\n  [1, 0, 0]\n])\n\ntop_k_accuracy = m.top_k_accuracy(Y, T, k = 3)\n\nprint(top_k_accuracy) --> 1.0\n```\n\n# 2 model\n\n[TOC](#table-of-contents)\n\nThe module `rsp.ml.model` provides some usefull functionality to store and load pytorch models.\n\n## 2.2 Constants\n\n[TOC](#table-of-contents)\n\n| Name | Value | Description |\n| -----|-------|------------ |\n| TUC_ActionPrediction_model004 | TUC/ActionPrediction/Model4 | **TUC Action prediction model 4**<br>CNN with Multihead-Self-Attention<br>**Input**<br>- batch size<br>- sequence length = 30<br>- channels = 3<br>- width = 200<br>- height = 200<br>**Output**<br>- batch size<br>- number of classes = 10 |\n| TUC_ActionPrediction_model005 | TUC/ActionPrediction/Model5 | **TUC Action prediction model 5**<br>CNN with Multihead-Self-Attention<br>**Input**<br>- batch size<br>- sequence length = 30<br>- channels = 3<br>- width = 300<br>- height = 300<br>**Output**<br>- batch size<br>- number of classes = 10 |\n| URL | https://drive.google.com/drive/folders/1ulNnPqg-5wvenRl2CuJMxMMcaiYfHjQ9?usp=share_link | Google Drive URL |\n\n\n## 2.1 load\\_model\n\n[TOC](#table-of-contents)\n\n**Description**\n\nLoads a model from an pretrained PyTorch external source into memory.\n\n> See Constants for available models\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| model_id | str | ID of the model |\n| force_reload | bool | Overwrite local file -> forces downlad. |\n\n**Returns**\n\nPretrained PyTorch model : torch.nn.Module\n\n**Example**\n\n```python\nimport rsp.ml.model as model\n\nmodel004 = model.load_model(model.TUC_ActionPrediction_model004)\n```\n\n# 3 multi\\_transforms\n\n[TOC](#table-of-contents)\n\nThe module `rsp.ml.multi_transforms` is based on `torchvision.transforms`, which is made for single images. `rsp.ml.multi_transforms` extends this functionality by providing transformations for sequences of images, which could be usefull for video augmentation.\n\n## 3.1 BGR2GRAY : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts a sequence of BGR images to grayscale images.\n\n\n### 3.1.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.1.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.2 BGR2RGB : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts sequence of BGR images to RGB images.\n\n\n### 3.2.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.2.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.3 Brightness : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.3.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.3.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.4 CenterCrop : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCrops Images at the center after upscaling them. Dimensions kept the same.\n\n![](documentation/image/multi_transforms.CenterCrop.png)\n\n\n### 3.4.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.4.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| max_scale | float | Images are scaled randomly between 1. and max_scale before cropping to original size. |\n## 3.5 Color : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.5.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.5.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.6 Compose : builtins.object\n\n[TOC](#table-of-contents)\n\n**Description**\n\nComposes several MultiTransforms together.\n\n**Example**\n\n```python\nimport rsp.ml.multi_transforms as t\n\ntransforms = t.Compose([\n  t.BGR2GRAY(),\n  t.Scale(0.5)\n])\n```\n### 3.6.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n### 3.6.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| children | List[MultiTransform] | List of MultiTransforms to compose. |\n## 3.7 GaussianNoise : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.7.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.7.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.8 MultiTransform : builtins.object\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.8.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.8.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.9 Normalize : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nNormalize images with mean and standard deviation. Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for n channels, this transform will normalize each channel of the input torch.*Tensor i.e., output[channel] = (input[channel] - mean[channel]) / std[channel]\n\n> Based on torchvision.transforms.Normalize\n\n\n### 3.9.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.9.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| mean | List[float] | Sequence of means for each channel. |\n| std | List[float] | Sequence of standard deviations for each channel. |\n| inplace | bool | Set to True make this operation in-place. |\n## 3.10 RGB2BGR : BGR2RGB\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts sequence of RGB images to BGR images.\n\n\n### 3.10.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.10.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.11 RandomCrop : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCrops Images at a random location after upscaling them. Dimensions kept the same.\n\n![](documentation/image/multi_transforms.RandomCrop.png)\n\n\n### 3.11.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.11.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| max_scale | float | Images are scaled randomly between 1. and max_scale before cropping to original size. |\n## 3.12 RandomHorizontalFlip : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.12.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.12.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.13 RandomVerticalFlip : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.13.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.13.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.14 Resize : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.14.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.14.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.15 Rotate : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nRandomly rotates images.\n\n**Equations**\n\n$angle = -max\\_angle + 2 \\cdot random() \\cdot max\\_angle$\n\n![](documentation/image/multi_transforms.Rotate.png)\n\n\n### 3.15.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.15.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nIitializes a new instance.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| max_angle | float | Maximal rotation in degrees | -max_angle <= rotate <= max_angle |\n| auto_scale | bool, default = True | Image will be resized when auto scale is activated to avoid black margins. |\n## 3.16 Satturation : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.16.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.16.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.17 Scale : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.17.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.17.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.18 Stack : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nMultiTransform is an extension to keep the same transformation over a sequence of images instead of initializing a new transformation for every single image. It is inspired by `torchvision.transforms` and could be used for video augmentation. Use `rsp.ml.multi_transforms.Compose`to combine multiple image sequence transformations.\n\n> **Note** `rsp.ml.multi_transforms.MultiTransform` is a base class and should be inherited.\n\n\n### 3.18.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.18.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.19 ToCVImage : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts a `torch.Tensor`to Open CV image by changing dimensions (d0, d1, d2) -> (d1, d2, d0) and converting `torch.Tensor` to `numpy`.\n\n\n### 3.19.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.19.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.20 ToNumpy : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts a `torch.Tensor`to `numpy`\n\n\n### 3.20.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.20.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.21 ToPILImage : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts sequence of images to sequence of `PIL.Image`.\n\n\n### 3.21.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.21.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n## 3.22 ToTensor : MultiTransform\n\n[TOC](#table-of-contents)\n\n**Description**\n\nConverts a sequence of images to torch.Tensor.\n\n\n### 3.22.1 \\_\\_call\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nCall self as a function.\n\n**Parameters**\n\n| Name | Type | Description |\n|------|------|-------------|\n| input | torch.Tensor<br>List[PIL.Image]<br>List[numpy.array] | Sequence of images |\n### 3.22.2 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitializes a new instance.\n\n# 4 run\n\n[TOC](#table-of-contents)\n\nThe module `rsp.ml.run` provides some tools for storing, loading and visualizing data during training of models using PyTorch. \n\n## 4.1 Run : builtins.object\n\n[TOC](#table-of-contents)\n\n\n### 4.1.1 \\_\\_init\\_\\_\n\n[TOC](#table-of-contents)\n\n**Description**\n\nInitialize self.  See help(type(self)) for accurate signature.\n\n### 4.1.2 append\n\n[TOC](#table-of-contents)\n\n### 4.1.3 get\\_avg\n\n[TOC](#table-of-contents)\n\n### 4.1.4 get\\_val\n\n[TOC](#table-of-contents)\n\n### 4.1.5 len\n\n[TOC](#table-of-contents)\n\n### 4.1.6 load\\_best\\_state\\_dict\n\n[TOC](#table-of-contents)\n\n### 4.1.7 load\\_state\\_dict\n\n[TOC](#table-of-contents)\n\n### 4.1.8 pickle\\_dump\n\n[TOC](#table-of-contents)\n\n### 4.1.9 pickle\\_load\n\n[TOC](#table-of-contents)\n\n### 4.1.10 plot\n\n[TOC](#table-of-contents)\n\n### 4.1.11 recalculate\\_moving\\_average\n\n[TOC](#table-of-contents)\n\n### 4.1.12 save\n\n[TOC](#table-of-contents)\n\n### 4.1.13 save\\_best\\_state\\_dict\n\n[TOC](#table-of-contents)\n\n### 4.1.14 save\\_state\\_dict\n\n[TOC](#table-of-contents)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Machine Learning",
    "version": "0.0.66",
    "project_urls": {
        "Homepage": "https://github.com/SchulzR97/rsp-ml"
    },
    "split_keywords": [
        "python",
        " machine learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3bfe737d8aca155f39e792a67a3fd92e89496ce53410cbf1e7bc5ba7ad2fc40a",
                "md5": "395e8c283b6b73771c68f341c8347dc9",
                "sha256": "f9540aee9992da8cce6bc00a5d9924db16045069049b22b24e70a603f0e618ae"
            },
            "downloads": -1,
            "filename": "rsp_ml-0.0.66-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "395e8c283b6b73771c68f341c8347dc9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 20233,
            "upload_time": "2024-11-15T12:23:43",
            "upload_time_iso_8601": "2024-11-15T12:23:43.614651Z",
            "url": "https://files.pythonhosted.org/packages/3b/fe/737d8aca155f39e792a67a3fd92e89496ce53410cbf1e7bc5ba7ad2fc40a/rsp_ml-0.0.66-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad8ce4013233c7e28924927134dcc804b106ad767974b2c63724cc6fa944d165",
                "md5": "18397c843ccd3794c0ed8e609a4cc8f2",
                "sha256": "8ad3248e1353c0fc8fb67263147993abdf5c7475840770e70e967273a635b019"
            },
            "downloads": -1,
            "filename": "rsp_ml-0.0.66.tar.gz",
            "has_sig": false,
            "md5_digest": "18397c843ccd3794c0ed8e609a4cc8f2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29086,
            "upload_time": "2024-11-15T12:23:47",
            "upload_time_iso_8601": "2024-11-15T12:23:47.878569Z",
            "url": "https://files.pythonhosted.org/packages/ad/8c/e4013233c7e28924927134dcc804b106ad767974b2c63724cc6fa944d165/rsp_ml-0.0.66.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-15 12:23:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SchulzR97",
    "github_project": "rsp-ml",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rsp-ml"
}
        
Elapsed time: 1.22497s