-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update KD Notebook for classification (#1595)
* Update what_are_recipes_and_how_to_use notebook * Improve notebook version check script and added what_are_recipes_and_how_to_use to the list of checked notebooks * Move import of nbformat inside get_first_cell_content method * Update KD notebook, make it using predict() Fixed Cifar/Imagenet datasets that using torchvision transforms to support HasPreprocessingParams * Added Resize op to dataset params * Added notebook * Added test_get_torchvision_transforms_equivalent_processing & Fixed Resize implementation to match the implementation from Torchvision * Update notebook
- Loading branch information
Showing
14 changed files
with
793 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
612 changes: 612 additions & 0 deletions
612
notebooks/how_to_use_knowledge_distillation_for_classification.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/super_gradients/training/datasets/classification_datasets/torchvision_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List, Any, Dict | ||
|
||
from torchvision.datasets.vision import StandardTransform | ||
from torchvision.transforms import Resize, ToTensor, Normalize, CenterCrop, Compose | ||
|
||
from super_gradients.common.object_names import Processings | ||
|
||
|
||
def get_torchvision_transforms_equivalent_processing(transforms: List[Any]) -> List[Dict[str, Any]]: | ||
""" | ||
Get the equivalent processing pipeline for torchvision transforms. | ||
:return: List of Processings operations | ||
""" | ||
# Since we are using cv2.imread to read images, our model in fact is trained on BGR images. | ||
# In our pipelines the convention that input images are RGB, so we need to reverse the channels to get BGR | ||
# to match with the expected input of the model. | ||
pipeline = [] | ||
|
||
if isinstance(transforms, StandardTransform): | ||
transforms = transforms.transform | ||
|
||
if isinstance(transforms, Compose): | ||
transforms = transforms.transforms | ||
|
||
for transform in transforms: | ||
if isinstance(transform, ToTensor): | ||
pipeline.append({Processings.StandardizeImage: {"max_value": 255}}) | ||
elif isinstance(transform, Normalize): | ||
pipeline.append({Processings.NormalizeImage: {"mean": tuple(map(float, transform.mean)), "std": tuple(map(float, transform.std))}}) | ||
elif isinstance(transform, Resize): | ||
pipeline.append({Processings.Resize: {"size": int(transform.size)}}) | ||
elif isinstance(transform, CenterCrop): | ||
pipeline.append({Processings.CenterCrop: {"size": int(transform.size)}}) | ||
else: | ||
raise ValueError(f"Unsupported transform: {transform}") | ||
|
||
pipeline.append({Processings.ImagePermute: {"permutation": (2, 0, 1)}}) | ||
return pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters