Skip to main content

saldet

Saliency Detection (saldet) is a collection of models and tools to perform Saliency Detection with PyTorch (cuda, mps, etc.).

PyPI Version Build Status Code Coverage

Models

List of saliency detection models supported by saldet:

Weights

  • PGNet -> weights from PGNet repo converted to saldet version from here
  • U2Net Lite -> weights from here (U2Net repository)
  • U2Net Full -> weights from here (U2Net repository)
  • U2Net Full - Portrait -> weights for portrait images from here (U2Net repository)
  • U2Net Full - Human Segmentation -> weights for segmenting humans from here (U2Net repository)
  • PFAN -> weights from PFAN repo converted to saldet version from here

To load pre-trained weights:

from saldet import create_model
model = create_model("pgnet", checkpoint_path="PATH/TO/pgnet.pth")

Train

Easy Mode

The library comes with easy access to train models thanks to the amazing PyTorch Lightning support.

from saldet.experiment import train

train(
    data_dir=...,
    config_path="config/u2net_lite.yaml", # check the config folder with some configurations
    output_dir=...,
    resume_from=...,
    seed=42
)

Once the training is over, configuration file and checkpoints will be saved into the output dir.

[WARNING] The dataset must be structured as follows:

dataset
    ├── train                    
    |       ├── images          
    |       │   ├── img_1.jpg
    |       │   └── img_2.jpg                
    |       └── masks
    |           ├── img_1.png
    |           └── img_2.png   
    └── val
           ├── images          
           │   ├── img_10.jpg
           │   └── img_11.jpg                
           └── masks
               ├── img_10.png
               └── img_11.png   

PyTorch Lighting Mode

The library provides utils for model and data PyTorch Lightning Modules.

import pytorch_lightning as pl
from saldet import create_model
from saldet.pl import
 SaliencyPLDataModule, SaliencyPLModel
from saldet.transform import SaliencyTransform

# datamodule
datamodule = SaliencyPLDataModule(
    root_dir=data_dir,
    train_transform=SaliencyTransform(train=True, **config["transform"]),
    val_transform=SaliencyTransform(train=False, **config["transform"]),
    **config["datamodule"],
)

model = create_model(...)
criterion = ...
optimizer = ...
lr_scheduler = ...

pl_model = SaliencyPLModel(
    model=model, criterion=criterion, optimizer=optimizer, lr_scheduler=lr_scheduler
)

trainer = pl.Trainer(...)

# fit
print(f"Launching training...")
trainer.fit(model=pl_model, datamodule=datamodule)

PyTorch Mode

Alternatively you can define your custom training process and use the create_model() util to use the model you like.

Inference

The library comes with easy access to inference saliency maps from a folder with images.

from saldet.experiment import inference

inference(
    images_dir=...,
    ckpt=..., # path to ckpt/pth model file
    config_path=..., # path to configuration file from saldet train
    output_dir=..., # where to save saliency maps
    sigmoid=..., # whether to apply sigmoid to predicted masks
)

To-Dos

[ ] Improve code coverage

[ ] ReadTheDocs documentation

Metadata

Release files for saldet 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for saldet 0.6.1
File Size Uploaded
saldet-0.6.1.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for saldet 0.6.1
File Interpreter ABI Platform
saldet-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 65.7 kB

Release files / saldet-0.6.1.tar.gz

Download URL saldet-0.6.1.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
62afa0246dd90cf0cb8d43051e199abe2a13b3f0656312ec9c7b8601c1133d3b
BLAKE2b-256 checksum
How to use checksums
382471838b72210002901cd5c0702a27cf923c48048a3a8d6a7a4d9ed71d5f9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.6 Darwin/22.5.0

Release files / saldet-0.6.1-py3-none-any.whl

Download URL saldet-0.6.1-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87939ac87fe1042665562cb6d50060798d1ce4b6a7d372133498fb902a778206
BLAKE2b-256 checksum
How to use checksums
bb09f07fbc6c5ff8f0ef6e22639155219c007e900d090d865ab35a86d8e47927
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.9.6 Darwin/22.5.0

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page