def _crop_neg(self, index): N = len(self.neg_cubic) #疑似位置总数目 ids = np.random.randint(0, N) neg_file = self.neg_cubic[ids] data = np.load(neg_file) #疑似结点数据文件,字典,包含图像数据以及对应原图上的体素坐标中心 voxel_center = data['center'] patient_id = neg_file.split('/')[-1].split("_")[0] mhd_file = opt.data_train + patient_id + '.mhd' #结点对应训练集的mhd文件 image_mask, nodule_centers, origin, spacing = make_mask( mhd_file) #生成mask,并返回其原图的节点信息 img = data['data'].astype(np.float32) crop_mask = self._crop(image_mask, voxel_center) return img, crop_mask
def generate_data(tran, emit, T, miss=0., nmasks=1): """ Generate synthetic data from finite HMM with continuous emissions. A `miss` fraction of data is marked as missing. `nmasks` sets of missing data are created. tran : K x K discrete transition matrix. emit : K x 1 vector of continuous emission distributions. T : Number of observations to generate. miss : Fraction of observations that are missing. Tries to pick evenly over all states. nmasks : Number of missing masks to generate. """ # doesn't matter for now because we're only dealing with one sequence of # observations K = tran.shape[0] curr_st = 0 obs = [] sts = [0] obs.append(emit[0].rvs()[0]) for i in xrange(T - 1): # transition # pass in probability of 1 curr_st = np.random.choice(K, p=tran[curr_st, :]) sts.append(curr_st) # emit an observation point = emit[curr_st].rvs()[0] obs.append(point) obs = np.array(obs) sts = np.array(sts) masks = None if miss > 0.: masks = list() for i in xrange(nmasks): masks.append(make_mask(sts, miss)) # Backwards compatability with old tests if len(masks) == 1: masks = masks[0] return obs, sts, masks
def generate_data_smoothing(tran, emit, T, miss=0., left=0, nmasks=1): """ Generate synthetic data from finite HMM with continuous emissions. A `miss` fraction of data to the right of index `left` is marked as missing. `nmasks` sets of missing data are created. tran : K x K transition matrix (row normalized). emit : 1-d array-like of size K containing continuous emissions. T : Length of resulting observation sequence. miss : Fraction of observations that are missing. left : Index of leftmost observation that can be missing. nmasks : Number of missing masks to generate. """ # doesn't matter for now because we're only dealing with one sequence of # observations K = tran.shape[0] curr_st = 0 obs = [] sts = [0] obs.append(emit[0].rvs()[0]) for i in xrange(T - 1): # transition # pass in probability of 1 curr_st = np.random.choice(K, p=tran[curr_st, :]) sts.append(curr_st) # emit an observation point = emit[curr_st].rvs()[0] obs.append(point) obs = np.array(obs) sts = np.array(sts) masks = None if miss > 0.: masks = list() for i in xrange(nmasks): masks.append(make_mask(sts, miss, left)) # Backwards compatability with old tests if len(masks) == 1: masks = masks[0] return obs, sts, masks
def generate_data(tran, emit, T, miss=0., nmasks=1): """ Generate synthetic data from finite HMM with continuous emissions. A `miss` fraction of data is marked as missing. `nmasks` sets of missing data are created. tran : K x K discrete transition matrix. emit : K x 1 vector of continuous emission distributions. T : Number of observations to generate. miss : Fraction of observations that are missing. Tries to pick evenly over all states. nmasks : Number of missing masks to generate. """ # doesn't matter for now because we're only dealing with one sequence of # observations K = tran.shape[0] curr_st = 0 obs = [] sts = [0] obs.append(emit[0].rvs()[0]) for i in xrange(T-1): # transition # pass in probability of 1 curr_st = np.random.choice(K, p=tran[curr_st,:]) sts.append(curr_st) # emit an observation point = emit[curr_st].rvs()[0] obs.append(point) obs = np.array(obs) sts = np.array(sts) masks = None if miss > 0.: masks = list() for i in xrange(nmasks): masks.append(make_mask(sts, miss)) # Backwards compatability with old tests if len(masks) == 1: masks = masks[0] return obs, sts, masks
def generate_data_smoothing(tran, emit, T, miss=0., left=0, nmasks=1): """ Generate synthetic data from finite HMM with continuous emissions. A `miss` fraction of data to the right of index `left` is marked as missing. `nmasks` sets of missing data are created. tran : K x K transition matrix (row normalized). emit : 1-d array-like of size K containing continuous emissions. T : Length of resulting observation sequence. miss : Fraction of observations that are missing. left : Index of leftmost observation that can be missing. nmasks : Number of missing masks to generate. """ # doesn't matter for now because we're only dealing with one sequence of # observations K = tran.shape[0] curr_st = 0 obs = [] sts = [0] obs.append(emit[0].rvs()[0]) for i in xrange(T-1): # transition # pass in probability of 1 curr_st = np.random.choice(K, p=tran[curr_st,:]) sts.append(curr_st) # emit an observation point = emit[curr_st].rvs()[0] obs.append(point) obs = np.array(obs) sts = np.array(sts) masks = None if miss > 0.: masks = list() for i in xrange(nmasks): masks.append(make_mask(sts, miss, left)) # Backwards compatability with old tests if len(masks) == 1: masks = masks[0] return obs, sts, masks
def _crop_pos(self, index): ''' 剪切正样本,从保存的结点文件(64,64,64),剪切(48,48,48)的块 pos_file:/mnt/t/train_nodule_cubic/LKDS-00354_1021.npy,对应于一个结点 patient_id:LKDS-00354,为该结点对应的原始图像 nodule_index:1021 该结点在self.df_node中的index,便于取出该结点的中心 ''' file_index = int(index / opt.seg_ratio) pos_file = self.pos_cubic[file_index] nodule_index = int(pos_file.split('/')[-1].split('_')[1].split('.')[0]) df_min = self.df_node.iloc[nodule_index] #结点信息,包含他的中心世界坐标,文件名 patient_id = df_min.seriesuid world_center = np.array([df_min.coordZ, df_min.coordY, df_min.coordX], dtype=np.float32) mhd_file = opt.data_train + patient_id + '.mhd' #结点对应训练集的mhd文件 image_mask, nodule_centers, origin, spacing = make_mask( mhd_file) #生成mask,并返回其原图的节点信息 img = np.load(pos_file).astype(np.float32) voxel_center = np.rint((world_center - origin) / spacing) crop_mask = self._crop(image_mask, voxel_center) return img, crop_mask