Example #1
0
def main():
    ########################################################################
    # Loads the configuration for the experiment from the configuration file
    #config, learning_rate, batch_size, num_epochs, target_classes = load_config('configuration.json')

    ########################################################################
    # Obtain the PyTorch data loader objects to load batches of the datasets
    #train_loader, val_loader, test_loader, classes = get_data_loader(target_classes, batch_size)

    # Load the model
    net = torch.load("./saved_models/final.pt")
    val_images = np.load("./data/test_images_2.npy")
    val_label = np.load("./data/test_label_2.npy")
    val_dataset = MyDataset(val_images, val_label)
    val_loader = DataLoader(val_dataset, batch_size=1024, shuffle=False)

    #model_path = get_model_name(config)
    #net.load_state_dict(torch.load(model_path))

    # Evaluate the model for the confusion matrix
    #evaluate_confusion_matrix(model_path, net, test_loader, target_classes)

    # Visualize examples for false positive / true negative
    #evaluate_visual_confusion_matrix('Plot6', net, val_loader, ['no landing pad','landing pad'])
    #cm=evaluate_confusion_matrix('Plot4', net, val_loader, ['no landing pad','landing pad'])
    #plot_confusion_matrix('Plot5', cm, ['no landing pad','landing pad'],normalize=False,title='Confusion matrix',cmap=plt.cm.Blues)
    print(evaluate(net, val_loader))
Example #2
0
def load_data(batch_size):

    train_path = "data/rand_flowers_40/train/"
    train_path_masked = "data/rand_flowers_40_masked/train/"
    val_path = "data/rand_flowers_40/val/"
    val_path_masked = "data/rand_flowers_40_masked/val/"

    train_dataset = MyDataset(train_path, train_path_masked)
    val_dataset = MyDataset(val_path, val_path_masked)

    train_loader = DataLoader(train_dataset,
                              batch_size=batch_size,
                              shuffle=True)
    val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False)

    return train_loader, val_loader
Example #3
0
def load_data(batch_size):

    train_images = np.load("./data/train_images.npy")
    val_images = np.load("./data/val_images.npy")
    #test_images=np.load("./data/test_images.npy")

    train_label = np.load("./data/train_label.npy")
    val_label = np.load("./data/val_label.npy")
    #test_label =np.load("./data/test_label.npy")

    train_dataset = MyDataset(train_images, train_label)
    val_dataset = MyDataset(val_images, val_label)
    #test_dataset = MyDataset(test_images, test_label)
    train_loader = DataLoader(train_dataset,
                              batch_size=batch_size,
                              shuffle=True)
    val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False)
    #test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False)

    return train_loader, val_loader  #, test_loader
Example #4
0
def load_data(batch_size):

    test_path = "data/rand_flowers_40/test/"
    test_path_masked = "data/rand_flowers_40_masked/test/"

    test_path = "data/brick_40/test/"
    test_path_masked = "data/brick_40_masked/test/"

    test_dataset = MyDataset(test_path, test_path_masked)
    test_loader = DataLoader(test_dataset,
                             batch_size=batch_size,
                             shuffle=False)

    return test_loader
Example #5
0
        c = np.transpose(c, (1, 0, 2))
        plt.imshow(c)
        plt.gray()
        plt.show()
        # print(img.size)  # (4032, 2268)

model = torch.load("./data/model2.pt")

feat_valid = np.load("./data/images_test.npy")
label_valid = np.load("./data/labels_test.npy")

stride = 252
# feat_valid = feat_valid.transpose((0,2,1))

batch_size = 1
valid_dataset = MyDataset(X=feat_valid, y=label_valid)
val_loader = DataLoader(valid_dataset, batch_size=batch_size, shuffle=False)

total_corr = 0

matrix = np.zeros(img.size)
for i, data in enumerate(val_loader):
    images, label = data
    images = images.float()
    # print(label)
    # print("data: ",inputs.shape)
    # print("label",label.detach().numpy()[0][0])
    # print("label",label.detach().numpy()[0][1])

    outputs = model(images)
    # print("outputs:{}".format(outputs.item()))
Example #6
0
                # cv2.destroyAllWindows()
                # cv2.imwrite(newdir + "/" + filename, frame)
                print("size:",new_img.shape)
                crop_image.append(new_img)

                index.append((i, j))


                j += stride

            i += stride

        images_zeros = np.array(crop_image)
        label_zeros = np.array(index)
        batch_size = 1
        valid_dataset = MyDataset(X=images_zeros, y=label_zeros)
        val_loader = DataLoader(valid_dataset, batch_size=batch_size, shuffle=False)
        total_corr = 0
        matrix_0 = np.zeros((newframe.shape[0] // stride , newframe.shape[1] // stride))  ### 这里
        # matrix_0 = np.zeros((newframe.shape[0], newframe.shape[1] ))  ### 这里
        matrix = np.zeros((newframe.shape[0] // stride , newframe.shape[1] // stride ))
        # matrix = np.zeros((newframe.shape[0], newframe.shape[1]))

        for i, data in enumerate(val_loader):
            images, label = data
            print("label", label)
            images = images.float()
            print(images.shape)
            outputs = model(images)