1
0

2 Incheckningar 6eb09833a3 ... 134f578a30

Upphovsman SHA1 Meddelande Datum
  Zan Klanecek 134f578a30 Merge branch 'master' of https://git0.fmf.uni-lj.si/klanecek/AIM 4 veckor sedan
  Zan Klanecek 53fb877db9 added code for visualizing filters 4 veckor sedan
1 ändrade filer med 18 tillägg och 0 borttagningar
  1. 18 0
      Problem 5/visualize_filters.py

+ 18 - 0
Problem 5/visualize_filters.py

@@ -0,0 +1,18 @@
+from model import ModelCT
+from matplotlib import pyplot as plt
+import torch
+
+# Pseudo code for visualizing filters, adapt as needed
+device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
+
+# Load model
+model = ModelCT()
+model.to(device)
+model.load_state_dict(torch.load("trained_model_weights.pth"))
+model.eval()
+
+# Example of loading filters from the first convolutional layer (backbone.conv1)
+weights = model.backbone.conv1.weight.data.cpu().numpy() # weights.shape = (64,1,7,7) -> 64 filters, 1 channel, size 7x7
+
+# Visualization of 21st filter from the first convolutional layer
+plt.imshow(weights[20,0,:,:], cmap='gray')