Пример #1
0
def plot_image_and_reconstruction(X: np.ndarray,
                                  model: keras.models.Model,
                                  idx: Optional[int] = None,
                                  cmap: Optional[str] = 'binary') -> None:
    """Plot an image and its reconstruction from an autoencoder model

    Args:
        X (np.ndarray): Training data of autoencoder
        model (keras.models.Model): Autoencoder
        idx (Optional[int], optional): The index of the training sample to plot. Defaults to None, in which case a random index is chosen.  
        cmap (Optional[str], optional): The image mapping for pyplot. Defaults to 'binary'.
    """
    idx = idx or np.random.choice(len(X))

    image = X[idx]
    [reconstruction] = model.predict(image[np.newaxis, :])
    difference = np.abs(image - reconstruction)

    fig = plt.figure(figsize=(3 * 1.5, 3))
    plt.subplot(1, 3, 1)
    plt.imshow(image, cmap=cmap)
    plt.subplot(1, 3, 2)
    plt.imshow(reconstruction, cmap=cmap)
    plt.subplot(1, 3, 3)
    plt.imshow(difference, cmap=cmap)

    plt.show()
def split_dataset(dataset: Dataset, model: keras.models.Model) -> Split:
    dataset_gen = data_flow_from_disk(SOURCE_PATH, dataset, label_indices,
                                      False, BS, SEED, MODEL)
    predictions: Predictions = OrderedDict()
    for dataset_item, prediction in zip(dataset.keys(),
                                        model.predict(dataset_gen)):
        predictions[dataset_item] = prediction
    return SPLITTER_FACTORY(predictions, 50)(dataset)
Пример #3
0
def predict_future_vals(model: keras.models.Model, window_frame: np.array):

    future_window = model.predict(window_frame)
    future_window_rounded = np.rint(future_window)
    future_window_rounded = np.squeeze(future_window_rounded)
    return future_window_rounded