Metadata-Version: 2.1
Name: xai-inference-engine
Version: 0.1.1
Summary: A pip package for XAI Inferencing
Author: Ravidu Suien Rammuni Silva
Author-email: Ravidu Suien Rammuni Silva <ravidus@gmail.com>
Project-URL: Homepage, https://github.com/SuienS/xai-inference-engine
Project-URL: Bug Tracker, https://github.com/SuienS/xai-inference-engine/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: colorama ==0.4.6
Requires-Dist: contourpy ==1.1.1
Requires-Dist: cycler ==0.12.1
Requires-Dist: filelock ==3.12.4
Requires-Dist: fonttools ==4.43.1
Requires-Dist: fsspec ==2023.10.0
Requires-Dist: Jinja2 ==3.1.2
Requires-Dist: kiwisolver ==1.4.5
Requires-Dist: MarkupSafe ==2.1.3
Requires-Dist: matplotlib ==3.8.0
Requires-Dist: mpmath ==1.3.0
Requires-Dist: networkx ==3.2
Requires-Dist: numpy ==1.26.1
Requires-Dist: packaging ==23.2
Requires-Dist: Pillow ==10.1.0
Requires-Dist: pyparsing ==3.1.1
Requires-Dist: pyproject-hooks ==1.0.0
Requires-Dist: python-dateutil ==2.8.2
Requires-Dist: six ==1.16.0
Requires-Dist: sympy ==1.12
Requires-Dist: tomli ==2.0.1
Requires-Dist: torch ==2.1.0
Requires-Dist: typing-extensions ==4.8.0
Provides-Extra: interactive
Requires-Dist: jupyter ; extra == 'interactive'

# XAI Inference Engine
Todo Description...

# Installation
Execute the following command in your terminal to install the package.
```python
pip install xai-inference-engine
```

# Usage
Follow the example below to use the package. Copy and paste the code into a python script and run it.

```python

print("[INFO]: Testing XAIInferenceEngine...")

print("[INFO]: Importing Libraries...")
from xai_inference_engine import XAIInferenceEngine
from torchvision.models import resnet50, ResNet50_Weights

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print("[INFO]: Device: {}".format(device))

print("[INFO]: Loading Model...")
# Model
model = resnet50(weights=ResNet50_Weights.IMAGENET1K_V2).to(device)
weights = ResNet50_Weights.DEFAULT
preprocess = weights.transforms()

# Model config
# Set model to eval mode
model.eval()
last_conv_layer = model.layer4[2].conv3
class_count = 5
class_list = weights.meta["categories"]
img_h = 224

print("[INFO]: Image Preprocessing...")
# Image Preprocessing
url = "https://raw.githubusercontent.com/utkuozbulak/pytorch-cnn-visualizations/master/input_images/cat_dog.png"
r = requests.get(url, allow_redirects=True)
open("dog-and-cat-cover.jpg", "wb").write(r.content)
img = Image.open("dog-and-cat-cover.jpg")
img = img.resize((img_h, img_h), resample=Image.BICUBIC)
img_tensor = preprocess(img).to(device)


print("[INFO]: Creating XAIInferenceEngine...")
xai_inferencer = XAIInferenceEngine(
    model=model,
    last_conv_layer=last_conv_layer,
    device=device,
)

print("[INFO]: Running XAIInferenceEngine.predict()...")
preds, sorted_pred_indices, super_imp_img, heatmaps = xai_inferencer.predict(
    img=img,
    img_tensor=img_tensor,
)

print("[INFO]: Saving Results to the root folder...")
super_imp_img.save("super_imp_img.jpg")
heatmaps.save("heatmaps.jpg")

print("[INFO]: Displaying Results...")
print("        Predictions: {}".format(preds.shape))
print("        Sorted Prediction Indices: {}".format(sorted_pred_indices.cpu().numpy()[:10]))
print("        Heatmaps shape: {}".format(heatmaps))
print("        Super Imposed Image: {}".format(super_imp_img))

```
