def run(config_path, pipeline_config_path=None):
    '''Run the convolution module.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    convolution_config = ConvolutionConfig.from_json(config_path)
    etam.setup(convolution_config, pipeline_config_path=pipeline_config_path)
    _perform_convolution(convolution_config)
Exemple #2
0
def run(config_path, pipeline_config_path=None):
    '''Run the clip_videos module.

    Args:
        config_path: path to a ClipConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    clip_config = ClipConfig.from_json(config_path)
    etam.setup(clip_config, pipeline_config_path=pipeline_config_path)
    _clip_videos(clip_config)
def run(config_path, pipeline_config_path=None):
    '''Run the video_stream_info module.

    Args:
        config_path: path to a VideoStreamInfoConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    stream_info_config = VideoStreamInfoConfig.from_json(config_path)
    etam.setup(stream_info_config, pipeline_config_path=pipeline_config_path)
    _get_stream_info(stream_info_config)
def run(config_path, pipeline_config_path=None):
    '''Run the google_drive_download module.

    Args:
        config_path: path to a GoogleDriveDownloadConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    download_config = GoogleDriveDownloadConfig.from_json(config_path)
    etam.setup(download_config, pipeline_config_path=pipeline_config_path)
    _download_files(download_config)
Exemple #5
0
def run(config_path, pipeline_config_path=None):
    '''Run the canny edge detector module.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    canny_edge_config = CannyEdgeConfig.from_json(config_path)
    etam.setup(canny_edge_config, pipeline_config_path=pipeline_config_path)
    _perform_canny_edge_detection(canny_edge_config)
def run(config_path, pipeline_config_path=None):
    '''Run the Harris Corner module.

    Args:
        config_path: path to a HarrisCornerConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    harris_corner_config = HarrisCornerConfig.from_json(config_path)
    etam.setup(harris_corner_config, pipeline_config_path=pipeline_config_path)
    _find_corners(harris_corner_config)
Exemple #7
0
def run(config_path, pipeline_config_path=None):
    '''Run the format_videos module.

    Args:
        config_path: path to a FormatterConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    config = FormatterConfig.from_json(config_path)
    etam.setup(config, pipeline_config_path=pipeline_config_path)
    _format_videos(config)
def run(config_path, pipeline_config_path=None):
    '''Run the Image Stitching module.

    Args:
        config_path: path to a ImageStitchingConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    image_stitching_config = ImageStitchingConfig.from_json(config_path)
    etam.setup(image_stitching_config,
               pipeline_config_path=pipeline_config_path)
    _stitch_images(image_stitching_config)
def run(config_path, pipeline_config_path=None):
    '''Run the Steerable Filter module.

    Args:
        config_path: path to a SteerableFilterConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    steerable_filter_config = SteerableFilterConfig.from_json(config_path)
    etam.setup(steerable_filter_config,
               pipeline_config_path=pipeline_config_path)
    _filter_image(steerable_filter_config)
def run(config_path, pipeline_config_path=None):
    '''Run this module to find line segments in the image.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    #print(config_path)
    find_segments_config = FindSegmentsConfig.from_json(config_path)
    etam.setup(find_segments_config, pipeline_config_path=pipeline_config_path)
    _find_line_segments(find_segments_config)
Exemple #11
0
def run(config_path, pipeline_config_path=None):
    '''Run the embed_vgg16 module.

    Args:
        config_path: path to a config file containing the fields to define
            both an EmbedVGG16Config and a VGG16FeaturizerConfig
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    d = etas.read_json(config_path)
    embed_vgg16_config = EmbedVGG16Config(d)
    etam.setup(embed_vgg16_config, pipeline_config_path=pipeline_config_path)
    _featurize_driver(embed_vgg16_config, d)
Exemple #12
0
def run(config_path, pipeline_config_path=None):
    '''Run the SVHN Classification Module.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    svhn_config = SVHNClassificationConfig.from_json(config_path)
    etam.setup(svhn_config, pipeline_config_path=pipeline_config_path)
    for data in svhn_config.data:
        # Read all the MNIST data as numpy arrays
        mnist_train_images = read_idx(data.mnist_train_images_path)
        mnist_train_labels = read_idx(data.mnist_train_labels_path)
        mnist_test_images = read_idx(data.mnist_test_images_path)
        mnist_test_labels = read_idx(data.mnist_test_labels_path)

        # Read the digitStruct.mat from the SVHN test folder
        base_svhn_path = data.svhn_test_path
        dsf = DigitStructFile(base_svhn_path + "/digitStruct.mat")

        # training
        PCA_dir_train, PCA_socre_train, mean_train = Get_PCA(
            mnist_train_images, svhn_config.parameters.num_PCA)

        # testing
        svhn_error_rate, _, _ = test_SVHN(PCA_dir_train, mean_train,
                                          PCA_socre_train, mnist_train_labels,
                                          dsf, base_svhn_path,
                                          svhn_config.parameters.num_neighbor,
                                          300)

        mnist_error_rate, _, _ = test_MNIST(
            PCA_dir_train, mean_train, PCA_socre_train, mnist_train_labels,
            mnist_test_images, mnist_test_labels,
            svhn_config.parameters.num_neighbor, -1)
        '''
        # visualize
        PCA_vis, _, _ = Get_PCA(mnist_train_images, 10)
        visualize_PCA(PCA_vis)

        # get example
        test_MNIST_sample(PCA_dir_train, mean_train, PCA_socre_train, mnist_train_labels, 
            mnist_test_images, mnist_test_labels, svhn_config.parameters.num_neighbor)
        test_SVHN_sample(PCA_dir_train, mean_train, PCA_socre_train, mnist_train_labels, 
            dsf, base_svhn_path, svhn_config.parameters.num_neighbor)
        '''

        error_rate_dic = defaultdict(lambda: defaultdict())
        error_rate_dic["error_rates"]["mnist_error_rate"] = mnist_error_rate
        error_rate_dic["error_rates"]["svhn_error_rate"] = svhn_error_rate
        etas.write_json(error_rate_dic, data.error_rate_file)
