Example #1
0
def perform_pipeline_for_plots():
    y_length, x_length = Config.slide_window
    num_of_nodes = y_length * x_length * 3

    autoencoder = Autoencoder(
        lr=Config.learning_rate,
        momentum=0.0,
        adaptive_lr=Config.adaptive_lr,
        shape=[num_of_nodes, Config.num_of_hidden_neurons, num_of_nodes])

    dataset = ImageAutoencoderDataset(image_path=Config.image_path,
                                      image_size=Config.image_size,
                                      slide_window=Config.slide_window)

    total_error_list = train_model(network=autoencoder,
                                   dataset=dataset,
                                   n_epochs=Config.n_epochs,
                                   min_error=Config.min_error,
                                   verbose=False)

    compression_rate = calculate_image_compression(
        num_of_input_neurons=num_of_nodes,
        num_of_chunks=len(dataset),
        num_of_hidden_neurons=Config.num_of_hidden_neurons)

    return total_error_list, compression_rate
Example #2
0
def train_eval_factorial(verbose: bool = False) -> Tuple[float, List[float]]:
    """
    Trains jordan model on factorial sequence and evaluates it.
    Sequence example: [1, 1, 2, 6, 24, 120, 720, ...]

    :param verbose: if verbose draws plots
    :return: accuracy og the model
    """

    dataset = FactorialDataset(
        number_of_precalculated_values=Config.num_of_precalculated_values,
        number_of_input_elements=Config.num_of_input_elements)

    in_features = dataset.number_of_input_elements
    out_features = 1

    network = Jordan(
        lr=Config.learning_rate,
        momentum=Config.momentum,
        shape=[in_features, Config.num_of_hidden_neurons, out_features])

    errors_list = train_model(network=network,
                              dataset=dataset,
                              n_epochs=Config.num_epochs)
    accuracy = eval_model(network=network, dataset=dataset)

    if verbose:
        draw_error_plot(errors_list=errors_list,
                        title='Jordan model on factorial sequence errors')

    return accuracy, errors_list
Example #3
0
def perform_pipeline():
    y_length, x_length = Config.slide_window
    num_of_nodes = y_length * x_length * 3

    autoencoder = Autoencoder(
        lr=Config.learning_rate,
        momentum=0.0,
        adaptive_lr=Config.adaptive_lr,
        shape=[num_of_nodes, Config.num_of_hidden_neurons, num_of_nodes])

    dataset = ImageAutoencoderDataset(image_path=Config.image_path,
                                      image_size=Config.image_size,
                                      slide_window=Config.slide_window)

    total_error_list = train_model(network=autoencoder,
                                   dataset=dataset,
                                   n_epochs=Config.n_epochs)

    res_image = np.zeros(dataset.image.shape)
    true_image = dataset.image

    for idx, (input_image_flatten, true_image_flatten) in enumerate(dataset):
        result = autoencoder.propagate_forward(x=input_image_flatten)
        # result = sigmoid(result)

        result = result.reshape((*Config.slide_window, 3))

        res_image = input_part_into_res_image(res_image=res_image,
                                              image_chunk=result,
                                              idx=idx,
                                              slide_window=Config.slide_window)

    res_image = np.uint8(np.clip(res_image * 255, a_min=0, a_max=255))

    res_image = cv2.cvtColor(res_image, cv2.COLOR_BGR2RGB)
    true_image = cv2.cvtColor(true_image, cv2.COLOR_BGR2RGB)

    compression_rate = calculate_image_compression(
        num_of_input_neurons=num_of_nodes,
        num_of_chunks=len(dataset),
        num_of_hidden_neurons=Config.num_of_hidden_neurons)

    return res_image, true_image, total_error_list, compression_rate