sportslabkit.image_model.torchreid#

Overview#

Classes#

BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

ShuffleNet

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

MobileNetV2_x1_0

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

MobileNetV2_x1_4

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

MLFN

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_x1_0

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_x0_75

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_x0_5

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_x0_25

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_ibn_x1_0

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_ain_x1_0

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_ain_x0_75

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_ain_x0_5

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

OSNet_ain_x0_25

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

ResNet50

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

ResNet50_fc512

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Function#

show_torchreid_models()

Print available models as a list.

download_model(model_name)

-

Attributes#

model_save_dir

-

model_dict

-

Classes#

class sportslabkit.image_model.torchreid.BaseTorchReIDModel(name: str = 'osnet_x1_0', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: sportslabkit.image_model.base.BaseImageModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

Overview

Methods#

load()

-

forward(x)

Forward must be overridden by subclasses. The overriding method should define the forward pass of the model. The model will receive a 4-dimensional numpy array representing the images. As for the output, the model is expected to return something that can be converted into a 2-dimensional numpy array.

Members

load()[source]#
forward(x)[source]#

Forward must be overridden by subclasses. The overriding method should define the forward pass of the model. The model will receive a 4-dimensional numpy array representing the images. As for the output, the model is expected to return something that can be converted into a 2-dimensional numpy array.

Parameters:

x (np.ndarray) – input image

class sportslabkit.image_model.torchreid.ShuffleNet(name: str = 'shufflenet', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.MobileNetV2_x1_0(name: str = 'mobilenetv2_x1_0', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.MobileNetV2_x1_4(name: str = 'mobilenetv2_x1_4', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.MLFN(name: str = 'mfln', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_x1_0(name: str = 'osnet_x1_0', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_x0_75(name: str = 'osnet_x0_75', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_x0_5(name: str = 'osnet_x0_5', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_x0_25(name: str = 'osnet_x0_25', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_ibn_x1_0(name: str = 'osnet_ibn_x1_0', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_ain_x1_0(name: str = 'osnet_ain_x1_0', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_ain_x0_75(name: str = 'osnet_ain_x0_75', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_ain_x0_5(name: str = 'osnet_ain_x0_5', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.OSNet_ain_x0_25(name: str = 'osnet_ain_x0_25', path: str = '', device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.ResNet50(name: str = 'resnet50', path: str = model_dict['resnet50_MSMT17'], device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

class sportslabkit.image_model.torchreid.ResNet50_fc512(name: str = 'resnet50_fc512', path: str = model_dict['resnet50_fc512_MSMT17'], device: str = 'cpu', image_size: tuple[int, int] = (256, 128), pixel_mean: list[float] = field(default_factory=lambda : ...), pixel_std: list[float] = field(default_factory=lambda : ...), pixel_norm: bool = True, verbose: bool = False)[source]#

Bases: BaseTorchReIDModel

Base class for image embedding models. This class implements basic functionality for handling input and output data, and requires subclasses to implement model loading and forward pass functionality.

Subclasses should override the ‘load’ and ‘forward’ methods. The ‘load’ method should handle loading the model from the specified repository and checkpoint, and ‘forward’ should define the forward pass of the model. Then add ConfigTemplates for your model to define the available configuration options.

The input to the model should be flexible. It accepts numpy.ndarray, torch.Tensor, pathlib Path, string file, PIL Image, or a list of any of these. All inputs will be converted to a list of numpy arrays representing the images.

The output of the model is expected to be a list of embeddings, one for each image. If the model’s output does not meet this expectation, _check_and_fix_outputs method should convert the output into a compatible format.

Example

class CustomImageModel(BaseImageModel):
def load(self):

# Load your model here pass

def forward(self, x):

# Define the forward pass here pass

model_config#

The configuration for the model.

Type:

Optional[dict]

inference_config#

The configuration for the inference.

Type:

Optional[dict]

input_is_batched#

Whether the input is batched or not. This is set by the _check_and_fix_inputs method.

Type:

bool

Functions#

sportslabkit.image_model.torchreid.show_torchreid_models()[source]#

Print available models as a list.

sportslabkit.image_model.torchreid.download_model(model_name)[source]#

Attributes#

sportslabkit.image_model.torchreid.model_save_dir[source]#
sportslabkit.image_model.torchreid.model_dict[source]#