This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _autoLabel(self, img, rects, masks): | |
with open(self._via_export_json, 'r') as fr: | |
json_file = json.load(fr) | |
regions = [] | |
N = len(rects) | |
for i in range(N): | |
mask = masks[..., i] | |
mask = np.where(mask, 255, 0).astype(np.uint8) | |
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Object Detection using MaskRCNN | |
def MaskRCNNDetection(self, frame, epsilon=None, auto_mask=True): | |
''' | |
Detects objects in frame by masking them. | |
:param frame: An image in BGR format. | |
:type frame: :class:`numpy.ndarray` | |
:param None epsilon: Used only to have consistency. | |
Not used in the algorithm. | |
:param bool auto_mask: Should the system perform auto-masking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
display_FP_FN(model, test_loader, criterion = nn.CrossEntropyLoss(), display = 'fn') | |
get_confusion_matrix(y_truth, y_proba, labels = [0, 1]) | |
plot_ROCAUC_curve(y_truth, y_proba, (8, 8)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# performance on test data | |
def test(model, test_loader, criterion): | |
''' | |
Model testing | |
Args: | |
model: model used during training and validation | |
test_loader: data loader object containing testing data | |
criterion: loss function used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save model | |
PATH = ".\ViTModel.pt" # Use your own path | |
torch.save(model.state_dict(), PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
efficient_transformer = Linformer( | |
dim=128,#128 | |
seq_len=49+1, # 7x7 patches + 1 cls-token | |
depth=12, | |
heads=8, | |
k=64 | |
) | |
model = ViT( | |
dim=128, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ### Image Augmentation | |
#Tune the transforms | |
ORIG_RES = False | |
if ORIG_RES: | |
resize = 512 | |
else: | |
resize = 224 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
device = 'cpu' | |
os.makedirs('lung_ct_scan_data', exist_ok=True) | |
train_dir = 'lung_ct_scan_data/train' | |
test_dir = 'lung_ct_scan_data/test' | |
train_list = glob.glob(os.path.join(train_dir,'*.png')) + glob.glob(os.path.join(train_dir,'*.jpg')) | |
test_list = glob.glob(os.path.join(test_dir, '*.png')) + glob.glob(os.path.join(test_dir, '*.jpg')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Training settings | |
batch_size = 64 | |
epochs = 20 | |
lr = 3e-5 | |
gamma = 0.7 | |
seed = 142 | |
IMG_SIZE = 224 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import glob | |
from itertools import chain | |
import os | |
import random | |
import zipfile | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import torch |
NewerOlder