Exemple #13
0
def run(config_path, pipeline_config_path=None):
    '''Run the Pott's Energy module.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    potts_config = PottsEnergyConfig.from_json(config_path)
    etam.setup(potts_config, pipeline_config_path=pipeline_config_path)
    for data in potts_config.data:
        energy = _calculate_potts_energy(data)
        potts_energy = defaultdict(lambda: defaultdict())
        potts_energy["result"]["energy"] = energy
        etas.write_json(potts_energy, data.potts_energy_out)
Exemple #14
0
def run(config_path, pipeline_config_path=None):
    '''Run the {{module_name}} module.

    Args:
        config_path: path to a {{ModuleName}}Config file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    # Load the module config
    config = DarknetConfig.from_json(config_path)

    # Perform base module setup via the `eta.core.module.setup()` method
    # provided by the ETA library
    etam.setup(config, pipeline_config_path=pipeline_config_path)

    # Now pass the `config` instance to another private method to perform the
    # actual module computations
    # ..."
    logger.debug("Trying to invoke the darknet code now...")
    run_darknet(config)
def run(config_path, pipeline_config_path=None):
    '''Run the SVHN Classification Module.

    Args:
        config_path: path to a ConvolutionConfig file
        pipeline_config_path: optional path to a PipelineConfig file
    '''
    svhn_config = SVHNClassificationConfig.from_json(config_path)
    etam.setup(svhn_config, pipeline_config_path=pipeline_config_path)
    for data in svhn_config.data:
        # Read all the MNIST data as numpy arrays
        mnist_train_images = read_idx(data.mnist_train_images_path)
        mnist_train_labels = read_idx(data.mnist_train_labels_path)

        mnist_test_images = read_idx(data.mnist_test_images_path)
        mnist_test_labels = read_idx(data.mnist_test_labels_path)

        # Read the digitStruct.mat from the SVHN test folder
        base_svhn_path = data.svhn_test_path
        dsf = DigitStructFile(base_svhn_path + "/digitStruct.mat")

        #reshape mnust_train_data
        train_images = np.reshape(mnist_train_images,
                                  (mnist_train_images.shape[0], 784))
        test_images = np.reshape(mnist_test_images,
                                 (mnist_test_images.shape[0], 784))
        eigen_basis = compute_eigen_basis(mnist_train_images)
        mnist_total_num = 0
        mnist_wrong = 0
        # Apply PCA to the training and test images
        train = np.dot(train_images, eigen_basis.T)
        test = np.dot(test_images, eigen_basis.T)
        '''
        plt.imshow(testarray.reshape(28, 28))
        plt.show()
        pca = PCA(n_components=2)
        principal_components = pca.fit_transform(train_images)
        '''
        # for i in range(500):
        #     mnist_total_num += 1
        #     neighbors = getNeighbors(train, test[i], 3, mnist_train_labels)
        #     res = getResponse(neighbors)
        #     if res != mnist_test_labels[i]:
        #         print("wrong", mnist_test_labels[i], res)
        #         # plt.imshow(mnist_test_images[i])
        #         # plt.show()
        #         mnist_wrong += 1
        # else:
        #     print("correct")
        #     plt.imshow(mnist_test_images[i])
        #     plt.show()
        '''
        Format of the bounding box
        {
            'height': [16.0],
            'label': [6.0],
            'left': [61.0],
            'top': [6.0],
            'width': [11.0]
        }
        '''
        svhn_total_num = 0
        svhn_correct = 0
        for i in range(300):
            print(i)
            for j in range(len(dsf.getBbox(i)['label'])):
                svhn_total_num += 1
                img_original = crop_img(base_svhn_path, i + 1,
                                        int(dsf.getBbox(i)['top'][j]),
                                        int(dsf.getBbox(i)['height'][j]),
                                        int(dsf.getBbox(i)['left'][j]),
                                        int(dsf.getBbox(i)['width'][j]))

                img_gray = cv2.cvtColor(img_original,
                                        cv2.COLOR_BGR2GRAY).flatten('F')
                img = np.dot(img_gray, eigen_basis.T)
                # Apply knn
                neighbors = getNeighbors(train, img, 1, mnist_train_labels)
                res = getResponse(neighbors)
                if res == int(dsf.getBbox(i)['label'][j]):
                    svhn_correct += 1
                # else:
                #     print("wrong")
                #     plt.imshow(img_original)
                #     plt.show()

        print("correct rate:", svhn_correct,
              float(svhn_correct) / float(svhn_total_num))
        '''CALL YOUR FUNCTIONS HERE.

        Please call of your functions here. For this problem, we ask you to
        visualize several things. You need to do this yourself (in any
        way you wish).

        For the MNIST and SVHN error rates, please store these two error
        rates in the variables called "mnist_error_rate" and
        "svhn_error_rate", for the MNIST error rate and SVHN error rate,
        respectively. These two variables will be used to write
        the numbers in a JSON file.
        '''
        # Make sure you assign values to these two variables
        mnist_error_rate = 0.074
        svhn_error_rate = (svhn_total_num - svhn_correct) / svhn_total_num

        error_rate_dic = defaultdict(lambda: defaultdict())
        error_rate_dic["error_rates"]["mnist_error_rate"] = mnist_error_rate
        error_rate_dic["error_rates"]["svhn_error_rate"] = svhn_error_rate
        etas.write_json(error_rate_dic, data.error_rate_file)