Example #1
0
import matplotlib.pyplot as plt

if __name__ == "__main__":
    slice_samples = 24

    # Ruta y nombre del modelo guardado
    ia_file_path = "/home/augusto/Desktop/GIBIO/Algoritmos/ia/trained_models/model_1_beta_large"
    ia_filename = "qrs_det_model_1_epoch_10.pt"

    # Archivo a testear
    rec_path = "/home/augusto/Desktop/GIBIO/processed_dbs/only_MLII_agosto/mitdb"
    rec_filename = "217.bin"

    # Cargo modelo
    model = qrs_detector.qrs_det_1_beta(24)
    model.load_state_dict(torch.load(os.path.join(ia_file_path, ia_filename)))
    model.eval()

    # Cargo archivo a testear
    data = pickle.load(open(os.path.join(rec_path, rec_filename), 'rb'))

    counter = 0

    while True:
        this_data = torch.Tensor(
            data['data'][counter * slice_samples:counter * slice_samples +
                         slice_samples])
        this_data = this_data.view(1, 1, 24)

        y_pred = model(this_data)
Example #2
0
    if realistic_check:
        save_filename += "_realistic.bin"
    else:
        save_filename += "_norealistic.bin"

    if not os.path.isfile(os.path.join(save_path, save_filename)):
        # Archivos a testear
        test_file_handler = open(os.path.join(test_path, test_filename), 'r')
        test_files = test_file_handler.read()
        test_files = test_files.split('\n')
        test_files = list(filter(None, test_files))
        test_filepaths = [os.path.join(test_path, s) for s in test_files]
        test_file_handler.close()

        # Modelo de IA a testear
        model = qrs_detector.qrs_det_1_beta(slice_samples)
        model.load_state_dict(
            torch.load(os.path.join(ia_file_path, ia_filename)))
        model.eval()

        # Matriz de confusion
        results = {}
        results['confusion_matrix'] = []
        results['specifiers'] = []
        results['file_name'] = []
        results['file_path'] = []

        print("Entering test loop...")

        if realistic_check:
            print("Mode: Realistic check.")
Example #3
0
    # Donde guardar el modelo
    model_path = "/home/augusto/Desktop/GIBIO/Algoritmos/ia/trained_models/model_rata_v3"
    model_filename = "qrs_det_model_rata_epoch_{}.pt"

    # Donde guardar historia del entrenamiento
    train_progress_path = "/home/augusto/Desktop/GIBIO/Algoritmos/ia/trained_models/model_rata_v3"
    train_progress_filename = "qrs_det_model_rata_training.bin"

    # Si num_workers no es cero, la RAM aumenta constantemente hasta que explota el SO
    train_dataloader = DataLoader(train_gen,
                                  batch_size=batch_size,
                                  shuffle=True,
                                  num_workers=0)

    # Definicion del modelo
    model = qrs_detector.qrs_det_1_beta(train_gen.shape)

    loss_fn = torch.nn.BCELoss()

    learning_rate = 250e-6

    optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)

    print("Entering training loop...")
    print("Total epochs: {}".format(total_epochs))

    if train_time_in_secs == 0 and batchs_per_epoch == 0:
        print("Whole training set mode.")
    elif batchs_per_epoch > 0:
        print("Batchs per epoch: {}".format(batchs_per_epoch))
    else: