<jupyter_start><jupyter_text>Quiz Model<jupyter_code>from models.QuizDNN import QuizDNN
transform_album = album_compose()
# View model config
args = ModelConfig(transform_album)
args.print_config()

print()
# Set seed
init_seed(args)
data = DataEngine(args)

# get some random training images
dataiter = iter(data.train_loader)
images, labels = dataiter.next()

# show images
imshow(torchvision.utils.make_grid(images[:4]))
# print labels
print(' '.join('%5s' % data.classes[labels[j]] for j in range(4)))
device = which_device()
# model = Net(args).to(device)
# model = ResNet18().to(device)
model = QuizDNN().to(device)
show_model_summary(model, device, (3,32,32))
from torch.optim.lr_scheduler import StepLR,OneCycleLR
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9, weight_decay=0.001)
scheduler = StepLR(optimizer, step_size=8, gamma=0.1)
# scheduler = OneCycleLR(optimizer,max_lr=0.1,total_steps=20)
trainer = Trainer(model, 
                  device,
                  train_loader=data.train_loader, 
                  test_loader = data.test_loader, 
                  optimizer = optimizer, 
                  loss_func = criterion, 
                  lr_scheduler = None) 
(train_loss, train_acc, test_loss, test_acc) = trainer.train_model(epochs=40, lambda_l1=0.0001)
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog',
			'frog', 'horse', 'ship', 'truck')
trainer.classwise_acc(classes)
misclassified_imgs = trainer.get_misclassified()
plot_misclassified_images(misclassified_imgs, classes, "misclassified_images1.png")
from results import plot_metrics
plot_metrics(train_loss, train_acc, test_loss, test_acc)
dataiter = iter(data.test_loader)
images, labels = dataiter.next()
for name, layer in model.named_modules():
  if isinstance(layer, torch.nn.Conv2d):
    print(name, layer)
import PIL
import numpy as np
def plot_images_gradcam(torch_img,normed_torch_img, model):
    images=[]
    g1 = GradCAM(model, model.convblock9)
    g2 = GradCAM(model, model.convblock8)
    g3 = GradCAM(model, model.convblock7)
    g4 = GradCAM(model, model.convblock6)
    mask1, _ = g1(normed_torch_img)
    mask2, _ = g2(normed_torch_img)
    mask3, _ = g3(normed_torch_img)
    mask4, _ = g4(normed_torch_img)
    heatmap1, result1 = visualize_cam(mask1, torch_img)
    heatmap2, result2 = visualize_cam(mask2, torch_img)
    heatmap3, result3 = visualize_cam(mask3, torch_img)
    heatmap4, result4 = visualize_cam(mask4, torch_img)

    images.extend([torch_img.cpu(), heatmap1, heatmap2, heatmap3, heatmap4])
    images.extend([torch_img.cpu(), result1, result2, result3, result4])
    grid_image = make_grid(images, nrow=5)
    imshow(grid_image)
trans = transforms.ToPILImage()
pil_img=trans(torchvision.utils.make_grid(images[1]))
torch_img,normed_torch_img=change(pil_img,device)
plot_images_gradcam(torch_img,normed_torch_img, model)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12252559726962457, 'fraction_numerical': 0.025597269624573378, 'mean_word_length': 5.080912863070539, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '317631', 'license': 'MIT', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1049, 'n_words': 193, 'path': 'week-9/s9_quiz.ipynb', 'repo_name': 'vamsigp/EVA5', 'size': '2930'}