Skip to content

Instantly share code, notes, and snippets.

View McSpooder's full-sized avatar
🎯
Focusing

Daniel Wilde McSpooder

🎯
Focusing
View GitHub Profile
def X_Y_df_split(in_df):
X_df = in_df.drop(columns=['fun', 'valuable', 'exciting', 'awesome', 'cool'], axis=1)
Y_df = in_df.drop(columns=['id', 'comment_text'], axis=1)
return (X_df, Y_df)
import matplotlib.pyplot as plt
import nibabel as nib
def show_image(image):
plt.imshow(image)
fig = plt.figure()
mri = nib.load("path_to_mri_scan\\mri_volume.nii").get_fdata()
mri.shape
@McSpooder
McSpooder / Loading in the clinical data
Last active July 22, 2020 13:26
Neural Network Blocks - ConvBlock
class ConvBlock(nn.Module):
def __init__(self, c_in, c_out, ks, k_stride=1):
super().__init__()
self.conv1 = nn.Conv3d(c_in, c_out, ks, stride=k_stride, padding=(1,1,1))
self.bn = nn.BatchNorm3d(c_out)
self.elu = nn.ELU()
self.pool = nn.MaxPool3d(kernel_size=(3,3,3), stride=2)
@McSpooder
McSpooder / gist:b4133763a5c3f073364ddd637bc3f2f9
Created July 22, 2020 13:39
Connection skips - addition
identity = out
out = self.layer(out)
out = out + identity
@McSpooder
McSpooder / gist:6a26788367d05bfce2ed4924f5d2f0d2
Created July 22, 2020 13:41
Connection skips - Concatenation
out_a = self.stack3_a(out_a)
out_b = self.stack3_b(out_b)
out = torch.cat((out_a, out_b), 1)
@McSpooder
McSpooder / Understanding the clinical data
Created July 22, 2020 18:17
Understanding the clinical data
import seaborn as sns
import pandas as pd
import matplotlib as plt
clin = pd.read_csv("./bas_clin_with_categorical.csv")
clin.head()
@McSpooder
McSpooder / seaborn visualization
Created July 22, 2020 18:28
normal distributions of each label
sMCI_df = clin[clin["label"] == "sMCI"]
pMCI_df = clin[clin["label"] == "pMCI"]
kde_kws = {"color": "orange", "lw": 2, "label": "sMCI", "shade":True}
sns.distplot(sMCI_df["AGE"], kde_kws=kde_kws, hist=False)
kde_kws = {"color": "red", "lw": 2, "label": "pMCI", "shade":True}
sns.distplot(pMCI_df["AGE"], color="magenta", kde_kws=kde_kws, hist=False)
@McSpooder
McSpooder / DataLoader
Created July 22, 2020 18:35
Pytorch data loader
class MRIDataset(Dataset):
def __init__(self, root_dir, labels, transform=None):
self.root_dir = root_dir
self.transform = transform
self.directories = []
self.len = 0
self.labels = labels
@McSpooder
McSpooder / get item
Created July 22, 2020 18:46
get item method
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
repeat = True
while(repeat):
try:
path = self.directories[idx]