TorchScript Export #596
-
Hi everybody, I was wondering if it is possible to export Anomalib's Pytorch Lighting models to TorchScript format. I tried to use the import torch
from anomalib.models import get_model
from anomalib.config import get_configurable_parameters
# Artifact paths
model_path = './results/patchcore/mvtec/bottle/weights/model.ckpt'
config_path = './anomalib/models/patchcore/config.yaml'
# Read config file
cfg = get_configurable_parameters(config_path=config_path)
# Load model
model = get_model(cfg)
model.load_state_dict(torch.load(model_path)["state_dict"])
model.eval()
# Compile the Pytorch lightning model to TorchScript
script = model.to_torchscript()
# Save for use in production environment
torch.jit.save(script, 'patchcore.pt')
It is possible to export the Anomalib's models to TorchScript format? If not, please consider adding this useful feature in the future. Many thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
From my experience with TorchScript and Anomaly Detection models, it is really not that simple (e.g., just call So, in your case, I would try to untagle the line
That helped me quite a lot during my debugging phase of jit compilation of torch models. |
Beta Was this translation helpful? Give feedback.
-
save issue here |
Beta Was this translation helpful? Give feedback.
-
@mvidela31 Anomalib currently supports OpenVINO export (including patchcore). This enables faster inference speed and allows edge deployment in low power devices. With OpenVINO you can also use these models from your C++ code. |
Beta Was this translation helpful? Give feedback.
@mvidela31 Anomalib currently supports OpenVINO export (including patchcore). This enables faster inference speed and allows edge deployment in low power devices. With OpenVINO you can also use these models from your C++ code.
While we currently do not have a plan to support
TorchScript
, can you tell us what specific features are you looking for fromTorchScript
models. We can then consider introducing it to Anomalib.