Example #1
0
def main():
    input = ComLine(sys.argv[1:])
    cvFile = CV(input.args.cv)
    cvFile.readText()
    #cvFile.printText()

    so = CVStats(cvFile.d, input.args.out)
    so.calcStats()
    so.printStats()

    plot = Graphics(cvFile.d, input.args.cv)
    plot.printFigure()
Example #2
0
def main(args):
    search_terms_input = str(args.search)
    cv_url = str(args.cv_url)

    # Scrap indeed.co.uk
    sc = Scraper(search_terms_input, start_invisible=True)
    sc.scrap_data()
    df = sc.df.copy()

    # Read CV
    cv = CV(cv_url).get_cv()
Example #3
0
def main():
    import os

    pwd = os.getcwd()
    if 'working' not in pwd:
        pwd = f'{pwd}/working'
        os.chdir(pwd)
        print(f'current_dir -> {pwd}')
    print(f'current_dir -> {pwd}')

    import numpy as np
    import pandas as pd
    from sklearn.metrics import accuracy_score
    # from sklearn.metrics import log_loss

    from data import Data
    from cv import CV
    from lgbm_wrapper import LGBMWrapper
    from xgb_wrapper import XGBWrapper
    from cat_wrapper import CatWrapper
    from lr_wrapper import LogisticRegrWrapper

    data = Data()
    X_train, y_train, test, submission_temp = data.processing()

    cv = CV()

    lgbm_wrap = LGBMWrapper()
    level1_tr_pred_lgbm, level1_test_pred_lgbm = cv.predict_cv(
        lgbm_wrap, X_train, y_train, test)

    xgb_wrap = XGBWrapper()
    level1_tr_pred_xgb, level1_test_pred_xgb = cv.predict_cv(
        xgb_wrap, X_train, y_train, test)

    cat_wrap = CatWrapper()
    level1_tr_pred_cat, level1_test_pred_cat = cv.predict_cv(
        cat_wrap, X_train, y_train, test)

    print(
        f'accuracy_score lightgbm: {round(accuracy_score(y_train, (level1_tr_pred_lgbm > 0.5).astype(int))*100, 2)}'
    )

    print(
        f'accuracy_score xgboost: {round(accuracy_score(y_train, (level1_tr_pred_xgb > 0.5).astype(int))*100, 2)}'
    )

    print(
        f'accuracy_score catboost: {round(accuracy_score(y_train, (level1_tr_pred_cat > 0.5).astype(int))*100, 2)}'
    )

    X_train2 = pd.DataFrame({
        'pred_lgbm': level1_tr_pred_lgbm,
        'pred_xgb': level1_tr_pred_xgb,
        'pred_cat': level1_tr_pred_cat
    })

    test2 = pd.DataFrame({
        'pred_lgbm': level1_test_pred_lgbm,
        'pred_xgb': level1_test_pred_xgb,
        'pred_cat': level1_test_pred_cat
    })

    lr_wrap = LogisticRegrWrapper()
    level2_tr_pred_lr, level2_test_pred_lr = cv.predict_cv(
        lr_wrap, X_train2, y_train, test2)

    print(
        f'accuracy_score LogisticRegrssion: {round(accuracy_score(y_train, (level2_tr_pred_lr > 0.5).astype(int))*100, 2)}'
    )

    submission_temp['Survived'] = (level2_test_pred_lr > 0.5).astype(int)
    submission_temp.to_csv('submission.csv', index=False)
Example #4
0
def test_cv():
    cv = CV()

    cv.show()

    cv.to_html("test.html")
Example #5
0
from cv import CV

