import torch import torch.cuda import torch.nn.functional as F from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) # log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) raw_cache = getCache('part2ch14_raw') CandidateInfoTuple = namedtuple( 'CandidateInfoTuple', 'isNodule_bool, hasAnnotation_bool, isMal_bool, diameter_mm, series_uid, center_xyz' ) MaskTuple = namedtuple( 'MaskTuple', 'raw_dense_mask, dense_mask, body_mask, air_mask, raw_candidate_mask, candidate_mask, lung_mask, neg_mask, pos_mask' ) @functools.lru_cache(1) def getCandidateInfoList(requireDataOnDisk_bool=True): # We construct a set with all series_uids that are present on disk. # This will let us use the data, even if we haven't downloaded all of
import numpy as np import torch import torch.cuda from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) raw_cache = getCache('part2ch08_raw') @functools.lru_cache(1) def getNoduleInfoList(requireDataOnDisk_bool=True): # We construct a set with all series_uids that are present on disk. # This will let us use the data, even if we haven't downloaded all of # the subsets yet. mhd_list = glob.glob('data/luna/subset*/*.mhd') dataPresentOnDisk_set = {os.path.split(p)[-1][:-4] for p in mhd_list} diameter_dict = {} with open('data/luna/annotations.csv', "r") as f: for row in list(csv.reader(f))[1:]: series_uid = row[0] annotationCenter_xyz = tuple([float(x) for x in row[1:4]])
import torch import torch.cuda import torch.nn.functional as F from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) # log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) raw_cache = getCache("part2ch13_raw") MaskTuple = namedtuple( "MaskTuple", "raw_dense_mask, dense_mask, body_mask, air_mask, raw_candidate_mask, candidate_mask, lung_mask, neg_mask, pos_mask", ) CandidateInfoTuple = namedtuple( "CandidateInfoTuple", "isNodule_bool, hasAnnotation_bool, isMal_bool, diameter_mm, series_uid, center_xyz", ) @functools.lru_cache(1) def getCandidateInfoList(requireOnDisk_bool=True): # We construct a set with all series_uids that are present on disk.
import torch import torch.cuda from torch.utils.data import Dataset, DataLoader from torch.utils.data.sampler import Sampler from util.disk import getCache from util.util import XyzTuple, xyz2irc, IrcTuple from util.logconf import logging from util.affine import affine_grid_generator log = logging.getLogger(__name__) # log.setLevel(logging.WARN) log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) raw_cache = getCache('part2ch11_raw') cubic_cache = getCache('part2ch11_cubic') NoduleInfoTuple = namedtuple('NoduleInfoTuple', 'isMalignant_bool, diameter_mm, series_uid, center_xyz') @functools.lru_cache(1) def getNoduleInfoList(requireDataOnDisk_bool=True): # We construct a set with all series_uids that are present on disk. # This will let us use the data, even if we haven't downloaded all of # the subsets yet. mhd_list = glob.glob('data-unversioned/part2/luna/subset*/*.mhd') dataPresentOnDisk_set = {os.path.split(p)[-1][:-4] for p in mhd_list} diameter_dict = {} with open('data/part2/luna/annotations.csv', "r") as f: for row in list(csv.reader(f))[1:]:
import numpy as np import torch import torch.cuda from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) cache = getCache('part2') class Ct(object): def __init__(self, series_uid): mhd_path = glob.glob('data/luna/subset*/{}.mhd'.format(series_uid))[0] ct_mhd = sitk.ReadImage(mhd_path) ct_ary = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32) # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0. # This converts HU to g/cc. ct_ary += 1000 ct_ary /= 1000 # This gets rid of negative density stuff used to indicate out-of-FOV
import numpy as np import torch import torch.cuda from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) # log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) raw_cache = getCache('raw') CandidateInfoTuple = namedtuple( 'CandidateInfoTuple', 'isNodule_bool, diameter_mm, series_uid, center_xyz', ) @functools.lru_cache(1) def getCandidateInfoList(requireOnDisk_bool=True): # We construct a set with all series_uids that are present on disk. # This will let us use the data, even if we haven't downloaded all of # the subsets yet. mhd_list = glob.glob('data/subset*/*.mhd') presentOnDisk_set = {os.path.split(p)[-1][:-4] for p in mhd_list}
import imageio import glob import torch import copy import functools import random import torch import matplotlib.pyplot as plt from torch.utils.data import Dataset from torch.nn.functional import affine_grid, grid_sample from util.disk import getCache import math device = (torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')) raw_cache = getCache('gloms_raw') class Gloms: def __init__(self, file_path): self.file_path = file_path self.file_list = glob.glob(self.file_path) self.num = len(self.file_list) ims = torch.tensor( [imageio.volread(file_name) for file_name in self.file_list], dtype=torch.float32, device=device) self.images = ims def show_glom(self, glom_id, cmap="gray", step=1): # print(glom_id)im3d = util.img_as_float(im[:, :, :])
import SimpleITK as sitk import numpy as np import torch import torch.cuda from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) log.setLevel(logging.INFO) raw_cache = getCache('part2ch9_raw') NoduleInfoTuple = namedtuple('NoduleInfoTuple', 'isMalignant_bool', 'diameter_mm', 'series_uid', 'center_xyz') @functools.lru_cache(1) def getNoduleInfoList(requireDataOnDisk_bool=True): # We construct a set with all series_uids that are present on disk. # This will let us use the data, even if we haven't downloaded all # of the subsets yet. mhd_list = glob.glob("data-unversioned/part2/luna/subset*/*.mhd") dataPresentOnDisk_set = {os.path.split(p)[-1][:-4] for p in mhd_list} diameter_dict = {} with open("data/part2/luna/annotations.csv", 'r') as f:
import csv, copy import functools import glob import os from collections import namedtuple import SimpleITK as sitk import numpy as np import torch as torch from torch.utils.data import Dataset from util.utils import xyz2irc, irc2xyz, XyzTuple, IrcTuple from util.disk import getCache import log raw_cache = getCache('luna_raw') logger = log.setup_custom_logger(__name__) CandidateInfoTuple = namedtuple( 'CandidateInfoTuple', 'isNodule_bool, diameter_mm, series_uid, center_xyz', ) @functools.lru_cache(1) def get_candidate_info_list(requireOnDisk_bool=True): mhd_list = glob.glob('data/subset*/*.mhd') presentOnDisk_set = {os.path.split(p)[-1][:-4] for p in mhd_list} diameter_dict = {} with open('data/annotations.csv') as f:
import numpy as np import torch import torch.cuda from torch.utils.data import Dataset from util.disk import getCache from util.util import XyzTuple, xyz2irc from util.logconf import logging log = logging.getLogger(__name__) # log.setLevel(logging.WARN) log.setLevel(logging.INFO) log.setLevel(logging.DEBUG) cache = getCache('p2ch1') class Ct(object): def __init__(self, series_uid): mhd_path = glob.glob('data/luna/subset*/{}.mhd'.format(series_uid))[0] ct_mhd = sitk.ReadImage(mhd_path) ct_ary = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32) # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0. # This converts HU to g/cc. ct_ary += 1000 ct_ary /= 1000