-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changes for e2e inference for passing test cases (#1127)
### Summary - End to end inference changes added for passing test cases present in Mobilenet v1, Mobilenet v2, Mobilenet v3, Resnext, wideresnet , ghostnet & DLA Models - Push marker added for vilt & all above models
- Loading branch information
1 parent
6296027
commit ccb3f6b
Showing
16 changed files
with
398 additions
and
190 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
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,57 @@ | ||
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
import urllib | ||
|
||
import requests | ||
import torch | ||
import torchvision.transforms as transforms | ||
from PIL import Image | ||
|
||
from test.models.pytorch.vision.dla.utils import dla_model | ||
|
||
|
||
def load_dla_model(variant): | ||
|
||
func = getattr(dla_model, variant) | ||
|
||
# Load data sample | ||
url = "https://images.rawpixel.com/image_1300/cHJpdmF0ZS9sci9pbWFnZXMvd2Vic2l0ZS8yMDIyLTA1L3BkMTA2LTA0Ny1jaGltXzEuanBn.jpg" | ||
image = Image.open(requests.get(url, stream=True).raw) | ||
|
||
# Preprocessing | ||
transform = transforms.Compose( | ||
[ | ||
transforms.Resize(256), | ||
transforms.CenterCrop(224), | ||
transforms.ToTensor(), | ||
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), | ||
] | ||
) | ||
img_tensor = transform(image).unsqueeze(0) | ||
|
||
framework_model = func(pretrained="imagenet") | ||
framework_model.eval() | ||
|
||
inputs = [img_tensor] | ||
|
||
return framework_model, inputs | ||
|
||
|
||
url = "https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt" | ||
|
||
|
||
def post_processing(output, top_k=5): | ||
|
||
probabilities = torch.nn.functional.softmax(output[0][0], dim=0) | ||
urllib.request.urlretrieve(url, "imagenet_classes.txt") | ||
|
||
with open("imagenet_classes.txt", "r") as f: | ||
categories = [s.strip() for s in f.readlines()] | ||
topk_prob, topk_catid = torch.topk(probabilities, top_k) | ||
for i in range(topk_prob.size(0)): | ||
print(categories[topk_catid[i]], topk_prob[i].item()) | ||
|
||
# Cleanup | ||
os.remove("imagenet_classes.txt") |
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
Empty file.
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,52 @@ | ||
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
import urllib | ||
|
||
import timm | ||
import torch | ||
from PIL import Image | ||
from timm.data import resolve_data_config | ||
from timm.data.transforms_factory import create_transform | ||
|
||
from test.utils import download_model | ||
|
||
|
||
def load_ghostnet_model(variant): | ||
|
||
# Create Forge module from PyTorch model | ||
framework_model = download_model(timm.create_model, variant, pretrained=True) | ||
framework_model.eval() | ||
|
||
# Prepare input | ||
url, filename = ( | ||
"https://github.com/pytorch/hub/raw/master/images/dog.jpg", | ||
"dog.jpg", | ||
) | ||
urllib.request.urlretrieve(url, filename) | ||
img = Image.open(filename) | ||
data_config = resolve_data_config({}, model=framework_model) | ||
transforms = create_transform(**data_config, is_training=False) | ||
img_tensor = transforms(img).unsqueeze(0) | ||
|
||
return framework_model, [img_tensor] | ||
|
||
|
||
url = "https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt" | ||
|
||
|
||
def post_processing(output, top_k=5): | ||
|
||
probabilities = torch.nn.functional.softmax(output[0][0], dim=0) | ||
urllib.request.urlretrieve(url, "imagenet_classes.txt") | ||
|
||
with open("imagenet_classes.txt", "r") as f: | ||
categories = [s.strip() for s in f.readlines()] | ||
topk_prob, topk_catid = torch.topk(probabilities, top_k) | ||
for i in range(topk_prob.size(0)): | ||
print(categories[topk_catid[i]], topk_prob[i].item()) | ||
|
||
# Cleanup | ||
os.remove("imagenet_classes.txt") | ||
os.remove("dog.jpg") |
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
Oops, something went wrong.