Exemplo n.º 1
0
def load_labels(restart_valid_train):
    # Generate consistent train and validation sets
    ## Only do this if the train / validation has not been generated yet
    original_labels = dataset_loaders.groundlabels_dataframe()
    if restart_valid_train == True:
        os.system('rm -f %s/%s/train_df.csv' %
                  (settings.DATAMODEL_PATH, experiment_folder_name))
        os.system('rm -f %s/%s/valid_df.csv' %
                  (settings.DATAMODEL_PATH, experiment_folder_name))

    if not os.path.exists(
            '%s/%s/train_df.csv' %
        (settings.DATAMODEL_PATH,
         experiment_folder_name)) and not os.path.exists(
             '%s/%s/valid_df.csv' %
             (settings.DATAMODEL_PATH, experiment_folder_name)):
        cases = original_labels['image'].unique()
        np.random.shuffle(cases)
        train_data = original_labels[original_labels.image.isin(
            cases[num_valid_cases:])]
        valid_data = original_labels[~original_labels.image.
                                     isin(cases[num_valid_cases:])]

        train_data.to_csv('%s/%s/train_df.csv' %
                          (settings.DATAMODEL_PATH, experiment_folder_name),
                          index=False)
        valid_data.to_csv('%s/%s/valid_df.csv' %
                          (settings.DATAMODEL_PATH, experiment_folder_name),
                          index=False)
    train_data = pd.read_csv('%s/%s/train_df.csv' %
                             (settings.DATAMODEL_PATH, experiment_folder_name))
    valid_data = pd.read_csv('%s/%s/valid_df.csv' %
                             (settings.DATAMODEL_PATH, experiment_folder_name))
    return original_labels, train_data, valid_data
Exemplo n.º 2
0
            patches.append(
                scipy.misc.imresize(img[xi - wnd:xi + wnd, yi - wnd:yi + wnd],
                                    [image_size_nn, image_size_nn]) / 255)
            if len(patches) == batch_size:
                yield np.array(patches).transpose([0, 3, 1, 2])
                patches = []
    if len(patches) > 0:
        yield np.array(patches).transpose([0, 3, 1, 2])


########################################################
### Initilize things
########################################################

# We load the cases as they were originally...if needed
original_labels = dataset_loaders.groundlabels_dataframe()
original_labels = dataset_loaders.map_labels(original_labels, map_category)
## train_data = pd.read_csv('%s/%s/train_df.csv' % (settings.DATAMODEL_PATH, experiment_folder_name))
## valid_data = pd.read_csv('%s/%s/valid_df.csv' % (settings.DATAMODEL_PATH, experiment_folder_name))

# Initialize these cases
## We add background as label to the rest of existing labels
existing_labels = np.concatenate(
    [original_labels['class'].unique(), ['background']])
labelencoder = LabelEncoding(existing_labels)

########################################################
### Load model
########################################################
model = ResnetBuilder().build_resnet_50((3, image_size_nn, image_size_nn),
                                        len(existing_labels))