Пример #1
0
 def __call__(self, arr, aux=None):
     shape = arr.shape
     if self.move is not None:
         center = random_center(shape, self.move)
         arr_ret = crop(arr, center, self.size)
         angle = np.random.randint(4, size=3)
         arr_ret = rotation(arr_ret, angle=angle)
         axis = np.random.randint(4) - 1
         arr_ret = reflection(arr_ret, axis=axis)
         arr_ret = np.expand_dims(arr_ret, axis=-1)
         if aux is not None:
             aux_ret = crop(aux, center, self.size)
             aux_ret = rotation(aux_ret, angle=angle)
             aux_ret = reflection(aux_ret, axis=axis)
             aux_ret = np.expand_dims(aux_ret, axis=-1)
             return arr_ret, aux_ret
         return arr_ret
     else:
         center = np.array(shape) // 2
         arr_ret = crop(arr, center, self.size)
         arr_ret = np.expand_dims(arr_ret, axis=-1)
         if aux is not None:
             aux_ret = crop(aux, center, self.size)
             aux_ret = np.expand_dims(aux_ret, axis=-1)
             return arr_ret, aux_ret
         return arr_ret
Пример #2
0
    try:
        voxel_train = np.append(voxel_train,
                                np.expand_dims(data['voxel'], axis=0),
                                axis=0)  #向voxel_train中添加读取的voxel向量,但是初次读取会出错
        seg_train = np.append(seg_train,
                              np.expand_dims(data['seg'], axis=0),
                              axis=0)  #向seg_train中添加读取的seg向量,同样初次读取时会出错
    except ValueError:
        voxel_train = np.expand_dims(data['voxel'], axis=0)
        seg_train = np.expand_dims(data['seg'], axis=0)

training_batch_size = voxel_train.shape[0]  #465

#对训练数据进行数据增强扩充为原来3倍
voxel_train_new = []
voxel_train_new = np.expand_dims(crop(voxel_train[0], (50, 50, 50),
                                      (32, 32, 32)),
                                 axis=0)
for i in range(voxel_train.shape[0] - 1):
    voxel_train_new = np.append(voxel_train_new,
                                np.expand_dims(crop(voxel_train[i + 1],
                                                    (50, 50, 50),
                                                    (32, 32, 32)),
                                               axis=0),
                                axis=0)

seg_train_new = []
seg_train_new = np.expand_dims(crop(seg_train[0], (50, 50, 50), (32, 32, 32)),
                               axis=0)
for i in range(seg_train.shape[0] - 1):
    seg_train_new = np.append(seg_train_new,
                              np.expand_dims(crop(seg_train[i + 1],
Пример #3
0
                             np.expand_dims(data['seg'], axis=0),
                             axis=0)
        name_test.append('candidate{}.npz'.format(i))
    except ValueError:
        voxel_test = np.expand_dims(data['voxel'], axis=0)
        seg_test = np.expand_dims(data['seg'], axis=0)
        name_test.append('candidate{}.npz'.format(i))

seg_test = seg_test.astype(int)  #将seg布尔array转换为1/0整数
X_test_sharp = voxel_test
X_test_net = voxel_test * seg_test  #将结节抠出来

X_test_sharp = X_test_sharp.astype(np.float32)
X_test_net = X_test_net.astype(np.float32)
training_test_size = X_test_sharp.shape[0]  #训练数据集的数量
X_test_new = crop(X_test_sharp[0], (50, 50, 50), (32, 32, 32))
X_test_new2 = crop(X_test_net[0], (50, 50, 50), (32, 32, 32))
X_test_new = np.expand_dims(X_test_new, axis=0)
X_test_new2 = np.expand_dims(X_test_new2, axis=0)
print(X_test_new.shape)
print(X_test_new2.shape)
test_batch_size = X_test_sharp.shape[0]
for i in tqdm(range(test_batch_size - 1), desc='croping'):
    X_test_new = np.append(X_test_new,
                           np.expand_dims(crop(X_test_sharp[i + 1],
                                               (50, 50, 50), (32, 32, 32)),
                                          axis=0),
                           axis=0)

for i in tqdm(range(test_batch_size - 1), desc='croping'):
    X_test_new2 = np.append(X_test_new2,