Example #1
0
def test_loader():

    nn_input_shape = (32, ) * 3
    norm_patch_shape = (32, ) * 3

    preprocessors = [
        AugmentFPRCandidates(
            candidates_csv="candidates_V2",
            tags=["luna:3d"],
            output_shape=nn_input_shape,
            norm_patch_shape=norm_patch_shape,
            augmentation_params={
                "scale": [1, 1, 1],  # factor
                "uniform scale": 1,  # factor
                "rotation": [0, 0, 0],  # degrees
                "shear": [0, 0, 0],  # deg
                "translation": [0, 0, 0],  # mm
                "reflection": [0, 0, 0]
            },  # Bernoulli p
            interp_order=1),
        DefaultNormalizer(tags=["luna:3d"])
    ]

    l = LunaDataLoader(only_positive=True,
                       multiprocess=False,
                       sets=TRAINING,
                       preprocessors=preprocessors)
    l.prepare()

    chunk_size = 1

    batches = l.generate_batch(chunk_size=chunk_size,
                               required_input={
                                   "luna:3d": (chunk_size, ) + nn_input_shape,
                                   "luna:pixelspacing": (chunk_size, 3)
                               },
                               required_output={"luna:target": (chunk_size, )})

    for sample in batches:
        import utils.plt

        print sample[INPUT]["luna:3d"].shape, sample[OUTPUT][
            "luna:target"], sample[INPUT]["luna:pixelspacing"]
        utils.plt.show_animate(np.clip(sample[INPUT]["luna:3d"][0] + 0.25, 0,
                                       1),
                               50,
                               normalize=False)
Example #2
0
]

#####################
#     training      #
#####################
training_data = LunaDataLoader(
    only_positive=True,
    sets=TRAINING,
    epochs=10,
    preprocessors=preprocessors,
    multiprocess=False,
    crash_on_exception=True
)

chunk_size = 1
training_data.prepare()
data,segm = None,None
sample_nr = 0

def get_data():
    global data,segm
    global sample_nr
    while True:
        #####################
        #      single       #
        #####################
        if sample_nr>=483:
            return True
        print sample_nr
        sample = training_data.load_sample(sample_nr,input_keys_to_do=["luna:3d"], output_keys_to_do=["luna:segmentation"])
        data = sample[INPUT]["luna:3d"][:,:,:]