Exemple #1
0
 def _test_dsk(self, input_shape):
     input_array = np.random.uniform(size=input_shape)
     print("[+] Starting dsk computation...")
     with timeit() as timestats:
         out = self.compute_features(input_array)
     print("[+] Dsk computation done...")
     print("Input shape: {} || Output shape: {}".format(
         input_shape, out.shape))
     print("Elapsed time: {}".format(timestats.elapsed_time))
Exemple #2
0
    def _test_presmoothing(self, input_shape):
        input_array = np.random.uniform(size=input_shape)

        with timeit() as timestats:
            presmoothed = self.presmoothing(input_array)

        print("Input shape: {} || Output shape: {}".format(
            input_shape, presmoothed.size()))
        print("Elapsed time on {}: {}".format(self.device,
                                              timestats.elapsed_time))
Exemple #3
0
    def _test_gradient(self, input_shape, wrt='0'):
        input_array = np.random.uniform(size=input_shape)
        # Presmooth
        presmoothed = self.presmoothing(input_array)
        # Get gradient func to test
        grad_func = getattr(self, "d{}".format(wrt))
        # Time gradient
        with timeit() as timestats:
            g = grad_func(presmoothed)

        print("Input shape: {} || Output shape: {}".format(
            presmoothed.size(), g.size()))
        print("Elapsed time: {}".format(timestats.elapsed_time))
Exemple #4
0
    def _test_dmag_2d(self, input_shape):
        input_array = np.random.uniform(size=input_shape)
        # Presmooth
        presmoothed = self.presmoothing(input_array)
        # Compute gradients
        g0 = self.d0(presmoothed)
        g1 = self.d1(presmoothed)
        # Compute gradient magnitude
        with timeit() as timestats:
            gmag = self.dmag(g0, g1)

        print("Input shape: {} || Output shape: {}".format(
            presmoothed.size(), gmag.size()))
        print("Elapsed time: {}".format(timestats.elapsed_time))
Exemple #5
0
    def _test_laplacian_2d(self, input_shape):
        input_array = np.random.uniform(size=input_shape)
        # Presmooth
        presmoothed = self.presmoothing(input_array)
        # Compute gradients
        g0 = self.d0(presmoothed)
        g1 = self.d1(presmoothed)
        g00 = self.d0(g0)
        g11 = self.d1(g1)
        # Compute and time laplacian
        with timeit() as timestats:
            lap = self.laplacian(g00, g11)

        print("Input shape: {} || Output shape: {}".format(
            presmoothed.size(), lap.size()))
        print("Elapsed time: {}".format(timestats.elapsed_time))
Exemple #6
0
def conv(input_size, kernel_size, num_output=1, num_input=1):
    input_variable = Variable(torch.from_numpy(np.random.uniform(size=(num_input, 1,
                                                                       input_size[0],
                                                                       input_size[1]))))
    kernel_variable = Variable(torch.from_numpy(np.random.uniform(size=(num_output,
                                                                        1,
                                                                        kernel_size[0],
                                                                        kernel_size[1]))))

    # bias = Variable(torch.from_numpy(np.zeros(shape=(num_output,))))

    with timeit() as timestat:
        # output = conv2d(input_variable, kernel_variable, bias=bias, groups=num_output)
        output = conv2d(input_variable, kernel_variable)

    print("Input size: {} || Kernel size: {} || Num outputs: {}".format(input_size, kernel_size,
                                                                        num_output))
    print("Output shape: {}".format(output.data.size()))
    print("Elapsed time: {}".format(timestat.elapsed_time))
Exemple #7
0
    def _test_eighess_3d(self, input_shape):
        input_array = np.random.uniform(size=input_shape)
        # Presmooth
        presmoothed = self.presmoothing(input_array)
        # Compute gradients
        g0 = self.d0(presmoothed)
        g1 = self.d1(presmoothed)
        g2 = self.d2(presmoothed)
        g00 = self.d0(g0)
        g01 = self.d1(g0)
        g02 = self.d2(g0)
        g11 = self.d1(g1)
        g12 = self.d2(g1)
        g22 = self.d2(g2)

        # Compute and time laplacian
        with timeit() as timestats:
            eighess = self.eighess(g00, g01, g02, g11, g12, g22)

        print("Input shape: {} || Output shape: {}".format(
            presmoothed.size(), eighess.size()))
        print("Elapsed time: {}".format(timestats.elapsed_time))
Exemple #8
0
    # Create a random dataset
    rng = np.random.RandomState(1)
    X = np.sort(200 * rng.rand(600, 1) - 100, axis=0)
    y = np.array([
        0
        if x > X.mean() or np.random.choice([True, False, False, False]) else 1
        for x in X
    ]).T

    X_train, X_test, y_train, y_test = train_test_split(X,
                                                        y,
                                                        train_size=400,
                                                        random_state=4)

    dsk = {
        "classifier_type": "RandomForest",
        "RF": (learning.get_classifier, "classifier_type"),
        "X_train": X_train,
        "X_test": X_test,
        "y_train": y_train,
        "y_test": y_test,
        'trained-RF': (learning.train, 'RF', "X_train", "y_train"),
        'predict': (learning.predict, 'trained-RF', 'X_test')
    }

    with timeit() as time_info:
        output = get(dsk, 'predict')

    print("Time Elapsed: {}".format(time_info.elapsed_time))