Skip to content

Commit

Permalink
predict() support for segmentation models and more (#1708)
Browse files Browse the repository at this point in the history
* squashed commits from segmentation predict branch

* Set ignore_errors=True to trainer test and declare why

* version bumped (#1374)

Co-authored-by: Eugene Khvedchenya <ekhvedchenya@gmail.com>

* segmentation predict:
remove predict from ppliteseg models (PPLiteSegBase) as it's implement in SegmentationModule

* Added missing transforms in validation

* Add missing default preprocessing params for rest of the models

* Add STDC predict

* Update the predict & transforms & deprecate SegToTensor

* Added lru_cache(1) to _get_pipeline method

* Use only URL in the example script

* Rename segmentation processing classes to have "Segmentation" prefix

* Remove test for predict using segformer b0

* Segmentation transforms to use nd.ndarray whenever possible

* Segmentation transforms to use nd.ndarray whenever possible

* Added tests

* Added tests

* Fix typos

* Merge master

---------

Co-authored-by: dafna-r <dalia.rifold@gmail.com>
Co-authored-by: dafna-r <47064033+dafna-r@users.noreply.github.com>
Co-authored-by: Louis-Dupont <35190946+Louis-Dupont@users.noreply.github.com>
Co-authored-by: Shay Aharon <80472096+shaydeci@users.noreply.github.com>
Co-authored-by: Louis Dupont <louis-dupont@live.fr>
  • Loading branch information
6 people committed Dec 20, 2023
1 parent 445db0f commit c4bbce7
Show file tree
Hide file tree
Showing 40 changed files with 2,044 additions and 1,698 deletions.
2,273 changes: 710 additions & 1,563 deletions notebooks/transfer_learning_semantic_segmentation.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/super_gradients/common/object_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class Transforms:

# From SG
SegNormalize = "SegNormalize"
SegStandardize = "SegStandardize"
SegToTensor = "SegToTensor"
SegConvertToTensor = "SegConvertToTensor"
SegRandomFlip = "SegRandomFlip"
SegResize = "SegResize"
SegRescale = "SegRescale"
Expand All @@ -53,6 +55,7 @@ class Transforms:
SegPadShortToCropSize = "SegPadShortToCropSize"
SegPadToDivisible = "SegPadToDivisible"
SegColorJitter = "SegColorJitter"
# Detection transforms
DetectionStandardize = "DetectionStandardize"
DetectionMosaic = "DetectionMosaic"
DetectionRandomAffine = "DetectionRandomAffine"
Expand Down Expand Up @@ -442,3 +445,8 @@ class Processings:
ComposeProcessing = "ComposeProcessing"
CenterCrop = "CenterCrop"
Resize = "Resize"
SegmentationResizeWithPadding = "SegmentationResizeWithPadding"
SegmentationRescale = "SegmentationRescale"
SegmentationResize = "SegmentationResize"
SegmentationPadShortToCropSize = "SegmentationPadShortToCropSize"
SegmentationPadToDivisible = "SegmentationPadToDivisible"
13 changes: 13 additions & 0 deletions src/super_gradients/examples/predict/segmentation_predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from super_gradients.common.object_names import Models
from super_gradients.training import models


model = models.get(model_name=Models.PP_LITE_T_SEG75, pretrained_weights="cityscapes")

IMAGES = [
"https://deci-pretrained-models.s3.amazonaws.com/sample_images/beatles-abbeyroad.jpg",
]

predictions = model.predict(IMAGES)
predictions.show()
predictions.save(output_folder="") # Save in working directory
6 changes: 5 additions & 1 deletion src/super_gradients/recipes/cityscapes_al_ddrnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ dataset_params:
crop_size: [ 1024, 1024 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



training_hyperparams:
max_epochs: 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@ train_dataset_params:
cache_labels: False
cache_images: False
transforms:
- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor


val_dataset_params:
root_dir: /data/cityscapes
list_file: lists/val.lst
labels_csv_path: lists/labels.csv
cache_labels: False
cache_images: False
transforms:
- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor

train_dataloader_params:
dataset: CityscapesConcatDataset
shuffle: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ train_dataset_params:
cache_labels: False
cache_images: False
transforms:
- SegToTensor
- SegStandardize:
max_value: 255
- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
- SegConvertToTensor


val_dataset_params:
root_dir: /data/cityscapes
Expand All @@ -17,10 +20,12 @@ val_dataset_params:
cache_labels: False
cache_images: False
transforms:
- SegToTensor
- SegStandardize:
max_value: 255
- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
- SegConvertToTensor

train_dataloader_params:
shuffle: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ train_dataset_params:
crop_size: [ 1024, 1024 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor


train_dataloader_params:
batch_size: 6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@ train_dataset_params:
crop_size: [ 768, 768 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor


val_dataset_params:
transforms:
- SegRescale:
scale_factor: 0.75

- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor


train_dataloader_params:
batch_size: 8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ train_dataset_params:
crop_size: 1024
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor


train_dataloader_params:
batch_size: 4
num_workers: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ train_dataset_params:
crop_size: [ 1024, 1024 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



val_dataset_params:
transforms:
Expand All @@ -39,12 +43,16 @@ val_dataset_params:
crop_size: [ 1024, 1024 ]
fill_mask: 19

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



train_dataloader_params:
batch_size: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,32 @@ train_dataset_params:
crop_size: [ 1024, 512 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



val_dataset_params:
transforms:
- SegRescale:
scale_factor: 0.5

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



train_dataloader_params:
batch_size: 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@ train_dataset_params:
crop_size: [ 1536, 768 ]
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



val_dataset_params:
transforms:
- SegRescale:
scale_factor: 0.75

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
mean: [ 0.485, 0.456, 0.406 ]
std: [ 0.229, 0.224, 0.225 ]

- SegConvertToTensor



train_dataloader_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ train_dataset_params:
crop_size: 512
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



val_dataset_params:
root_dir: /data/coco/
Expand All @@ -49,12 +53,16 @@ val_dataset_params:
crop_size: 512
mode: center

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



train_dataloader_params:
shuffle: True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ train_dataset_params:
crop_size: 1024
mode: random

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



val_dataset_params:
root_dir: /data/mapillary-vistas-dataset_public_v2.0
Expand All @@ -58,12 +62,16 @@ val_dataset_params:
divisible_value: 32
fill_mask: ${dataset_params.mask_fill_value}

- SegToTensor
- SegStandardize:
max_value: 255

- SegNormalize:
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]

- SegConvertToTensor



train_dataloader_params:
shuffle: True
Expand Down
Loading

0 comments on commit c4bbce7

Please sign in to comment.