keyword stringclasses 7
values | repo_name stringlengths 8 98 | file_path stringlengths 4 244 | file_extension stringclasses 29
values | file_size int64 0 84.1M | line_count int64 0 1.6M | content stringlengths 1 84.1M ⌀ | language stringclasses 14
values |
|---|---|---|---|---|---|---|---|
3D | john-drago/fluoro | code/datacomp/coord_change.py | .py | 19,493 | 577 | '''
This script is meant to accomplish four things, all about transforming between coordinate systems.
1) Transform from local coordinate system to global coordinate system.
- func: Local2Global_Coord
2) Transform from globabl coordinate system to local coordinate system.
- func: Global2Local_Coord
3) If given... | Python |
3D | john-drago/fluoro | code/datacomp/data_compile_from_source.py | .py | 12,354 | 336 |
'''
The purpose of this file is to organize the matched frames by compiling: (1) two .png fluoroscopic images and (2) the .mat file
with the results of the matching.
To accomplish this, first adjust the following variables at the top of the file:
- new_dir_name
- activity_to_copy
- dir_parse_list
- replacement_la... | Python |
3D | john-drago/fluoro | code/datacomp/h5py_multidimensional_array.py | .py | 27,688 | 742 | '''
This file is developed to help deal with saving multidimensional arrays (4-D) that have variable last three-dimensions. This file is meant to help store variable voxel data sets with a variety of sizes.
'''
import numpy as np
import h5py
import math
import os
import tempfile
def matrix_unwrapper_3d(matrix):
... | Python |
3D | john-drago/fluoro | code/datacomp/voxel_graph.py | .py | 2,370 | 69 | '''
This file will allow us to roughly graph voxel data for visualization using mayavi.
'''
import mayavi.mlab as mlab
# from data_organization import extract_stl_femur_tib
import numpy as np
import h5py
import h5py_multidimensional_array
# path_to_dir = '/Users/johndrago/fluoro/data/Gait Updated/CR 01/Lt'
# fib_ti... | Python |
3D | john-drago/fluoro | code/datacomp/data_augmentation.py | .py | 56,997 | 1,479 | '''
This function will perform data augmentation on our current data set. Basically, we will do small translations and rotations on our voxel dataset to increase the number of instances we are currently training with.
'''
import os
import scipy.io as sio
import skimage
import numpy as np
import trimesh
import pandas a... | Python |
3D | john-drago/fluoro | code/datacomp/mesh_voxelization.py | .py | 6,116 | 165 | '''
This file will be used to generate voxel data sets from the meshes by voxelizing the vertices.
The high level overview is that we need to supply a list of directory paths to where the stl files are housed. We will then extract the vertices data, and we will create voxels in this file.
'''
import os
from coord_cha... | Python |
3D | john-drago/fluoro | code/scratch/unsup_segmentation_draft.py | .py | 6,619 | 136 | import numpy as np
import os
import skimage.io as io
import skimage.transform as trans
import numpy as np
from keras.models import *
from keras.layers import *
from keras.optimizers import *
from keras.callbacks import ModelCheckpoint, LearningRateScheduler
import keras
import sys
expr_name = sys.argv[0][:-3]
expr_n... | Python |
3D | john-drago/fluoro | code/scratch/graphical_rotation_of_frame.py | .py | 1,203 | 41 | import numpy as np
from numpy import *
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d
class Arrow3D(FancyArrowPatch):
def __init__(self, xs, ys, zs, *args, **kwargs):
FancyArrowPatch.__init... | Python |
3D | john-drago/fluoro | code/scratch/unsup_segmentation.py | .py | 24,536 | 483 | import numpy as np
import h5py
import tensorflow as tf
import keras
import os
import sys
from sklearn.model_selection import train_test_split
from sklearn.cluster import KMeans
expr_name = sys.argv[0][:-3]
expr_no = '2'
save_dir = os.path.abspath(os.path.join(os.path.expanduser('~/fluoro/code/scratch/unsup_seg'), exp... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/coord_conv.py | .py | 267 | 15 | # -*- coding: utf-8 -*-
import numpy as np
def cart2pol(x,y):
rho=np.sqrt(x**2+y**2)
phi=np.arctan2(y,x)
phi=phi*(180/np.pi)
return(rho,phi)
def pol2cart(rho, phi):
phi=phi*(np.pi/180)
x=rho*np.cos(phi)
y=rho*np.sin(phi)
return(x,y) | Python |
3D | aAbdz/CylShapeDecomposition | CSD/skeleton_decomposition.py | .py | 11,339 | 376 | # -*- coding: utf-8 -*-
import numpy as np
from skeleton3D import get_line_length
import collections
def skeleton_main_branch(skel):
main_skeletons = []
n_branch = len(skel)
nodes_coord, branch_length = skeleton_info(skel)
longest_branch = np.argmax(np.array(branch_length))
gr... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/shape_decomposition.py | .py | 19,224 | 573 | # -*- coding: utf-8 -*-
import numpy as np
import plane_rotation as pr
from scipy.interpolate import RegularGridInterpolator as rgi
from unit_tangent_vector import unit_tangent_vector
from hausdorff_distance import hausdorff_distance
from skimage.measure import label, regionprops
from skeleton_decomposition import ske... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/skeleton3D.py | .py | 7,991 | 304 | # -*- coding: utf-8 -*-
import numpy as np
import skfmm
import sys
def discrete_shortest_path(D,start_point):
sz = D.shape
x = [0, 1,-1, 0, 0, 1, 1,-1,-1, 0, 1,-1, 0, 0, 1, 1,-1,-1, 1,-1, 0, 0, 1, 1,-1,-1]
y = [0, 0, 0, 1,-1, 1,-1, 1,-1, 0, 0, 0, 1,-1, 1,-1, 1,-1, 0, 0, 1,-1, 1,-1, 1,-1]
z ... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/plane_rotation.py | .py | 1,117 | 41 | # -*- coding: utf-8 -*-
import numpy as np
def rotate_vector(vector, rot_mat):
"rotating a vector by a rotation matrix"
rotated_vec = np.dot(vector,rot_mat)
return rotated_vec
def rotation_matrix_3D(vector, theta):
"""counterclockwise rotation about a unit vector by theta radians using
... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/hausdorff_distance.py | .py | 425 | 13 | # -*- coding: utf-8 -*-
import numpy as np
from scipy.spatial.distance import directed_hausdorff
def hausdorff_distance(curve1,curve2,n_sampling):
s1=np.floor(np.linspace(0,len(curve1)-1,n_sampling)).astype(int)
s2=np.floor(np.linspace(0,len(curve2)-1,n_sampling)).astype(int)
u=curve1[s1]
v=curv... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/polar_interpolation.py | .py | 956 | 40 | # -*- coding: utf-8 -*-
import numpy as np
from coord_conv import cart2pol, pol2cart
from scipy.interpolate import interp1d
def polar_interpolation(curve, c_mesh):
r,phi = cart2pol(curve[:,1]-c_mesh,curve[:,0]-c_mesh)
s_phi = phi; s_phi[1:] = phi[1:] + 0.0001
sign_change=np.where((s_phi[1:]*s_phi... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/polar_parametrization.py | .py | 1,161 | 40 | # -*- coding: utf-8 -*-
import numpy as np
from coord_conv import cart2pol, pol2cart
def polar_parametrization(curve, c_mesh):
r,phi = cart2pol(curve[:,1]-c_mesh,curve[:,0]-c_mesh)
s=phi<0
s_inx=np.where(s)[0]
s_inx=s_inx[np.argmin(abs(phi[s_inx]))]
nphi=np.append(phi[s_inx:],phi[:s_inx])
... | Python |
3D | aAbdz/CylShapeDecomposition | CSD/unit_tangent_vector.py | .py | 298 | 14 | # -*- coding: utf-8 -*-
import numpy as np
def unit_tangent_vector(curve):
d_curve = np.gradient(curve, axis=0)
ds = np.expand_dims((np.sum(d_curve**2, axis=1))**0.5, axis=1)
ds[ds==0] = 1e-5
u_tang_vec = d_curve/np.repeat(ds, curve.shape[1], axis=1)
return u_tang_vec
| Python |
3D | kkhuang1990/PlaqueDetection | lr_scheduler.py | .py | 572 | 18 | # _*_ coding: utf-8 _*_
""" define custom learning rate scheduler """
from __future__ import print_function
from torch.optim.lr_scheduler import _LRScheduler
class PolyLR(_LRScheduler):
""" poly learning rate scheduler """
def __init__(self, optimizer, max_iter=100, power=0.9, last_epoch=-1):
self.m... | Python |
3D | kkhuang1990/PlaqueDetection | snake.py | .py | 3,786 | 95 | # _*_ coding: utf-8 _*_
""" use morphological operations and Snake to obtain single-pixel contour
from prediction results
"""
import matplotlib as mpl
mpl.use('Agg')
import torch
from torch.autograd import Variable
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning, module='scipy')
import num... | Python |
3D | kkhuang1990/PlaqueDetection | loss.py | .py | 54,878 | 1,255 | # _*_ coding: utf-8 _*_
""" define custom loss functions """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import torch
from torch.autograd import Variable
from torch import nn
import torch.nn.functional as F
from torch.autograd import Function
from torch.nn import CrossEntropyLoss
from sk... | Python |
3D | kkhuang1990/PlaqueDetection | metric.py | .py | 15,092 | 417 | # _*_ coding: utf-8 _*_
""" metrics used to evaluate the performance of our approach """
from sklearn.preprocessing import label_binarize
from sklearn.metrics import f1_score
import warnings
warnings.filterwarnings('ignore', module='sklearn') # omit sklearn warning
import torch
import numpy as np
from sklearn.metric... | Python |
3D | kkhuang1990/PlaqueDetection | __init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | vision.py | .py | 42,317 | 920 | # _*_ coding: utf-8 _*_
""" functions for visualization """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from utils import mask2rgb
from sklearn.metrics import average_precision_score
from sklearn.metrics import precision_recall_curve
from metric import cal_f_score
import numpy as np
imp... | Python |
3D | kkhuang1990/PlaqueDetection | operation.py | .py | 40,489 | 856 | # _*_ coding: utf-8 _*_
""" calculate risk statistics and HU value statistics of the whole data set
this part is not directly used in training our network
"""
import matplotlib as mpl
mpl.use('Agg')
from image.transforms import Intercept
import matplotlib.pyplot as plt
import os
import os.path as osp
from os i... | Python |
3D | kkhuang1990/PlaqueDetection | utils.py | .py | 12,990 | 395 | # _*_ coding: utf-8 _*_
""" Often used functions for data loading and visualisation """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore', category=RuntimeWarning, module='scipy')
import numpy as np
from sklearn.preprocessing import label_binari... | Python |
3D | kkhuang1990/PlaqueDetection | playground.py | .py | 93 | 5 | # _*_ coding: utf-8 _*_
""" playground for debug
you can check functions freely here
""" | Python |
3D | kkhuang1990/PlaqueDetection | BoundDetection/train.py | .py | 27,444 | 555 | # _*_ coding: utf-8 _*_
""" define train and test functions here """
import matplotlib as mpl
mpl.use('Agg')
import imageio
import warnings
warnings.filterwarnings('ignore', module='imageio')
import sys
sys.path.append("..")
import matplotlib.pyplot as plt
from sklearn.metrics import auc
import copy
from collectio... | Python |
3D | kkhuang1990/PlaqueDetection | BoundDetection/main.sh | .sh | 4,401 | 110 | #!/bin/bash
# input/output
OUTPUT_CHANNEL=3
BOUND_OUTPUT='True'
# For output_channel=2, [inner, outer, innerouter] is available, for output_channel=3, only innerouter is available
BOUND_TYPE='innerouter'
WIDTH=1 # boundary width
#DATA_DIR="/home/mil/huang/Dataset/CPR_multiview"
#DATA_DIR="/data/ugui0/antonio-t/CPR_mul... | Shell |
3D | kkhuang1990/PlaqueDetection | BoundDetection/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | BoundDetection/main.py | .py | 20,753 | 382 | # _*_ coding: utf-8 _*_
""" main code for train and test U-Net """
from __future__ import print_function
import sys
sys.path.append("..")
import numpy as np
import time
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.optim as optim
import argparse
import shutil
from loss import d... | Python |
3D | kkhuang1990/PlaqueDetection | volume/train.py | .py | 25,288 | 528 | # _*_ coding: utf-8 _*_
""" define train and test functions here """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import sys
sys.path.append("..")
from sklearn.metrics import auc
import copy
from collections import Counter
import numpy as np
np.set_printoptions(precision=4)
from tqdm impo... | Python |
3D | kkhuang1990/PlaqueDetection | volume/main.sh | .sh | 3,449 | 96 | #!/bin/bash
# input/output
OUTPUT_CHANNEL=3
BOUND_OUTPUT='False'
WIDTH=1 # boundary width
#DATA_DIR="/home/mil/huang/Dataset/CPR_multiview"
DATA_DIR="/data/ugui0/antonio-t/CPR_multiview_interp2_huang"
# Experiment
EXPERIMENT="Experiment1"
SUB_FOLDER="Res-UNet_CE_3class"
# optimizer
LR_SCHEDULER='StepLR'
MOMENTUM=0.9... | Shell |
3D | kkhuang1990/PlaqueDetection | volume/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | volume/main.py | .py | 17,494 | 348 | # _*_ coding: utf-8 _*_
""" main code for train and test U-Net """
from __future__ import print_function
import os, sys
sys.path.append("..")
import numpy as np
import time
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.optim as optim
import argparse
import shutil
from loss impo... | Python |
3D | kkhuang1990/PlaqueDetection | volume/dataloader.py | .py | 16,652 | 360 | # _*_ coding: utf-8 _*_
""" functions used to load images and masks """
import matplotlib as mpl
mpl.use('Agg')
import os
import os.path as osp
from os import listdir
import random
import torch
import numpy as np
from torch.utils.data import Dataset, DataLoader
import time
from skimage import io
from skimage import ... | Python |
3D | kkhuang1990/PlaqueDetection | volume/transforms.py | .py | 14,554 | 440 | # _*_ coding: utf-8 _*_
""" transforms for 3D volume """
import torch
from skimage import transform
import numpy as np
import random
import warnings
import cv2
from scipy import ndimage
from sklearn.preprocessing import label_binarize
from utils import hu2lut, gray2mask, central_crop, hu2lut, hu2gray
from utils impo... | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/res_unet.py | .py | 5,131 | 144 | # coding = utf-8
""" define the U-Net structure """
import torch
from torch import nn
from .utils import _initialize_weights
def conv_333(in_channels, out_channels, stride=1):
return nn.Conv3d(in_channels, out_channels, kernel_size=3, stride=stride,
padding=1, bias=True)
class ResBlock(nn.M... | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/unet.py | .py | 3,945 | 110 | # _*_ coding: utf-8 _*_
""" 3D U-Net for semantic segmentation """
import torch
from torch import nn
from .utils import _initialize_weights
class ConvBlock(nn.Sequential):
""" Convolution Block """
def __init__(self, in_channels, out_channels):
super().__init__()
self.add_module('conv1', nn.Co... | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/tiramisu.py | .py | 8,943 | 233 | # _*_ coding: utf-8 _*_
import torch
import torch.nn as nn
from .utils import _initialize_weights
class DenseLayer(nn.Sequential):
""" Basic dense layer of DenseNet """
def __init__(self, in_channels, growth_rate):
super().__init__()
self.add_module('norm', nn.BatchNorm3d(in_channels))
... | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/utils.py | .py | 503 | 16 | # _*_ coding: utf-8 _*_
from torch import nn
def count_parameters(model):
""" count number of parameters """
return sum(p.numel() for p in model.parameters() if p.requires_grad)
def _initialize_weights(model):
""" model weight initialization """
for m in model.modules():
if isinstance(m, (nn.... | Python |
3D | kkhuang1990/PlaqueDetection | volume/models/hyper_tiramisu.py | .py | 11,797 | 305 | # _*_ coding: utf-8 _*_
""" implemented the Fully Convolution HyperDenseNet for semantic segmentation """
import torch
import torch.nn as nn
from .utils import _initialize_weights
class DenseLayer(nn.Sequential):
""" Basic dense layer of DenseNet """
def __init__(self, in_channels, growth_rate):
supe... | Python |
3D | kkhuang1990/PlaqueDetection | image/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | image/dataloader.py | .py | 26,076 | 560 | # _*_ coding: utf-8 _*_
""" Load data using hard mining, which means only load data whose segmentation accuracy is lower than the threshold
obtained from the previous epoch.
"""
import matplotlib as mpl
mpl.use('Agg')
import random
import os
import os.path as osp
from os import listdir
import numpy as np
import tim... | Python |
3D | kkhuang1990/PlaqueDetection | image/transforms.py | .py | 13,836 | 447 | # _*_ coding: utf-8 _*_
""" different types of transforms """
from skimage import transform
import torch
import random
import warnings
import cv2
from os import listdir
import os
import os.path as osp
from skimage.transform import rotate
from skimage import io
import numpy as np
import shutil
from utils import hu2lut... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/deeplab_resnet.py | .py | 13,971 | 386 | # _*_ coding: utf-8 _*_
""" implement DeepLab v2 in pytorch """
import torch.nn as nn
import torch
import numpy as np
affine_par = True
import torch.nn.functional as F
from torchvision.models import ResNet
def outS(i):
i = int(i)
i = (i+1)/2
i = int(np.ceil((i+1)/2.0))
i = (i+1)/2
return i
def... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/res_unet.py | .py | 4,967 | 146 | # coding = utf-8
""" define the U-Net structure """
import torch
from torch import nn
from .utils import _initialize_weights
import torch.nn.functional as F
def conv_33(in_channels, out_channels, stride=1):
# since BN is used, bias is not necessary
return nn.Conv2d(in_channels, out_channels, kernel_size=3, s... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/unet.py | .py | 3,607 | 99 | # coding = utf-8
""" define the U-Net structure """
import torch
from torch import nn
from .utils import _initialize_weights
class ConvBlock(nn.Sequential):
""" Convolution Block """
def __init__(self, in_channels, out_channels):
super().__init__()
self.add_module('conv1', nn.Conv2d(in_channe... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/wnet.py | .py | 3,624 | 89 | # coding = utf-8
""" define the U-Net structure """
import torch
from torch import nn
from .utils import _initialize_weights
import torch.nn.functional as F
class WNet(nn.Module):
""" define W-Net for help segmentation with boundary detection first """
def __init__(self, in_channel, inter_channel, out_chann... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/tiramisu.py | .py | 8,578 | 225 | # _*_ coding: utf-8 _*_
import torch
import torch.nn as nn
import math
from .utils import _initialize_weights
class DenseLayer(nn.Sequential):
""" Basic dense layer of DenseNet """
def __init__(self, in_channels, growth_rate):
super().__init__()
self.add_module('norm', nn.BatchNorm2d(in_channe... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | image/models/res_unet_dp.py | .py | 5,055 | 147 | # coding = utf-8
""" define the U-Net structure """
import torch
from torch import nn
from .utils import _initialize_weights
import torch.nn.functional as F
def conv_33(in_channels, out_channels, stride=1):
# since BN is used, bias is not necessary
return nn.Conv2d(in_channels, out_channels, kernel_size=3, s... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/utils.py | .py | 528 | 17 | # _*_ coding: utf-8 _*_
from torch import nn
import math
def _initialize_weights(model):
""" model weight initialization """
for m in model.modules():
if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d)):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.norma... | Python |
3D | kkhuang1990/PlaqueDetection | image/models/hyper_tiramisu.py | .py | 11,640 | 302 | # _*_ coding: utf-8 _*_
""" define the structure of Hyper Tiramisu for multi-stream input """
import torch
import torch.nn as nn
from .utils import _initialize_weights
class DenseLayer(nn.Sequential):
""" Basic dense layer of DenseNet """
def __init__(self, in_channels, growth_rate):
super().__init__(... | Python |
3D | kkhuang1990/PlaqueDetection | PlaqueSegmentation/train.py | .py | 25,288 | 528 | # _*_ coding: utf-8 _*_
""" define train and test functions here """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import sys
sys.path.append("..")
from sklearn.metrics import auc
import copy
from collections import Counter
import numpy as np
np.set_printoptions(precision=4)
from tqdm impo... | Python |
3D | kkhuang1990/PlaqueDetection | PlaqueSegmentation/main.sh | .sh | 3,449 | 96 | #!/bin/bash
# input/output
OUTPUT_CHANNEL=3
BOUND_OUTPUT='False'
WIDTH=1 # boundary width
#DATA_DIR="/home/mil/huang/Dataset/CPR_multiview"
DATA_DIR="/data/ugui0/antonio-t/CPR_multiview_interp2_huang"
# Experiment
EXPERIMENT="Experiment1"
SUB_FOLDER="Res-UNet_CE_3class"
# optimizer
LR_SCHEDULER='StepLR'
MOMENTUM=0.9... | Shell |
3D | kkhuang1990/PlaqueDetection | PlaqueSegmentation/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | PlaqueSegmentation/main.py | .py | 17,494 | 348 | # _*_ coding: utf-8 _*_
""" main code for train and test U-Net """
from __future__ import print_function
import os, sys
sys.path.append("..")
import numpy as np
import time
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.optim as optim
import argparse
import shutil
from loss impo... | Python |
3D | kkhuang1990/PlaqueDetection | datasets/pix2pix.py | .py | 3,483 | 81 | import matplotlib as mpl
mpl.use('Agg')
import os
import os.path as osp
from os import listdir
import numpy as np
import random
from skimage import io
from multiprocessing import Pool
from utils import dcm2hu, hu2gray, rgb2gray, rgb2mask, centra_crop, mask2gray
def create_image_mask_pair_cycleGAN(data_dir, des_dir, m... | Python |
3D | kkhuang1990/PlaqueDetection | datasets/multiview.py | .py | 11,942 | 240 | # _*_ coding: utf-8 _*_
""" Functions for creating dataset of multi-view slices """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from skimage import io
import pydicom as dicom
import os
import os.path as osp
from os import listdir
import numpy as np
from utils import dcm2hu
from multiproce... | Python |
3D | kkhuang1990/PlaqueDetection | datasets/normal.py | .py | 4,083 | 95 | import os
import os.path as osp
from os import listdir
import numpy as np
import pydicom as dicom
from skimage import io
from multiprocessing import Pool
from utils import dcm2hu, hu2gray, rgb2gray, rgb2mask, centra_crop, mask2gray
def resave_multi_preocess(method, data_dir, des_dir, num_workers=24):
""" resave d... | Python |
3D | kkhuang1990/PlaqueDetection | datasets/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | datasets/multiview_45degree.py | .py | 12,280 | 243 | # _*_ coding: utf-8 _*_
""" Functions for creating dataset of multi-view slices """
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from skimage import io
import pydicom as dicom
import os
import os.path as osp
from os import listdir
import numpy as np
from utils import dcm2hu
from multiproce... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/dataloader_debug.py | .py | 14,978 | 342 | # _*_ coding: utf-8 _*_
""" Dataloader used for debug
Here we want to check whether each time the same order of slices can be ensured by
setting the random seed as fixed
"""
import matplotlib as mpl
mpl.use('Agg')
import os
import os.path as osp
from os import listdir
import random
import torch
import numpy ... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/dataloader.py | .py | 20,977 | 452 | # _*_ coding: utf-8 _*_
""" functions used to load images and masks """
import matplotlib as mpl
mpl.use('Agg')
import os
import os.path as osp
from os import listdir
import random
import torch
import numpy as np
from torch.utils.data import Dataset, DataLoader
import time
from skimage import io
from skimage import ... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/transforms.py | .py | 14,554 | 440 | # _*_ coding: utf-8 _*_
""" transforms for 3D volume """
import torch
from skimage import transform
import numpy as np
import random
import warnings
import cv2
from scipy import ndimage
from sklearn.preprocessing import label_binarize
from utils import hu2lut, gray2mask, central_crop, hu2lut, hu2gray
from utils impo... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/models/__init__.py | .py | 0 | 0 | null | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/models/hybrid_res_unet.py | .py | 8,457 | 210 | # coding = utf-8
""" Hybrid Res-UNet architecture with regularization of number of predicted boundary pixels
the contract path is 3D while the expansion path is 2D.
For input, slices before and after current slice are concatenated as a volume.
For output, annotation of current slice is compared with the pr... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/models/utils.py | .py | 1,072 | 32 | # _*_ coding: utf-8 _*_
from torch import nn
import math
import torch
torch.manual_seed(42) # make random weight fixed for every running
def count_parameters(model):
""" count number of parameters """
return sum(p.numel() for p in model.parameters() if p.requires_grad)
def _initialize_weights_3d(model):
... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/models/hybrid_res_unet_reg.py | .py | 9,157 | 224 | # coding = utf-8
""" Hybrid Res-UNet architecture with regularization of number of predicted boundary pixels
the contract path is 3D while the expansion path is 2D.
For input, slices before and after current slice are concatenated as a volume.
For output, annotation of current slice is compared with the pr... | Python |
3D | kkhuang1990/PlaqueDetection | hybrid/models/hybrid_res_unet_bp.py | .py | 7,862 | 209 | # coding = utf-8
""" define the Hybrid Res-UNet structure in which the contract path is 3D while the expansion
path is 2D.
For input, slices before and after current slice are concatenated as a volume.
For output, annotation of current slice is compared with the prediction (single slice)
"""
import torch
... | Python |
3D | yuanqidu/LeftNet | main_md17.py | .py | 8,602 | 213 | from md17_dataset import MD17
from model import LEFTNet
import sys, os
import argparse
import os
import torch
from torch.optim import Adam,AdamW
from torch_geometric.data import DataLoader
from torch.autograd import grad
from torch.utils.tensorboard import SummaryWriter
from torch.optim.lr_scheduler import StepLR,Redu... | Python |
3D | yuanqidu/LeftNet | model.py | .py | 16,857 | 482 | import math
from math import pi
from typing import Optional, Tuple
import torch
from torch import nn
from torch.nn import Embedding
from torch_geometric.nn import radius_graph
from torch_geometric.nn.conv import MessagePassing
from torch_scatter import scatter
def nan_to_num(vec, num=0.0):
idx = torch.isnan(vec)... | Python |
3D | yuanqidu/LeftNet | qm9_dataset.py | .py | 7,456 | 174 | import os
import os.path as osp
import numpy as np
from tqdm import tqdm
import torch
from sklearn.utils import shuffle
from rdkit import Chem
from torch_geometric.data import Data, DataLoader, InMemoryDataset, download_url, extract_zip
HAR2EV = 27.211386246
KCALMOL2EV = 0.04336414
conversion = torch.tensor([
1... | Python |
3D | yuanqidu/LeftNet | md17_dataset.py | .py | 5,674 | 127 | import os.path as osp
import numpy as np
from tqdm import tqdm
import torch
from sklearn.utils import shuffle
from torch_geometric.data import InMemoryDataset, download_url
from torch_geometric.data import Data, DataLoader
class MD17(InMemoryDataset):
r"""
A `Pytorch Geometric <https://pytorch-geometric.... | Python |
3D | yuanqidu/LeftNet | main_qm9.py | .py | 7,283 | 176 | ### Based on the code in https://github.com/divelab/DIG/tree/dig-stable/dig/threedgraph
from qm9_dataset import QM93D
from model import LEFTNet
import argparse
import os
import torch
from torch.optim import Adam
from torch_geometric.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
from torch.o... | Python |
3D | chenz53/MIM-Med3D | train.sh | .sh | 94 | 6 | #!/usr/bin/env bash
MAIN_FILE=$1
CONFIG_FILE=$2
python3 $MAIN_FILE fit --config $CONFIG_FILE
| Shell |
3D | chenz53/MIM-Med3D | setup.py | .py | 206 | 8 | from setuptools import setup, find_packages
setup(
name="mim3d",
version="1.0",
description="Codes for Masked Image Modeling advances 3D Medical Image Modeling",
packages=find_packages(),
) | Python |
3D | chenz53/MIM-Med3D | slurm_train.sh | .sh | 406 | 8 | # For example, using AWS g5.48xlarge instance for slurm training 2 days
# brats data pretraining using SimMIM on t1ce modality
sbatch --ntasks-per-node=192 \
--partition=g5-on-demand \
--time=2-00:00:00 \
--gres=gpu:8 \
--constraint="[g5.48xlarge]" \
--wrap="sh train.sh code/experime... | Shell |
3D | chenz53/MIM-Med3D | code/metrics/ravd_metric.py | .py | 5,524 | 135 | from typing import Union
import warnings
import torch
from monai.metrics import CumulativeIterationMetric
from monai.metrics.utils import do_metric_reduction, ignore_background
from monai.utils import MetricReduction
class RavdMetric(CumulativeIterationMetric):
"""
Compute the relative absolute volume differ... | Python |
3D | chenz53/MIM-Med3D | code/metrics/__init__.py | .py | 36 | 2 | from .ravd_metric import RavdMetric
| Python |
3D | chenz53/MIM-Med3D | code/models/upernet_3d.py | .py | 6,509 | 211 | import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
from itertools import chain
from typing import Sequence
def initialize_weights(*models):
for model in models:
for m in model.modules():
if isinstance(m, nn.Conv3d):
nn.init.kaiming... | Python |
3D | chenz53/MIM-Med3D | code/models/vit_3d.py | .py | 16,828 | 496 | import math
from functools import partial
import torch
import torch.nn as nn
import torch.nn.functional as F
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
class Mlp(nn.Module):
def __init__(
self,
in_features,
hidden_features=None,
out_features=None,
ac... | Python |
3D | chenz53/MIM-Med3D | code/models/unetr.py | .py | 9,000 | 267 | from typing import Sequence, Tuple, Union
import torch.nn as nn
from monai.networks.blocks.dynunet_block import UnetOutBlock
from monai.networks.blocks.unetr_block import (
UnetrBasicBlock,
UnetrPrUpBlock,
UnetrUpBlock,
)
from monai.networks.nets.vit import ViT
from monai.utils import ensure_tuple_rep
fro... | Python |
3D | chenz53/MIM-Med3D | code/models/vitautoenc.py | .py | 6,619 | 193 | from typing import Sequence, Union
import math
import torch
import torch.nn as nn
from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
from monai.networks.blocks.transformerblock import TransformerBlock
from monai.networks.layers import Conv
from monai.utils import ensure_tuple_rep
from timm.models.la... | Python |
3D | chenz53/MIM-Med3D | code/models/simmim.py | .py | 12,139 | 373 | from typing import Union, Sequence
import torch
from torch import nn
import torch.nn.functional as F
from einops import repeat
from .swin_3d import SwinTransformer3D
from monai.networks.layers import Conv
from monai.networks.nets import ViT
from mmcv.runner import load_checkpoint
from timm.models.layers import DropPat... | Python |
3D | chenz53/MIM-Med3D | code/models/upernet_swin.py | .py | 4,444 | 132 | from typing import Sequence, Tuple, Union
import torch
from .swin_3d import SwinTransformer3D
from .upernet_3d import UperNet3D
from mmcv.runner import load_checkpoint
class UperNetSwin(torch.nn.Module):
"""
UNETR based on: "Hatamizadeh et al.,
UNETR: Transformers for 3D Medical Image Segmentation <http... | Python |
3D | chenz53/MIM-Med3D | code/models/upernet_van.py | .py | 3,367 | 91 | from typing import Sequence, Tuple, Union
import torch
from .van_3d import VAN3D
from .upernet_3d import UperNet3D
from mmcv.runner import load_checkpoint
class UperNetVAN(torch.nn.Module):
"""
UNETR based on: "Hatamizadeh et al.,
UNETR: Transformers for 3D Medical Image Segmentation <https://arxiv.org/... | Python |
3D | chenz53/MIM-Med3D | code/models/__init__.py | .py | 324 | 11 | from .mae import MAE
from .simmim import ViTSimMIM
from .vit_3d import VisionTransformer3D
from .swin_3d import SwinTransformer3D
from .upernet_3d import UperNet3D
from .van_3d import VAN3D
from .vitautoenc import ViTAutoEnc
from .unetr import UNETR
from .upernet_swin import UperNetSwin
from .upernet_van import UperNet... | Python |
3D | chenz53/MIM-Med3D | code/models/mae.py | .py | 7,582 | 212 | import math
import logging
from typing import Sequence, Union
import torch
import torch.nn as nn
from monai.networks.blocks.patchembedding import PatchEmbeddingBlock
from monai.networks.blocks.transformerblock import TransformerBlock
from monai.networks.nets import ViT
from einops import repeat
from mmcv.runner impo... | Python |
3D | chenz53/MIM-Med3D | code/models/utils.py | .py | 5,676 | 149 | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _quadruple
class Conv4d(nn.Module):
def __init__(
self,
in_channels: int,
out_channels: int,
kernel_size: [int, tuple],
stride: [int, tuple] = (1, 1, 1, 1),
... | Python |
3D | chenz53/MIM-Med3D | code/models/van_3d.py | .py | 14,082 | 462 | from typing import Optional, Union, Sequence
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from functools import partial
from timm.models.layers import DropPath, to_2tuple, trunc_normal_
# from timm.models.registry import register_model
# from timm.models.vision_transformer im... | Python |
3D | chenz53/MIM-Med3D | code/models/swin_3d.py | .py | 33,945 | 986 | import logging
from functools import reduce, lru_cache
from operator import mul
from einops import rearrange
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
import numpy as np
from timm.models.layers import DropPath, trunc_normal_
from mmcv.runner import ... | Python |
3D | chenz53/MIM-Med3D | code/experiments/ssl/simmim_pretrain_main.py | .py | 2,731 | 79 | import torch
import pytorch_lightning as pl
from pytorch_lightning.utilities.cli import LightningCLI
from models import ViTSimMIM
from torch.nn import L1Loss
from monai.inferers import SlidingWindowInferer
from utils.schedulers import LinearWarmupCosineAnnealingLR
import data
import optimizers
class SimMIMtrainer(pl... | Python |
3D | chenz53/MIM-Med3D | code/experiments/ssl/simclr_pretrain_main.py | .py | 3,605 | 104 | import data
import optimizers
from models import ViTAutoEnc
from losses import ContrastiveLoss
from torch.nn import L1Loss
import pytorch_lightning as pl
from pytorch_lightning.utilities.cli import LightningCLI
class SimCLRtrainer(pl.LightningModule):
def __init__(
self, batch_size: int, temperature: flo... | Python |
3D | chenz53/MIM-Med3D | code/experiments/ssl/mae_pretrain_main.py | .py | 2,712 | 79 | import torch
import pytorch_lightning as pl
from pytorch_lightning.utilities.cli import LightningCLI
from models import MAE
from torch.nn import L1Loss
from monai.inferers import SlidingWindowInferer
from utils.schedulers import LinearWarmupCosineAnnealingLR
import data
import optimizers
class MAEtrainer(pl.Lightnin... | Python |
3D | chenz53/MIM-Med3D | code/experiments/sl/single_seg_main.py | .py | 7,103 | 207 | from typing import Union, Optional, Sequence
from monai.losses import DiceCELoss
from monai.inferers import sliding_window_inference
from monai.transforms import AsDiscrete
from monai.metrics import DiceMetric
from models import UNETR, UperNetSwin, UperNetVAN
from monai.networks.nets import SegResNet
from monai.data i... | Python |
3D | chenz53/MIM-Med3D | code/experiments/sl/multi_seg_main.py | .py | 6,865 | 201 | from monai.losses import DiceCELoss
from monai.inferers import sliding_window_inference
from monai.metrics import DiceMetric
from models import UNETR
from monai.networks.nets import SegResNet
from monai.data import decollate_batch
from monai.transforms import Compose, Activations, AsDiscrete, EnsureType
import numpy a... | Python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.