Esempio n. 1
0
def load_model(parameters):
    """
    Load trained patch classifier
    """
    if (parameters["device_type"] == "gpu") and torch.has_cudnn:
        device = torch.device("cuda:{}".format(parameters["gpu_number"]))
    else:
        device = torch.device("cpu")

    model = models.ModifiedDenseNet121(num_classes=parameters['number_of_classes'])
    model.load_from_path(parameters["initial_parameters"])
    model = model.to(device)
    model.eval()
    return model, device
Esempio n. 2
0
def load_model_and_produce_heatmaps(parameters):
    """
    Loads trained patch classifier and generates heatmaps for all exams
    """
    # set random seed at the beginning of program
    random.seed(parameters['seed'])

    if (parameters["device_type"] == "gpu") and torch.has_cudnn:
        device = torch.device("cuda:{}".format(parameters["gpu_number"]))
    else:
        device = torch.device("cpu")

    model = models.ModifiedDenseNet121(num_classes=parameters['number_of_classes'])
    model.load_from_path(parameters["initial_parameters"])
    model = model.to(device)
    model.eval()
    
    # Load exam info
    exam_list = pickling.unpickle_from_file(parameters['data_file'])    

    # Create heatmaps
    making_heatmap_with_large_minibatch_potential(parameters, model, exam_list, device)