Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rsp-ml

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rsp-ml

Machine Learning

  • 0.0.72
  • PyPI
  • Socket score

Maintainers
1

RSProduction MachineLearning

This project provides some usefull machine learning functionality.

Table of Contents

1 metrics

TOC

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

1.1 AUROC

TOC

Description

Calculates the Area under the Receiver Operation Chracteristic Curve.

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
num_thresholdsint, default = 100Number of thresholds to compute.

Returns

Receiver Operation Chracteristic Area under the Curve : float

1.2 F1_Score

TOC

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll 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

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

False negatives : int

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

False positives : int

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

False positive rate : float

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
num_thresholdsint, default = 100Number of thresholds to compute.

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

True negatives : int

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

True positives : int

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll values that are greater than or equal to the threshold are considered a positive class.

Returns

True positive rate : float

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

Confusion matrix : torch.Tensor

Example

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

Description

Plot the receiver operating characteristic.

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
num_thresholdsint, default = 100Number of thresholds to compute.
titlestr, optional, default = 'Confusion Matrix'Title of the plot
class_curvesbool, default = FalsePlot ROC curve for each class
labelsstr, optional, default = NoneClass labels -> automatic labeling C000, ..., CXXX if labels is None
plt_showbool, optional, default = FalseSet to True to show the plot
save_file_namestr, optional, default = NoneIf not None, the plot is saved under the specified save_file_name.

Returns

Image of the confusion matrix : np.array

1.12 plot_confusion_matrix

TOC

Description

Plot the confusion matrix

Parameters

NameTypeDescription
confusion_matrixtorch.TensorConfusion matrix
labelsstr, optional, default = NoneClass labels -> automatic labeling C000, ..., CXXX if labels is None
cmapstr, optional, default = 'Blues'Seaborn cmap, see https://r02b.github.io/seaborn_palettes/
xlabelstr, optional, default = 'Predicted label'X-Axis label
ylabelstr, optional, default = 'True label'Y-Axis label
titlestr, optional, default = 'Confusion Matrix'Title of the plot
plt_showbool, optional, default = FalseSet to True to show the plot
save_file_namestr, optional, default = NoneIf not None, the plot is saved under the specified save_file_name.

Returns

Image of the confusion matrix : np.array

1.13 precision

TOC

Description

Precision. Expected input shape: (batch_size, num_classes)

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll 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

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

Description

Recall. Expected input shape: (batch_size, num_classes)

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values
thresholdfloatAll 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

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

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

Example

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

Description

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

Parameters

NameTypeDescription
Ytorch.TensorPrediction
Ttorch.TensorTrue values

Returns

Top k accuracy : float

Example

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

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

2.2 Constants

TOC

NameValueDescription
TUC_ActionPrediction_model004TUC/ActionPrediction/Model4TUC 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_model005TUC/ActionPrediction/Model5TUC 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
URLhttps://drive.google.com/drive/folders/1ulNnPqg-5wvenRl2CuJMxMMcaiYfHjQ9?usp=share_linkGoogle Drive URL

2.1 load_model

TOC

Description

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

See Constants for available models

Parameters

NameTypeDescription
model_idstrID of the model
force_reloadboolOverwrite local file -> forces downlad.

Returns

Pretrained PyTorch model : torch.nn.Module

Example

import rsp.ml.model as model

model004 = model.load_model(model.TUC_ActionPrediction_model004)

3 multi_transforms

TOC

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

Description

Converts a sequence of BGR images to grayscale images.

3.1.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.1.2 __init__

TOC

Description

Initializes a new instance.

3.2 BGR2RGB : MultiTransform

TOC

Description

Converts sequence of BGR images to RGB images.

3.2.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.2.2 __init__

TOC

Description

Initializes a new instance.

3.3 Brightness : 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.3.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.3.2 __init__

TOC

Description

Initializes a new instance.

3.4 CenterCrop : MultiTransform

TOC

Description

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

3.4.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.4.2 __init__

TOC

Description

Initializes a new instance.

Parameters

NameTypeDescription
max_scalefloatImages are scaled randomly between 1. and max_scale before cropping to original size.

3.5 Color : 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.5.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.5.2 __init__

TOC

Description

Initializes a new instance.

3.6 Compose : builtins.object

TOC

Description

Composes several MultiTransforms together.

Example

import rsp.ml.multi_transforms as t

transforms = t.Compose([
  t.BGR2GRAY(),
  t.Scale(0.5)
])

3.6.1 __call__

TOC

Description

Call self as a function.

3.6.2 __init__

TOC

Description

Initializes a new instance.

Parameters

NameTypeDescription
childrenList[MultiTransform]List of MultiTransforms to compose.

3.7 GaussianNoise : 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.7.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.7.2 __init__

TOC

Description

Initializes a new instance.

3.8 MultiTransform : builtins.object

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

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.8.2 __init__

TOC

Description

Initializes a new instance.

3.9 Normalize : MultiTransform

TOC

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

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.9.2 __init__

TOC

Description

Initializes a new instance.

Parameters

NameTypeDescription
meanList[float]Sequence of means for each channel.
stdList[float]Sequence of standard deviations for each channel.
inplaceboolSet to True make this operation in-place.

3.10 RGB2BGR : BGR2RGB

TOC

Description

Converts sequence of RGB images to BGR images.

3.10.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.10.2 __init__

TOC

Description

Initializes a new instance.

3.11 RandomCrop : MultiTransform

TOC

Description

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

3.11.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.11.2 __init__

TOC

Description

Initializes a new instance.

Parameters

NameTypeDescription
max_scalefloatImages are scaled randomly between 1. and max_scale before cropping to original size.

3.12 RandomHorizontalFlip : 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.12.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.12.2 __init__

TOC

Description

Initializes a new instance.

3.13 RandomVerticalFlip : 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.13.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.13.2 __init__

TOC

Description

Initializes a new instance.

3.14 Resize : 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.14.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.14.2 __init__

TOC

Description

Initializes a new instance.

3.15 Rotate : MultiTransform

TOC

Description

Randomly rotates images.

Equations

$angle = -max_angle + 2 \cdot random() \cdot max_angle$

3.15.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.15.2 __init__

TOC

Description

Iitializes a new instance.

Parameters

NameTypeDescription
max_anglefloatMaximal rotation in degrees
auto_scalebool, default = TrueImage will be resized when auto scale is activated to avoid black margins.

3.16 Satturation : 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.16.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.16.2 __init__

TOC

Description

Initializes a new instance.

3.17 Scale : 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.17.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.17.2 __init__

TOC

Description

Initializes a new instance.

3.18 Stack : 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.18.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.18.2 __init__

TOC

Description

Initializes a new instance.

3.19 ToCVImage : MultiTransform

TOC

Description

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

3.19.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.19.2 __init__

TOC

Description

Initializes a new instance.

3.20 ToNumpy : MultiTransform

TOC

Description

Converts a torch.Tensorto numpy

3.20.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.20.2 __init__

TOC

Description

Initializes a new instance.

3.21 ToPILImage : MultiTransform

TOC

Description

Converts sequence of images to sequence of PIL.Image.

3.21.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.21.2 __init__

TOC

Description

Initializes a new instance.

3.22 ToTensor : MultiTransform

TOC

Description

Converts a sequence of images to torch.Tensor.

3.22.1 __call__

TOC

Description

Call self as a function.

Parameters

NameTypeDescription
inputtorch.Tensor
List[PIL.Image]
List[numpy.array]
Sequence of images

3.22.2 __init__

TOC

Description

Initializes a new instance.

4 run

TOC

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

4.1.1 __init__

TOC

Description

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

4.1.2 append

TOC

4.1.3 get_avg

TOC

4.1.4 get_val

TOC

4.1.5 len

TOC

4.1.6 load_best_state_dict

TOC

4.1.7 load_state_dict

TOC

4.1.8 pickle_dump

TOC

4.1.9 pickle_load

TOC

4.1.10 plot

TOC

4.1.11 recalculate_moving_average

TOC

4.1.12 save

TOC

4.1.13 save_best_state_dict

TOC

4.1.14 save_state_dict

TOC

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc