<jupyter_start><jupyter_text>import models<jupyter_code>synth_model = ConvDropoutNet(in_channels=3, n_classes=2).to(device)
synth_model.load_state_dict(torch.load('models/synthetic_model.pth'))

real_model = make_resnet18(num_classes=2).to(device)
real_model.load_state_dict(torch.load('models/real_model.pth'))<jupyter_output><empty_output><jupyter_text>load images<jupyter_code># load images
synth_images, synth_labels = load_images('data/SyntheticDataset', verbose=False)
real_images, real_labels = load_images('data/RealDataset', verbose=False)
# train/test split
_, synth_test_img, _, synth_test_label = train_test_split(
    synth_images, synth_labels, test_size=0.20, random_state=42,
)
_, real_test_img, _, real_test_label = train_test_split(
    real_images, real_labels, test_size=0.20, random_state=42,
)
# image transformation
transform = transforms.Compose([
    Unsqueeze(axis=-1),
    Repeat(n_channel=3, axis=-1),
    transforms.ToTensor(),
])
# make datasets

# synthetic
synth_test_dataset = MRIDataset(
    images=synth_test_img,
    labels=synth_test_label,
    transform=transform,
)

# real
real_test_dataset = MRIDataset(
    images=real_test_img,
    labels=real_test_label,
    transform=transform,
)
# make dataloaders

# synthetic
synth_test_loader = DataLoader(
    synth_test_dataset,
    batch_size=128,
    shuffle=False,
)

# real
real_test_loader = DataLoader(
    real_test_dataset,
    batch_size=128,
    shuffle=False,
)<jupyter_output><empty_output><jupyter_text>explain synthetic model<jupyter_code>batch = next(iter(synth_test_loader))
images, _ = batch
images = images.to(device)
shap_deep_explainer(
    model=synth_model,
    background = images[:100],
    test_images = images[100:103],
)<jupyter_output><empty_output><jupyter_text>explain real model<jupyter_code>batch = next(iter(real_test_loader))
images, _ = batch
images = images.to(device)
shap_deep_explainer(
    model=real_model,
    background = images[:100],
    test_images = images[100:103],
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11330049261083744, 'fraction_numerical': 0.020689655172413793, 'mean_word_length': 6.841698841698841, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '557705', 'license': 'MIT', 'n_tokens_mistral': 772, 'n_tokens_neox': 740, 'n_words': 100, 'path': 'solution/shap.ipynb', 'repo_name': 'dayyass/synthetic_health_data_hackathon_2020', 'size': '2030'}