示例#1
0
train_label = np.zeros(shape=(train_num * NUM_VIEW, 2), dtype=bool)
train_indices = range(train_num)
random.shuffle(train_indices)
val_num = val_num_positive + val_num_negative
val_data = np.zeros(shape=(val_num * NUM_VIEW, IMG_WIDTH, IMG_HEIGHT),
                    dtype=float)
val_label = np.zeros(shape=(val_num * NUM_VIEW, 2), dtype=bool)
val_indices = range(val_num)
random.shuffle(val_indices)

#patchs extraction
patchs = np.zeros(shape=(NUM_VIEW, IMG_WIDTH, IMG_HEIGHT), dtype=float)
for i in range(train_num):
    label = int(train_indices[i] < train_num_positive)
    data = np.load(tfiles[train_indices[i]])
    patchs = mt.make_patchs(data)
    for j in range(NUM_VIEW):
        train_label[i * NUM_VIEW + j][1 - label] = 1
        train_data[
            i * NUM_VIEW +
            j] = (patchs[j] - MIN_BOUND) / (MAX_BOUND - MIN_BOUND) - PIXEL_MEAN
for i in range(val_num):
    label = int(val_indices[i] < val_num_positive)
    data = np.load(tfiles[val_indices[i]])
    patchs = mt.make_patchs(data)
    for j in range(NUM_VIEW):
        val_label[i * NUM_VIEW + j][1 - label] = 1
        val_data[
            i * NUM_VIEW +
            j] = (patchs[j] - MIN_BOUND) / (MAX_BOUND - MIN_BOUND) - PIXEL_MEAN
示例#2
0
    image_padded[window_prehalf:window_prehalf + image.shape[0],
                 window_prehalf:window_prehalf + image.shape[1],
                 window_prehalf:window_prehalf + image.shape[2]] = image
    nodule_centers = []
    print('candidate number:%d' % (len(candidate_coords)))
    for tb in range(0, len(candidate_coords), CANDIDATE_BATCH):
        batch_size = min(CANDIDATE_BATCH, len(candidate_coords) - tb)
        test_data = np.zeros(shape=(batch_size, 4 * IMG_HEIGHT, 4 * IMG_WIDTH,
                                    NUM_CHANNELS),
                             dtype=float)
        for i in range(batch_size):
            coord = candidate_coords[tb + i]
            local_region = image_padded[coord[0]:coord[0] + WINDOW_SIZE,
                                        coord[1]:coord[1] + WINDOW_SIZE,
                                        coord[2]:coord[2] + WINDOW_SIZE]
            patchs = mt.make_patchs(local_region)
            patch_channels = mt.concatenate_patchs(patchs, NUM_CHANNELS)
            test_data[i] = (patch_channels -
                            MIN_BOUND) / (MAX_BOUND - MIN_BOUND) - PIXEL_MEAN

        predictions = net_model.predict(test_data, batch_size=50)
        for p in range(predictions.shape[0]):
            if predictions[p][0] > predictions[p][1]:
                nodule_centers.append([
                    candidate_coords[p][0], candidate_coords[p][1],
                    candidate_coords[p][2], predictions[p][0]
                ])
                #nodules.append([candidate_coords[p][0], candidate_coords[p][1], candidate_coords[p][2]])
    print('Prediction Done')

    nodules = []