from leap_ie.vision import engine
from leap_ie.vision.models import get_model
config = {"leap_api_key": "YOUR_LEAP_API_KEY"}
# Replace this model with your own, or explore any imagenet classifier from torchvision (https://pytorch.org/vision/stable/models.html).
preprocessing_fn, model, class_list = get_model("resnet18", source="torchvision")
# indexes of classes to generate prototypes for. In this case, ['tench', 'goldfish', 'great white shark'].
target_classes = [0, 1, 2]
# generate prototypes
df_results, dict_results = engine.generate(
project_name="resnet18",
model=model,
class_list=class_list,
config=config,
target_classes=target_classes,
preprocessing=preprocessing_fn,
samples=None,
device=None,
mode="pt",
)
# For the best experience, head to https://app.leap-labs.com/ to explore your prototypes and feature isolations in the browser!
# Or, if you're in a jupyter notebook, you can display your results inline:
engine.display_df(df_results)from torchvision import transforms
from leap_ie.vision import engine
from leap_ie.vision.models import get_model
from PIL import Image
config = {"leap_api_key": "YOUR_LEAP_API_KEY"}
# Replace this model with your own, or explore any imagenet classifier from torchvision (https://pytorch.org/vision/stable/models.html).
preprocessing_fn, model, class_list = get_model("resnet18", source="torchvision")
# load an image
image_path = "tools.jpeg"
tt = transforms.ToTensor()
image = preprocessing_fn[0](tt(Image.open(image_path)).unsqueeze(0))
# to isolate features:
df_results, dict_results = engine.generate(
project_name="resnet18",
model=model,
class_list=class_list,
config=config,
target_classes=None,
preprocessing=preprocessing_fn,
samples=image,
mode="pt",
)
# For the best experience, head to https://app.leap-labs.com/ to explore your prototypes and feature isolations in the browser!
# Or, if you're in a jupyter notebook, you can display your results inline:
engine.display_df(df_results)