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
""" | |
This method uses the max pooling operation to get the boundary around a binary mask | |
Can be used in segmentation tasks where one wants to specific a loss for the boundary pixels/voxels | |
""" | |
import os | |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | |
import nrrd | |
import numpy as np | |
import tensorflow as tf |
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
import os | |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | |
import tensorflow as tf # v2.4 with CUDA11.0.0 & CuDNN8.0.0 | |
import tensorflow_probability as tfp # v0.12.1 | |
if len(tf.config.list_physical_devices('GPU')):tf.config.experimental.set_memory_growth(tf.config.list_physical_devices('GPU')[0], True) | |
x = tf.random.normal((1,100,100,100,10)) # B, H,W,D,C | |
layer = tfp.layers.Convolution3DFlipout(filters=16, kernel_size=1) |
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
""" | |
Expected Calibration Error for semantic segmentation tasks | |
""" | |
import pdb | |
import nrrd # pip install pynrrd | |
import traceback | |
import numpy as np | |
from pathlib import Path | |
import matplotlib.pyplot as plt |
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
import numpy as np | |
import matplotlib.pyplot as plt | |
f,axarr = plt.subplots(1,2) | |
# Step 1 | |
x = [0.01, 0.02, 0.03, 0.04] + np.arange(0.05,1.05,0.05).tolist() | |
y_ce = [-np.log(each) for each in x] | |
y_focal1 = [-1*(1 - each)**1*np.log(each) for each in x] | |
y_focal2 = [-1*(1 - each)**2*np.log(each) for each in x] |
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
import itk | |
import SimpleITK as sitk | |
def convert_sitk_to_itk(sitk_img): | |
img_array = sitk.GetArrayFromImage(sitk_img) | |
itk_img = itk.GetImageFromArray(img_array) | |
itk_img.SetOrigin(tuple(sitk_img.GetOrigin())) | |
itk_img.SetSpacing(tuple(sitk_img.GetSpacing())) | |
itk_img.SetDirection(itk.GetMatrixFromArray(np.reshape(np.array(sitk_img.GetDirection()), [sitk_img.GetDimension()]*2))) |
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
Feature | AnatomyNet | FocusNet | StratifiedNet | DeepMindNet | |
---|---|---|---|---|---|
Input | 3D Volume | 3D volume | 3D Sub-Volume | 3D Sub-Volume | |
Crop Info | 178×302×225 | N/A | 128x128x64 | 512x512x21 | |
Training Data | 38(MICCAI) + 46(Cetuximab) + 177 (Quebec) | 38(MICCAI) | 38(MICCAI) | 663 (Private dataset) | |
Augmentation | Affine + Elastic | N/A | Scaling | 2D Augmentations | |
Architecture | 3D UNet-variant | 3D UNet-variant | P-HNN | 3D UNet-variant | |
Additional Blocks | Squeeze-Excitation Residual Blocks | Squeeze-Excitation Residual Blocks + DenseASPP | NAS | Deptwise-Separable Convs | |
Cascaded Architecture | No | Yes (for smaller optic organs) | Yes (from anchor to small organs) | No | |
Downsampling | Dim/2 | Dim/2 | N/A | Dim/64 | |
Final Activation | softmax | N/A | N/A | Sigmoid |
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
class HaNMICCAI2015Dataset: | |
def __init__(): | |
# initialize map, filter parameters | |
def generator(): | |
# define generator, map and filter functions | |
batchsize = None # user defined value | |
prefetch_buffer = None # user defined value | |
shuffle_buffer = None # user defined value |
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 test(num1, num2): | |
return num1/num2 | |
num = 1 | |
den = 2 | |
import timeit | |
t = timeit.timeit(lambda: test(num, den), number=5) |
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 pathlib import Path | |
import itk | |
import SimpleITK as sitk | |
config = { | |
'transform' : { | |
'affine': 'AffineTransform' | |
, 'bspline': 'BSplineTransform' | |
} |
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
import time | |
import tqdm | |
import numpy as np | |
import concurrent | |
import concurrent.futures | |
def rand_func(param): | |
time.sleep(3) | |
print (param) |