Machine Learning
Project description
Table of Contents
- 1 metrics
- 2 model
- 3 multi_transforms
- 3.1 BGR2GRAY
- 3.2 BGR2RGB
- 3.3 Brightness
- 3.4 CenterCrop
- 3.5 Color
- 3.6 Compose
- 3.7 GaussianNoise
- 3.8 MultiTransform
- 3.9 Normalize
- 3.10 RGB2BGR
- 3.11 RandomCrop
- 3.12 RandomHorizontalFlip
- 3.13 RandomVerticalFlip
- 3.14 Resize
- 3.15 Rotate
- 3.16 Satturation
- 3.17 Scale
- 3.18 Stack
- 3.19 ToCVImage
- 3.20 ToNumpy
- 3.21 ToPILImage
- 3.22 ToTensor
- 4 run
1 metrics
1.1 F1_Score
Description
F1 Score. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
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
import rsp.ml.metrics as m
Y = torch.tensor([
[0.87, 0.01, 0.05, 0.07],
[0.02, 0.09, 0.86, 0.03]
])
T = torch.tensor([
[1., 0., 0., 0.],
[0., 1., 0., 0.]
])
f1score = m.F1_Score(Y, T)
print(f1score) --> 0.5
1.2 FN
Description
False negatives. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
False negatives : int
1.3 FP
Description
False positives. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
False positives : int
1.4 FPR
Description
False positive rate. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
False positive rate : float
1.5 TN
Description
True negatives. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
True negatives : int
1.6 TP
Description
True positives. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
True positives : int
1.7 TPR
Description
True positive rate. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
True positive rate : float
1.8 confusion
Description
Returns the confusion matrix for the values in the prediction
and truth
tensors, i.e. the amount of positions where the values of prediction
and truth
are
-
1 and 1 (True Positive)
-
1 and 0 (False Positive)
-
0 and 0 (True Negative)
-
0 and 1 (False Negative)
1.9 confusion_matrix
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
1.10 plot_confusion_matrix
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
1.11 precision
Description
Precision. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
Precision : float
Equations
$precision = \frac{TP}{TP + FP}$
1.12 recall
Description
Recall. Expected input shape: (batch_size, num_classes)
Parameters
Name | Type | Description |
---|---|---|
Y | torch.Tensor | Prediction |
T | torch.Tensor | True values |
Returns
Recall : float
Equations
$recall = \frac{TP}{TP + FN}$
1.13 top_10_accuracy
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
1.14 top_1_accuracy
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
1.15 top_2_accuracy
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
1.16 top_3_accuracy
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
1.17 top_5_accuracy
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
1.18 top_k_accuracy
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
2 model
2.2 Constants
Name | Value | Description |
---|---|---|
TUC_ActionPrediction_model004 | TUC/ActionPrediction/Model4 | TUC Action prediction model 4 CNN with Multihead-Self-Attention Input - batch size - sequence length = 30 - channels = 3 - width = 200 - height = 200 Output - batch size - number of classes = 10 |
TUC_ActionPrediction_model005 | TUC/ActionPrediction/Model5 | TUC Action prediction model 5 CNN with Multihead-Self-Attention Input - batch size - sequence length = 30 - channels = 3 - width = 300 - height = 300 Output - batch size - number of classes = 10 |
URL | https://drive.google.com/drive/folders/1ulNnPqg-5wvenRl2CuJMxMMcaiYfHjQ9?usp=share_link | Google Drive URL |
2.1 load_model
Description
3 multi_transforms
3.1 BGR2GRAY
Description
Test Description
3.1.1 __call__
Description
3.1.2 __init__
Description
Initializes a new instance
3.2 BGR2RGB
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.2.1 __call__
Description
3.2.2 __init__
Description
Initializes a new instance
3.3 Brightness
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__
Description
3.3.2 __init__
Description
Initializes a new instance
3.4 CenterCrop
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.4.1 __call__
Description
3.4.2 __init__
Description
Initializes a new instance
3.5 Color
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__
Description
3.5.2 __init__
Description
Initializes a new instance
3.6 Compose
3.6.1 __call__
Description
Call self as a function.
3.6.2 __init__
Description
Initialize self. See help(type(self)) for accurate signature.
3.7 GaussianNoise
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__
Description
3.7.2 __init__
Description
Initializes a new instance
3.8 MultiTransform
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__
Description
3.8.2 __init__
Description
Initializes a new instance
3.9 Normalize
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.9.1 __call__
Description
3.9.2 __init__
Description
Initializes a new instance
3.10 RGB2BGR
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.10.1 __call__
Description
3.10.2 __init__
Description
Initializes a new instance
3.11 RandomCrop
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.11.1 __call__
Description
3.11.2 __init__
Description
Test
3.12 RandomHorizontalFlip
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__
Description
3.12.2 __init__
Description
Initializes a new instance
3.13 RandomVerticalFlip
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__
Description
3.13.2 __init__
Description
Initializes a new instance
3.14 Resize
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__
Description
3.14.2 __init__
Description
Initializes a new instance
3.15 Rotate
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.15.1 __call__
Description
3.15.2 __init__
Description
Initializes a new instance
3.16 Satturation
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__
Description
3.16.2 __init__
Description
Initializes a new instance
3.17 Scale
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__
Description
3.17.2 __init__
Description
Initializes a new instance
3.18 Stack
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__
Description
3.18.2 __init__
Description
Initializes a new instance
3.19 ToCVImage
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.19.1 __call__
Description
3.19.2 __init__
Description
Initializes a new instance
3.20 ToNumpy
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.20.1 __call__
Description
3.20.2 __init__
Description
Initializes a new instance
3.21 ToPILImage
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.21.1 __call__
Description
3.21.2 __init__
Description
Initializes a new instance
3.22 ToTensor
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.22.1 __call__
Description
3.22.2 __init__
Description
Initializes a new instance
4 run
4.1 Run
4.1.1 __init__
Description
Initialize self. See help(type(self)) for accurate signature.
4.1.2 append
Description
4.1.3 get_avg
Description
4.1.4 get_val
Description
4.1.5 len
Description
4.1.6 load_best_state_dict
Description
4.1.7 load_state_dict
Description
4.1.8 pickle_dump
Description
4.1.9 pickle_load
Description
4.1.10 plot
Description
4.1.11 recalculate_moving_average
Description
4.1.12 save
Description
4.1.13 save_best_state_dict
Description
4.1.14 save_state_dict
Description
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file rsp_ml-0.0.46.tar.gz
.
File metadata
- Download URL: rsp_ml-0.0.46.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ad306f9dd2d2bc27f7dc55ca6158c187bc913a3ab1e9af83896774c40ee12e6 |
|
MD5 | b4ca29906de347b8cada343485ae8693 |
|
BLAKE2b-256 | 5348d0fe1a7c4d4403520c9352be29e286aadd9cac89c09d773657bf1cfaa989 |
File details
Details for the file rsp_ml-0.0.46-py3-none-any.whl
.
File metadata
- Download URL: rsp_ml-0.0.46-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068ab4b5eccf726fb67d836e4fec249750b98a43e24b3bdaab0f40c07dc7e83f |
|
MD5 | 80a39914a48c32079add0816311f0cf6 |
|
BLAKE2b-256 | 7ecf188f1b180e99a48f8b1411c764119828d7ea254eabb2cc3fcd9f5a3fe09f |