This file contains hidden or 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
| import miptools as mt | |
| #metadata windowing | |
| mt.preprocess('./data/test.dcm', org='brain', windowing='simple', resample=False, visualize=True) | |
| #bsb windowing | |
| mt.preprocess('./data/test.dcm', org='brain', windowing='bsb', resample=False, visualize=True) | |
| #sigmoid windowing | |
| mt.preprocess('./data/test.dcm', org='brain', windowing='sigmoid', resample=False, visualize=True) |
This file contains hidden or 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
| #***********************# | |
| #***Code by:************# | |
| #***Chi Nok Enoch Kan***# | |
| #***********************# | |
| #*******<(^.^)>*********# | |
| #***********************# | |
| #*****Encoder Block*****# | |
| #***********************# | |
| #***********************# | |
| #***********************# |
This file contains hidden or 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
| # --------------------- | |
| # Train Discriminator, only update every disc_update batches | |
| # --------------------- | |
| # Real loss | |
| fake_B = generator(real_A) | |
| pred_real = discriminator(real_B, real_A) | |
| loss_real = criterion_GAN(pred_real, valid) | |
| # Fake loss | |
| pred_fake = discriminator(fake_B.detach(), real_A) |
This file contains hidden or 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
| class diceloss(torch.nn.Module): | |
| def init(self): | |
| super(diceLoss, self).init() | |
| def forward(self,pred, target): | |
| smooth = 1. | |
| iflat = pred.contiguous().view(-1) | |
| tflat = target.contiguous().view(-1) | |
| intersection = (iflat * tflat).sum() | |
| A_sum = torch.sum(iflat * iflat) | |
| B_sum = torch.sum(tflat * tflat) |
This file contains hidden or 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
| class GeneratorUNet(nn.Module): | |
| def __init__(self, in_channels=1, out_channels=1): | |
| super(GeneratorUNet, self).__init__() | |
| self.down1 = UNetDown(in_channels, 64, normalize=False) | |
| self.down2 = UNetDown(64, 128) | |
| self.down3 = UNetDown(128, 256) | |
| self.down4 = UNetDown(256, 512) | |
| self.mid1 = UNetMid(1024, 512, dropout=0.2) | |
| self.mid2 = UNetMid(1024, 512, dropout=0.2) |
This file contains hidden or 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 torch_metrics import MSEMetric, MAEMetric, RSquaredMetric | |
| import torch | |
| metric = MSEMetric() | |
| t1 = torch.tensor([1., 2., 3.]) | |
| t2 = torch.tensor([1., 5., 25.]) | |
| print(metric(t1, t2)) |
This file contains hidden or 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
| import numpy as np | |
| class AdamOptim(): | |
| def __init__(self, eta=0.01, beta1=0.9, beta2=0.999, epsilon=1e-8): | |
| self.m_dw, self.v_dw = 0, 0 | |
| self.m_db, self.v_db = 0, 0 | |
| self.beta1 = beta1 | |
| self.beta2 = beta2 | |
| self.epsilon = epsilon | |
| self.eta = eta | |
| def update(self, t, w, b, dw, db): |
This file contains hidden or 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 loss_function(m): | |
| return m**2-2*m+1 | |
| ## take derivative | |
| def grad_function(m): | |
| return 2*m-2 | |
| def check_convergence(w0, w1): | |
| return (w0 == w1) |
This file contains hidden or 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
| w_0 = 0 | |
| b_0 = 0 | |
| adam = AdamOptim() | |
| t = 1 | |
| converged = False | |
| while not converged: | |
| dw = grad_function(w_0) | |
| db = grad_function(b_0) | |
| w_0_old = w_0 |