コード例 #1
0
test_data_path = Path(TEST_DATA_PATH)

IMG_SIZE = 512
BS = int(os.environ.get('BS', 20))
NUM_EPOCHS = int(os.environ.get('NUM_EPOCHS', 16))

DCM_CONF = json.loads(os.environ['DCM_CONF'])

open_dcm_image_func = simple_open_dcm_image_factory(DCM_CONF)
fastai.vision.image.open_image = open_dcm_image_func
fastai.vision.data.open_image = open_dcm_image_func
open_image = open_dcm_image_func

# TRAIN

scans = get_scans(data_path)

validation_patients = []
print('Validation patients: ', validation_patients)

data = get_data(scans,
                HOME_PATH,
                validation_patients,
                normalize_stats=DCM_CONF[NORM_STATS],
                bs=BS)
learn = get_learner(data, metrics=[], model_save_path=MODEL_SAVE_PATH)

learn.unfreeze()
learn.fit_one_cycle(NUM_EPOCHS, 1e-4)
learn.save(MODEL_NAME)
コード例 #2
0
NUM_EPOCHS = int(os.environ.get('NUM_EPOCHS', 16))


DCM_LOAD_FUNC = {
    SIMPLE_WINDOW_SMALL: simple_open_dcm_image_factory,
    SIMPLE_MULTIPLE_WINDOWS: simple_open_dcm_image_factory,
    FREQS_NO_LIMIT_WINDOWS: freqs_open_dcm_image_factory,
    FREQS_LIMIT_WINDOWS: freqs_open_dcm_image_factory,
    SIMPLE_WINDOW_1CHANNEL_CLASSIC_UNET: simple_open_dcm_image_factory,
    SIMPLE_WINDOW_3CHANNEL_CLASSIC_UNET: simple_open_dcm_image_factory,
}


# CV

scans = get_scans(data_path)
folds_df = pd.read_csv(FOLDS_PATH, encoding='utf-8')

results = []
by_patient_results = []

for idx, fold in folds_df.iterrows():
    conf = json.loads(fold[EXPERIMENT_NAME])
    open_dcm_image_func = DCM_LOAD_FUNC[EXPERIMENT_NAME](conf)

    fastai.vision.image.open_image = open_dcm_image_func
    fastai.vision.data.open_image = open_dcm_image_func
    open_image = open_dcm_image_func

    validation_patients = json.loads(fold[VALIDATION_PATIENTS])
    print('Validation patients: ', validation_patients)
コード例 #3
0
training_patients = [p for p in patients if p not in VALIDATION_PATIENTS]
print(
    f'patients: {len(patients)}, training: {len(training_patients)}, validation: {len(VALIDATION_PATIENTS)}'
)
print(f'validation patients: {VALIDATION_PATIENTS}')

results = []

for sample_size in SAMPLE_SIZES:
    print(f'Sample size: {sample_size}')

    for sampling_round in range(SAMPLING_ROUNDS):
        sampled_patients = sample(training_patients, sample_size)
        print(f'{sampling_round} sampled patients: {sampled_patients}')

        scans = get_scans(data_path,
                          patients=sampled_patients + VALIDATION_PATIENTS)

        data = get_data(
            scans,
            HOME_PATH,
            VALIDATION_PATIENTS,
            normalize_stats=DCM_CONF[NORM_STATS],
            bs=BS,
        )
        learn = get_learner(data,
                            metrics=[dice],
                            model_save_path=MODEL_SAVE_PATH)

        learn.unfreeze()
        learn.fit_one_cycle(16, 1e-4)
コード例 #4
0
    return {WINDOWS: windows, NORM_STATS: (means.tolist(), stds.tolist())}


folds = []
kfold = KFold(N_FOLDS, shuffle=True, random_state=SEED)
for train_index, val_index in kfold.split(patients):
    result = {}

    train_patients = patients[train_index]
    val_patients = patients[val_index]
    print(val_patients)

    result[TRAIN_PATIENTS] = json.dumps(train_patients.tolist())
    result[VALIDATION_PATIENTS] = json.dumps(val_patients.tolist())

    scans = get_scans(data_path, patients=train_patients)

    # freqs
    result[FREQS_NO_LIMIT_WINDOWS] = json.dumps(get_freqs_method_dict(scans, None))
    result[FREQS_LIMIT_WINDOWS] = json.dumps(
        get_freqs_method_dict(scans, STANDARD_WINDOWS[0])
    )

    # simple
    result[SIMPLE_WINDOW_SMALL] = json.dumps(
        get_standard_method_dict(scans, STANDARD_WINDOWS)
    )
    result[SIMPLE_MULTIPLE_WINDOWS] = json.dumps(
        get_standard_method_dict(scans, EXTENDED_WINDOWS)
    )