Skip to content

Commit

Permalink
Repository clean up for thesis
Browse files Browse the repository at this point in the history
  • Loading branch information
StamatisOrfanos committed Oct 30, 2024
1 parent 4ecd644 commit 89178ff
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ __pycache__
*.aux
*.lof
*.log
*.lot
*.lot
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion src/data_set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import defaultdict
import torch
from torch.utils.data import Dataset
import cv2
import numpy as np
from PIL import Image, ImageDraw

Expand Down
9 changes: 0 additions & 9 deletions src/helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import numpy as np
import torch, statistics
from sklearn.metrics import precision_recall_curve, average_precision_score
import torch
from torch.utils.data import DataLoader
from torchvision.transforms import Compose, ToTensor, Normalize
from torchvision import transforms
from sklearn.metrics import confusion_matrix
import pandas as pd
from datetime import datetime

Expand Down Expand Up @@ -69,10 +65,6 @@ def train(model, train_loader, device, anchors, optimizer, num_epochs, dataset):
# Save model info every 25 epochs to check progress with evaluation
if epoch % 25 == 0 and epoch != 0: torch.save(model, 'results/model_{}_{}.pt'.format(dataset, epoch)) # type: ignore
print('For the epoch:{} the loss is: {}, the precision is: {}, the recall is: {}, the mAP[0.5] is: {} and the mAP[0.5-0.95] is: {}'.format(loss, map['precision'], map['recall'], map['mAP'], mapCOCO['mAP']))






def evaluate_model(model, data_loader, device, anchors):
Expand Down Expand Up @@ -107,4 +99,3 @@ def evaluate_model(model, data_loader, device, anchors):
avg_loss = total_loss / len(data_loader)

return avg_loss

59 changes: 0 additions & 59 deletions test.py

This file was deleted.

82 changes: 41 additions & 41 deletions test/test_extendedmask2former.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@
import torch.nn.functional as F
from src.helpers import train, evaluate_model

# # ------------------------------------------------------------------------------------------------------------------------------------
# # Step 1: Load and preprocess the image
# def load_image(image_path):
# image = Image.open(image_path).convert('RGB')
# transform = transforms.Compose([
# transforms.Resize((600, 600)), # Resize to the input size expected by EfficientNet
# transforms.ToTensor(),
# transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), # Normalization for EfficientNet
# ])
# return transform(image).unsqueeze(0) # type: ignore # Add batch dimension

# image = load_image('/Users/stamatiosorphanos/Documents/MCs_Thesis/SOD_Thesis/docs/Extended_Mask2Former/1.jpg')


# # Step 2: Initialise the Mask2Former Model
# model = ExtendedMask2Former(num_classes=100, hidden_dim=256, num_queries=100, nheads=8, dim_feedforward=2048, dec_layers=1, mask_dim=256)

# # Step 3: Count the number of parameters
# total_params = sum(param.numel() for param in model.parameters())
# print('The total number of Extended Mask2Former parameters are: ', total_params)
# model.eval() # Set the model to evaluation mode

# # Step 4: Pass the image through the model
# with torch.no_grad():
# output = model(image)

# # Step 5: Visualize the feature maps
# print('\nThe predicted classes are the following:\n')
# print(output['pred_logits'])
# ------------------------------------------------------------------------------------------------------------------------------------
# Step 1: Load and preprocess the image
def load_image(image_path):
image = Image.open(image_path).convert('RGB')
transform = transforms.Compose([
transforms.Resize((600, 600)), # Resize to the input size expected by EfficientNet
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), # Normalization for EfficientNet
])
return transform(image).unsqueeze(0) # type: ignore # Add batch dimension

image = load_image('/Users/stamatiosorphanos/Documents/MCs_Thesis/SOD_Thesis/docs/Extended_Mask2Former/1.jpg')


# Step 2: Initialise the Mask2Former Model
model = ExtendedMask2Former(num_classes=100, hidden_dim=256, num_queries=100, nheads=8, dim_feedforward=2048, dec_layers=1, mask_dim=256)

# Step 3: Count the number of parameters
total_params = sum(param.numel() for param in model.parameters())
print('The total number of Extended Mask2Former parameters are: ', total_params)
model.eval() # Set the model to evaluation mode

# Step 4: Pass the image through the model
with torch.no_grad():
output = model(image)

# Step 5: Visualize the feature maps
print('\nThe predicted classes are the following:\n')
print(output['pred_logits'])

# # Step 6: Visualize the mask of the model
# print('\nThe masks with shape: {} created are the following:\n'.format(output['pred_masks'].shape))
# print(output['pred_masks'])
# Step 6: Visualize the mask of the model
print('\nThe masks with shape: {} created are the following:\n'.format(output['pred_masks'].shape))
print(output['pred_masks'])

# # Step 7: Visualize the bounding box of the model
# print('\nThe bounding box with shape: {} created is the following:\n'.format(output['bounding_box'].shape))
# print(output['bounding_box'])
# Step 7: Visualize the bounding box of the model
print('\nThe bounding box with shape: {} created is the following:\n'.format(output['bounding_box'].shape))
print(output['bounding_box'])

# # Step 8: Visualize the class scores
# print('\nThe class scores with shape: {} created are the following:\n'.format(output['class_scores'].shape))
# print(output['class_scores'])
# Step 8: Visualize the class scores
print('\nThe class scores with shape: {} created are the following:\n'.format(output['class_scores'].shape))
print(output['class_scores'])

# # # Step 9: Get the summary of the EFPN model
# # print('\n\nThe summary of the EFPN model is the following: \n', model)
# # ------------------------------------------------------------------------------------------------------------------------------------
# Step 9: Get the summary of the EFPN model
print('\n\nThe summary of the EFPN model is the following: \n', model)
# ------------------------------------------------------------------------------------------------------------------------------------


# Import data paths
Expand Down

0 comments on commit 89178ff

Please sign in to comment.