2 Комити 6eb09833a3 ... 134f578a30

Аутор SHA1 Порука Датум
  Zan Klanecek 134f578a30 Merge branch 'master' of https://git0.fmf.uni-lj.si/klanecek/AIM пре 4 недеља
  Zan Klanecek 53fb877db9 added code for visualizing filters пре 4 недеља
1 измењених фајлова са 18 додато и 0 уклоњено
  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')