cv = CV(WIDTH=180)
cv.to_html('cv.html')
cv.to_html('me.html')
cv.to_html('index.html')
'''
# TODO add to html>body
    zoom:80%;
    -moz-transform: scale(.8);
    position: absolute;
    top: -200px

'''
Example #6
0
File: sift.py Project: ameya98/pyCV
    def detect(self, start_scale=2, octave_size=5, edge_threshold=10, contrast_threshold=0.03):

        # Construct Difference-of-Gaussians (DoG) Pyramid
        prev_gaussian = CV.apply_blur(self.image_grayscale_array, start_scale)
        scale_factor = (2 ** (1/octave_size))
        scale = start_scale * scale_factor
        dog_octave = []
        for gaussian_count in range(octave_size):
            next_gaussian = CV.apply_blur(self.image_grayscale_array, scale)
            dog_octave.append(next_gaussian - prev_gaussian)
            prev_gaussian = next_gaussian
            scale *= scale_factor

        # Find extrema in DoG pyramid, excluding first and last scales
        extrema_points = []
        for temp_index, dog_matrix in enumerate(dog_octave[1:-1]):
            for i in range(1, dog_matrix.shape[0] - 1):
                for j in range(1, dog_matrix.shape[1] - 1):

                    # Actual index in the DoG pyramid
                    dog_index = temp_index + 1

                    # 8 neighbours in the same image
                    neighbour_pixels = []
                    neighbour_pixels.extend([dog_matrix[i - 1][j - 1], dog_matrix[i - 1][j], dog_matrix[i - 1][j + 1],
                                            dog_matrix[i][j - 1], dog_matrix[i][j + 1],
                                            dog_matrix[i + 1][j - 1], dog_matrix[i + 1][j], dog_matrix[i + 1][j + 1]])
                    # 9 neighbours below
                    dog_matrix_below = dog_octave[dog_index - 1]
                    neighbour_pixels.extend([dog_matrix_below[i - 1][j - 1], dog_matrix_below[i - 1][j], dog_matrix_below[i - 1][j + 1],
                                             dog_matrix_below[i][j - 1], dog_matrix_below[i][j], dog_matrix_below[i][j + 1],
                                             dog_matrix_below[i + 1][j - 1], dog_matrix_below[i + 1][j], dog_matrix_below[i + 1][j + 1]])

                    # 9 neighbours above
                    dog_matrix_above = dog_octave[dog_index + 1]
                    neighbour_pixels.extend([dog_matrix_above[i - 1][j - 1], dog_matrix_above[i - 1][j], dog_matrix_above[i - 1][j + 1],
                                             dog_matrix_above[i][j - 1], dog_matrix_above[i][j], dog_matrix_above[i][j + 1],
                                             dog_matrix_above[i + 1][j - 1], dog_matrix_above[i + 1][j], dog_matrix_above[i + 1][j + 1]])

                    # Check if dog_matrix[i][j] is an extrema!
                    if dog_matrix[i][j] > max(neighbour_pixels) or dog_matrix[i][j] < min(neighbour_pixels):
                        extrema_points.append((j, i, dog_index))

        self.mark_points(extrema_points, dims=(5, 5))
        self.show_marked()

        # Find derivatives for all scales in octave
        dog_octave_deriv = [SIFT.apply_derivative(dog_image) for dog_image in dog_octave]
        dog_octave_deriv_x = [deriv[0] for deriv in dog_octave_deriv]
        dog_octave_deriv_y = [deriv[1] for deriv in dog_octave_deriv]
        temp_doublederiv = [SIFT.apply_derivative(dog_image) for dog_image in dog_octave_deriv_y]

        dog_octave_doublederiv_xy = [doublederiv[0] for doublederiv in temp_doublederiv]
        dog_octave_doublederiv_yy = [doublederiv[1] for doublederiv in temp_doublederiv]
        dog_octave_doublederiv_xx = [SIFT.apply_derivative(dog_image)[0] for dog_image in dog_octave_deriv_x]

        # Rescale all scales in octave to range 0 to 255.
        dog_octave_rescaled = [SIFT.rescale_array(dog_image) for dog_image in dog_octave]

        # Apply intensity test
        passed_extrema_points = []
        for extrema_point in extrema_points:
            j, i, index = extrema_point

            if dog_octave_rescaled[index][i][j] > contrast_threshold * 255:
                passed_extrema_points.append(extrema_point)

        extrema_points = passed_extrema_points

        # Apply gradient test - evaluate Hessian at extrema points
        passed_extrema_points = []
        for extrema_point in extrema_points:
            j, i, index = extrema_point

            hessian = np.asarray([[dog_octave_doublederiv_xx[index][i][j], dog_octave_doublederiv_xy[index][i][j]],
                                  [dog_octave_doublederiv_xy[index][i][j], dog_octave_doublederiv_yy[index][i][j]]])

            if (np.trace(hessian) ** 2) < np.linalg.det(hessian)*((edge_threshold + 1)**2)/edge_threshold :
                passed_extrema_points.append(extrema_point)

        extrema_points = passed_extrema_points

        # Mark keypoints as 10px-by-10px rectangles on image
        self.mark_points(extrema_points, dims=(5, 5))
        self.show_marked()
        return dog_octave, extrema_points