Skip to main content

Machine Learning

Project description

Table of Contents

1 metrics

TOC

1.1 F1_Score

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

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

TOC

2.2 Constants

TOC

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

TOC

Description

3 multi_transforms

TOC

3.1 BGR2GRAY

TOC

Description

Test Description

3.1.1 __call__

TOC

Description

3.1.2 __init__

TOC

Description

Initializes a new instance

3.2 BGR2RGB

TOC

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.Composeto combine multiple image sequence transformations.

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

3.2.1 __call__

TOC

Description

3.2.2 __init__

TOC

Description

Initializes a new instance

3.3 Brightness

TOC

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.Composeto combine multiple image sequence transformations.

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

3.3.1 __call__

TOC

Description

3.3.2 __init__

TOC

Description

Initializes a new instance

3.4 CenterCrop

TOC

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.Composeto combine multiple image sequence transformations.

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

3.4.1 __call__

TOC

Description

3.4.2 __init__

TOC

Description

Initializes a new instance

3.5 Color

TOC

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.Composeto combine multiple image sequence transformations.

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

3.5.1 __call__

TOC

Description

3.5.2 __init__

TOC

Description

Initializes a new instance

3.6 Compose

TOC

3.6.1 __call__

TOC

Description

Call self as a function.

3.6.2 __init__

TOC

Description

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

3.7 GaussianNoise

TOC

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.Composeto combine multiple image sequence transformations.

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

3.7.1 __call__

TOC

Description

3.7.2 __init__

TOC

Description

Initializes a new instance

3.8 MultiTransform

TOC

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.Composeto combine multiple image sequence transformations.

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

3.8.1 __call__

TOC

Description

3.8.2 __init__

TOC

Description

Initializes a new instance

3.9 Normalize

TOC

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.Composeto combine multiple image sequence transformations.

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

3.9.1 __call__

TOC

Description

3.9.2 __init__

TOC

Description

Initializes a new instance

3.10 RGB2BGR

TOC

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.Composeto combine multiple image sequence transformations.

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

3.10.1 __call__

TOC

Description

3.10.2 __init__

TOC

Description

Initializes a new instance

3.11 RandomCrop

TOC

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.Composeto combine multiple image sequence transformations.

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

3.11.1 __call__

TOC

Description

3.11.2 __init__

TOC

Description

Test

3.12 RandomHorizontalFlip

TOC

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.Composeto combine multiple image sequence transformations.

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

3.12.1 __call__

TOC

Description

3.12.2 __init__

TOC

Description

Initializes a new instance

3.13 RandomVerticalFlip

TOC

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.Composeto combine multiple image sequence transformations.

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

3.13.1 __call__

TOC

Description

3.13.2 __init__

TOC

Description

Initializes a new instance

3.14 Resize

TOC

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.Composeto combine multiple image sequence transformations.

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

3.14.1 __call__

TOC

Description

3.14.2 __init__

TOC

Description

Initializes a new instance

3.15 Rotate

TOC

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.Composeto combine multiple image sequence transformations.

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

3.15.1 __call__

TOC

Description

3.15.2 __init__

TOC

Description

Initializes a new instance

3.16 Satturation

TOC

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.Composeto combine multiple image sequence transformations.

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

3.16.1 __call__

TOC

Description

3.16.2 __init__

TOC

Description

Initializes a new instance

3.17 Scale

TOC

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.Composeto combine multiple image sequence transformations.

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

3.17.1 __call__

TOC

Description

3.17.2 __init__

TOC

Description

Initializes a new instance

3.18 Stack

TOC

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.Composeto combine multiple image sequence transformations.

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

3.18.1 __call__

TOC

Description

3.18.2 __init__

TOC

Description

Initializes a new instance

3.19 ToCVImage

TOC

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.Composeto combine multiple image sequence transformations.

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

3.19.1 __call__

TOC

Description

3.19.2 __init__

TOC

Description

Initializes a new instance

3.20 ToNumpy

TOC

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.Composeto combine multiple image sequence transformations.

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

3.20.1 __call__

TOC

Description

3.20.2 __init__

TOC

Description

Initializes a new instance

3.21 ToPILImage

TOC

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.Composeto combine multiple image sequence transformations.

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

3.21.1 __call__

TOC

Description

3.21.2 __init__

TOC

Description

Initializes a new instance

3.22 ToTensor

TOC

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.Composeto combine multiple image sequence transformations.

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

3.22.1 __call__

TOC

Description

3.22.2 __init__

TOC

Description

Initializes a new instance

4 run

TOC

4.1 Run

TOC

4.1.1 __init__

TOC

Description

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

4.1.2 append

TOC

Description

4.1.3 get_avg

TOC

Description

4.1.4 get_val

TOC

Description

4.1.5 len

TOC

Description

4.1.6 load_best_state_dict

TOC

Description

4.1.7 load_state_dict

TOC

Description

4.1.8 pickle_dump

TOC

Description

4.1.9 pickle_load

TOC

Description

4.1.10 plot

TOC

Description

4.1.11 recalculate_moving_average

TOC

Description

4.1.12 save

TOC

Description

4.1.13 save_best_state_dict

TOC

Description

4.1.14 save_state_dict

TOC

Description

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rsp_ml-0.0.46.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

rsp_ml-0.0.46-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

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

Hashes for rsp_ml-0.0.46.tar.gz
Algorithm Hash digest
SHA256 9ad306f9dd2d2bc27f7dc55ca6158c187bc913a3ab1e9af83896774c40ee12e6
MD5 b4ca29906de347b8cada343485ae8693
BLAKE2b-256 5348d0fe1a7c4d4403520c9352be29e286aadd9cac89c09d773657bf1cfaa989

See more details on using hashes here.

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

Hashes for rsp_ml-0.0.46-py3-none-any.whl
Algorithm Hash digest
SHA256 068ab4b5eccf726fb67d836e4fec249750b98a43e24b3bdaab0f40c07dc7e83f
MD5 80a39914a48c32079add0816311f0cf6
BLAKE2b-256 7ecf188f1b180e99a48f8b1411c764119828d7ea254eabb2cc3fcd9f5a3fe09f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page