Beispiel #1
0
def test_init_pdnet():
    run_params = {
        'n_primal': 5,
        'n_dual': 5,
        'n_iter': 10,
        'n_filters': 32,
    }
    model = pdnet(lr=1e-3, **run_params)
def fine_tune_pdnet(original_run_id, af, contrast, cuda_visible_devices):
    os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(cuda_visible_devices)
    af = int(af)
    # generators
    train_set = train_masked_kspace_dataset_from_indexable(
        train_path,
        AF=af,
        contrast=contrast,
        inner_slices=8,
        rand=True,
        scale_factor=1e6,
    )
    val_set = train_masked_kspace_dataset_from_indexable(
        val_path,
        AF=af,
        contrast=contrast,
        scale_factor=1e6,
    )

    run_params = {
        'n_primal': 5,
        'n_dual': 5,
        'n_iter': 10,
        'n_filters': 32,
    }
    n_epochs = 50
    new_run_id = f'pdnet_af{af}_{contrast}_{int(time.time())}'
    chkpt_path = f'{CHECKPOINTS_DIR}checkpoints/{new_run_id}' + '-{epoch:02d}.hdf5'

    chkpt_cback = ModelCheckpoint(chkpt_path,
                                  period=n_epochs,
                                  save_weights_only=True)
    log_dir = op.join(f'{LOGS_DIR}logs', new_run_id)
    tboard_cback = TensorBoard(
        profile_batch=0,
        log_dir=log_dir,
        histogram_freq=0,
        write_graph=False,
        write_images=False,
    )

    model = pdnet(lr=1e-6, **run_params)
    model.load_weights(
        f'{CHECKPOINTS_DIR}checkpoints/{original_run_id}-300.hdf5')
    print(model.summary(line_length=150))
    model.fit(
        train_set,
        steps_per_epoch=n_volumes_train // 2,
        epochs=n_epochs,
        validation_data=val_set,
        validation_steps=5,
        verbose=0,
        callbacks=[
            tboard_cback,
            chkpt_cback,
        ],
    )
Beispiel #3
0
run_id = f'pdnet_af{AF}_oasis_{int(time.time())}'
chkpt_path = f'checkpoints/{run_id}' + '-{epoch:02d}.hdf5'

chkpt_cback = ModelCheckpoint(chkpt_path, period=100, save_weights_only=True)
log_dir = op.join('logs', run_id)
tboard_cback = TensorBoard(
    profile_batch=0,
    log_dir=log_dir,
    histogram_freq=0,
    write_graph=True,
    write_images=False,
)
tqdm_cb = TQDMCallback(metric_format="{name}: {value:e}")
tqdm_cb.on_train_batch_begin = tqdm_cb.on_batch_begin
tqdm_cb.on_train_batch_end = tqdm_cb.on_batch_end
model = pdnet(input_size=(None, None, 1), fastmri=False, lr=1e-3, **run_params)

print(model.summary(line_length=150))

model.fit_generator(
    train_gen,
    steps_per_epoch=n_train,
    epochs=n_epochs,
    validation_data=val_gen,
    validation_steps=1,
    verbose=0,
    callbacks=[tqdm_cb, tboard_cback, chkpt_cback,],
    # max_queue_size=35,
    use_multiprocessing=True,
    workers=35,
    shuffle=False,
def train_pdnet(subclassed, af, contrast, cuda_visible_devices, n_samples, n_epochs, n_iter):
    os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(cuda_visible_devices)
    af = int(af)
    # generators
    train_set = train_masked_kspace_dataset_from_indexable(
        train_path,
        AF=af,
        contrast=contrast,
        inner_slices=8,
        rand=True,
        scale_factor=1e6,
        n_samples=n_samples,
    )
    val_set = train_masked_kspace_dataset_from_indexable(
        val_path,
        AF=af,
        contrast=contrast,
        scale_factor=1e6,
    )

    run_params = {
        'n_primal': 5,
        'n_dual': 5,
        'n_iter': n_iter,
        'n_filters': 32,
    }
    additional_info = f'af{af}'
    if contrast is not None:
        additional_info += f'_{contrast}'
    if n_samples is not None:
        additional_info += f'_{n_samples}'
    if n_iter != 10:
        additional_info += f'_i{n_iter}'

    run_id = f'pdnet_{additional_info}_{int(time.time())}'
    chkpt_path = f'{CHECKPOINTS_DIR}checkpoints/{run_id}' + '-{epoch:02d}.hdf5'

    chkpt_cback = ModelCheckpoint(chkpt_path, period=n_epochs, save_weights_only=True)
    log_dir = op.join(f'{LOGS_DIR}logs', run_id)
    tboard_cback = TensorBoard(
        profile_batch=0,
        log_dir=log_dir,
        histogram_freq=0,
        write_graph=False,
        write_images=False,
    )
    if subclassed:
        model = PDNet(**run_params)
        default_model_compile(model, lr=1e-3)
    else:
        def adapt_dataset_tensors_to_functional_model(model_input, model_output):
            mask = model_input[1]
            new_mask = tf.tile(mask, [1, 640, 1])
            return (model_input[0], new_mask), model_output
        train_set = train_set.map(adapt_dataset_tensors_to_functional_model, num_parallel_calls=tf.data.experimental.AUTOTUNE)
        val_set = val_set.map(adapt_dataset_tensors_to_functional_model, num_parallel_calls=tf.data.experimental.AUTOTUNE)
        model = pdnet(lr=1e-3, **run_params)
    print(run_id)
    model.fit(
        train_set,
        steps_per_epoch=n_volumes_train,
        epochs=n_epochs,
        validation_data=val_set,
        validation_steps=5,
        verbose=0,
        callbacks=[tboard_cback, chkpt_cback,],
    )
Beispiel #5
0
def train_pdnet(af, contrast, cuda_visible_devices, n_samples, n_epochs):
    os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(cuda_visible_devices)
    af = int(af)
    # generators
    train_set = train_masked_kspace_dataset_from_indexable(
        train_path,
        AF=af,
        contrast=contrast,
        inner_slices=8,
        rand=True,
        scale_factor=1e6,
        n_samples=n_samples,
    )
    val_set = train_masked_kspace_dataset_from_indexable(
        val_path,
        AF=af,
        contrast=contrast,
        inner_slices=8,
        rand=True,
        scale_factor=1e6,
    )

    run_params = {
        'n_primal': 5,
        'n_dual': 5,
        'n_iter': 10,
        'n_filters': 32,
        'fastmri': False,
    }
    additional_info = f'af{af}'
    if contrast is not None:
        additional_info += f'_{contrast}'
    if n_samples is not None:
        additional_info += f'_{n_samples}'

    run_id = f'pdnet_multicoil_{additional_info}_{int(time.time())}'
    chkpt_path = f'{CHECKPOINTS_DIR}checkpoints/{run_id}' + '-{epoch:02d}.hdf5'

    chkpt_cback = ModelCheckpoint(chkpt_path,
                                  period=n_epochs,
                                  save_weights_only=True)
    log_dir = op.join(f'{LOGS_DIR}logs', run_id)
    tboard_cback = TensorBoard(
        profile_batch=0,
        log_dir=log_dir,
        histogram_freq=0,
        write_graph=False,
        write_images=False,
    )

    model = pdnet(lr=1e-3, **run_params)
    print(run_id)
    print(model.summary(line_length=150))
    model.fit(
        train_set,
        steps_per_epoch=n_volumes_train,
        epochs=n_epochs,
        validation_data=val_set,
        validation_steps=5,
        verbose=0,
        callbacks=[
            tboard_cback,
            chkpt_cback,
        ],
    )