22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Capturing Outputs

featurizer_layers = ['conv1', 'relu1', 'maxp1', 'flatten']

classifier_layers = ['fc1', 'relu2', 'fc2']

sbs_cnn1.attach_hooks(

layers_to_hook=featurizer_layers + classifier_layers

)

images_batch, labels_batch = iter(val_loader).next()

logits = sbs_cnn1.predict(images_batch)

predicted = np.argmax(logits, 1)

sbs_cnn1.remove_hooks()

Visualizing Feature Maps

with plt.style.context('seaborn-white'):

fig_maps1 = sbs_cnn1.visualize_outputs(featurizer_layers)

fig_maps2 = sbs_cnn1.visualize_outputs(

classifier_layers, y=labels_batch, yhat=predicted

)

Evaluating Accuracy

StepByStep.loader_apply(sbs_cnn1.val_loader, sbs_cnn1.correct)

Output

tensor([[59, 67],

[55, 62],

[71, 71]])

Putting It All Together | 413

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!