コード例 #1
0
                            output_units=output_units)

## train model
print(
    f'Stratified Splitting: {n_splits_cnn} splits, {int(X_coords.shape[0]/n_splits_cnn)} pixels per split'
)
skf = StratifiedKFold(n_splits=n_splits_cnn,
                      shuffle=True,
                      random_state=random_state)
for epoch in range(1, n_epochs + 1):
    i = 0
    for _, split_indices in skf.split(X_coords, y_coords):
        i += 1
        print(f'Epoch {epoch}/{n_epochs}, Split {i}/{n_splits_cnn}')
        X_split, y_split = X_coords[split_indices], y_coords[split_indices]
        X_patches = get_patches(X_split + int(window_size / 2), X_lookup,
                                window_size)
        ConvNet.fit(X_patches, y_split, batch_size=256, epochs=1)

################################################################################
# REPORTING AND IMAGE GENERATION
################################################################################

#####

xmin = x_highlim - x_lowlim - margin - int(window_size / 2)
ymin = y_highlim - y_lowlim - margin - int(window_size / 2)

#X_test_lookup = X_lookup#\
#[xmin:xmin+margin*2+int(window_size/2)*2, ymin:ymin+margin*2+int(window_size/2)*2]
#del X_lookup
コード例 #2
0
print(
    f'Stratified Splitting: {n_splits_cnn} splits, {int(X_coords.shape[0]/n_splits_cnn)} pixels per split'
)
skf = StratifiedKFold(n_splits=n_splits_cnn,
                      shuffle=True,
                      random_state=random_state)

label = 0
for epoch in range(1, n_epochs + 1):
    i = 0
    for _, split_indices in skf.split(X_coords, y_labels):
        i += 1
        print(f'Epoch {epoch}/{n_epochs}, Split {i}/{n_splits_cnn}')
        X_split, y_split = X_coords[split_indices], y_labels[split_indices]
        X_split = X_split[y_split == label]
        X_patches = get_patches(X_split, X_lookup, window_size)
        autoencoder.fit(X_patches, X_patches, batch_size=256, epochs=1)

## model setup 2
print('Setting up data...')
X_train = df[df.train_set][norm_pca_cols].values
y_train = df[df.train_set]['Megaclasse'].values
df_test = df[~df.train_set]

autoencoders = {}
mses = {}
for label in np.unique(y_train):
    autoencoder = MLPAutoEncoder(10)
    X_label = X_train[y_train == label]
    autoencoder.fit(X_label, X_label, batch_size=256, epochs=100)
    print(f'Predicting label {label}...')
コード例 #3
0
noisy_lookup = df.pivot('x', 'y', 'y_pred').fillna(-1).values
clean_lookup = df.pivot('y', 'x', 'Megaclasse').fillna(-1).values

coords = get_2Dcoordinates_matrix(noisy_lookup.shape, window_size=window_size)

coords = df[['y', 'x']]
labels = df[['Megaclasse']]
criteria = (coords > coords.min() + int(window_size / 2) + 1).all(
    axis=1) & (coords < coords.max() - int(window_size / 2)).all(axis=1)
coords = coords[criteria].astype(int).values
labels = labels[criteria].astype(int).values
#X = get_patches(coords, noisy_lookup, window_size)
#y = get_patches(coords, clean_lookup, window_size)

denoiser = DenoiserAE((window_size, window_size, int(clean_lookup.max())))
#denoiser.fit(X, y, batch_size=256, epochs=1)

print(
    f'Stratified Splitting: {n_splits_denoiser} splits, {int(coords.shape[0]/n_splits_denoiser)} pixels per split'
)
skf = StratifiedKFold(n_splits=n_splits_denoiser,
                      shuffle=True,
                      random_state=random_state)
for epoch in range(1, n_epochs + 1):
    for i, (_, split_indices) in enumerate(skf.split(coords, labels)):
        print(f'Epoch {epoch}/{n_epochs}, Split {i+1}/{n_splits_denoiser}')
        _coords = coords[split_indices]
        X = get_patches(_coords, noisy_lookup, window_size)
        y = get_patches(_coords, clean_lookup, window_size)
        denoiser.fit(X, y, batch_size=256, epochs=1)