示例#1
0
def main():
    """Main function for the task 4"""
    feature_extraction_model = get_input_feature_extractor_model()
    dimension_reduction_model = get_input_dimensionality_reduction_model()
    k_value = get_input_k()
    label = get_input_image_label()
    folder = get_input_folder()
    image_name = get_input_image(folder)
    m_value = get_input_m()

    if dimension_reduction_model != "NMF":
        dist_func = "euclidean"
    elif feature_extraction_model in ["CM", "LBP"]:
        dist_func = "nvsc1"
    else:
        dist_func = "euclidean"
        # dist_func = "cosine"
        # dist_func = "chebyshev"
        # dist_func = "manhattan"
        # dist_func = "chi_square"
        # dist_func = "euclidean"

    print(global_constants.LINE_SEPARATOR)
    print("User Inputs summary")
    print(global_constants.LINE_SEPARATOR)
    print("Feature Extraction Model: {}\nDimensionality Reduction Model: {}\nk-value: {}\nLabel: {}\nFolder: {}\n"
          "Image: {}\nm-value: {}".format(feature_extraction_model, dimension_reduction_model, k_value, label, folder,
                                          image_name, m_value))
    print(global_constants.LINE_SEPARATOR)

    # Saves the returned model
    filename = "{0}_{1}_{2}_{3}".format(feature_extraction_model, dimension_reduction_model, label.replace(" ", ''),
                                        str(k_value))
    model = model_interact.load_model(filename=filename)
    if not model:
        print("Please run Task 3 for {}, {}, {} and {}".format(feature_extraction_model, dimension_reduction_model,
                                                               label, k_value))
        sys.exit(1)

    # Compute the reduced dimensions for the new query image and find m similar images
    dim_reduction = DimensionReduction(feature_extraction_model, dimension_reduction_model, k_value, label)
    result = dim_reduction.find_m_similar_images(model, m_value, folder, image_name, dist_func)
    print(global_constants.LINE_SEPARATOR)
    print("Similar Images")
    print(global_constants.LINE_SEPARATOR)
    for rec in result:
        print(rec)
    print(global_constants.LINE_SEPARATOR)

    title = {
        "Feature Extraction": feature_extraction_model,
        "Dimension Reduction": dimension_reduction_model,
        "k": k_value,
        "Label": label,
        "Distance": dist_func
             }
    show_images(os.path.abspath(os.path.join(folder, image_name)), result, title)
def main():
    query_image = get_input_image("Hands")
    no_images = get_input_k("t")
    similar_images, img_vectors, query_image_vector = get_LSH_results(
        query_image, no_images)
    # while True:
    #     rerank_results(None)
    relevancefeedback.relevance_fdbk("DT", query_image, similar_images,
                                     img_vectors, query_image_vector)
    pass
示例#3
0
def main():
    feature_extraction_model = get_input_feature_extractor_model()
    dimension_reduction_model = get_input_dimensionality_reduction_model()
    label = get_input_image_label()
    k_value = get_input_k()
    query_folder = get_input_folder()
    image_name = get_input_image(query_folder)
    m_value = 1

    print(global_constants.LINE_SEPARATOR)
    print("User Inputs summary")
    print(global_constants.LINE_SEPARATOR)
    print(
        "Feature Extraction Model: {}\nDimensionality Reduction Model: {}\nLabel: {}\nk-value: {}\nQuery Folder: {}"
        "\nImage: {}".format(feature_extraction_model,
                             dimension_reduction_model, label, k_value,
                             query_folder, image_name, m_value))
    print(global_constants.LINE_SEPARATOR)

    if dimension_reduction_model != "NMF":
        dist_func = "euclidean"
    elif feature_extraction_model in ["CM", "LBP"]:
        dist_func = "nvsc1"
    else:
        dist_func = "euclidean"
        # dist_func = "cosine"
        # dist_func = "chebyshev"
        # dist_func = "manhattan"
        # dist_func = "chi_square"
        # dist_func = "euclidean"

    class1_label, class2_label = get_class_labels(label)

    run_task3(feature_extraction_model, dimension_reduction_model,
              class1_label, k_value)
    result1 = run_task4(feature_extraction_model, dimension_reduction_model,
                        query_folder, image_name, dist_func, class1_label,
                        k_value, m_value)
    class1_score = result1[0]['score']
    # print(class1_score)

    run_task3(feature_extraction_model, dimension_reduction_model,
              class2_label, k_value)
    result2 = run_task4(feature_extraction_model, dimension_reduction_model,
                        query_folder, image_name, dist_func, class2_label,
                        k_value, m_value)
    class2_score = result2[0]['score']
    # print(class2_score)

    final_label = class1_label if class1_score > class2_score else class2_label
    print(global_constants.LINE_SEPARATOR)
    print("{} !!!".format(final_label.upper()))
    print(global_constants.LINE_SEPARATOR)
def main():
    """Main function for the script"""
    number_of_tasks = 6
    print("Welcome to Phase 3!")
    choice = get_task_number()
    if choice == "0":
        module_name = "phase3.load_csv"
    elif choice == "1":
        module_name = "phase3.task1"
    elif choice == "2":
        module_name = "p3task2"
    elif choice == "3":
        module_name = "phase3.task3"
    elif choice == "5a":
        l = get_input_k("L")
        k = get_input_k("K")
        comb = get_bool("Combine Models")
        task5a(l, k, comb)
        sys.exit(0)
    elif choice == "5b":
        query = get_input_image("Hands")
        top = get_input_k("K")
        comb = get_bool("Combine Models")
        task5b(query, top, visualize=True, combine_models=comb)
        sys.exit(0)
    elif choice == "6a":
        module_name = "task6_svm"
    elif choice == "6b":
        module_name = "task6_dt"
    elif choice == "6c":
        module_name = "task6_ppr"
    elif choice == "4c":
        module_name = "phase3.task4_ppr"
    elif choice == "4b":
        module_name = "task4_dt"
    elif choice == "4a":
        module_name = "task4_svm"
    else:
        module_name = "task{}".format(choice)
    module = importlib.import_module('{0}'.format(module_name))
    module.main()
示例#5
0
def get_input_data():
    """Get Inputs from User"""
    number_of_tasks = 2
    choice = get_task_number(number_of_tasks)
    if choice == 1:
        folder = get_input_folder()
        image = get_input_image(folder)
        model = get_input_feature_extractor_model()
        feature_extractor = ExtractFeatures(folder, model)
        result = feature_extractor.execute(image)
        # if model == "LBP":
        #     result = [float(x) for x in result.strip('[]').split(",")]
        print(numpy.array(result))

    elif choice == 2:
        folder = get_input_folder()
        model = get_input_feature_extractor_model()

        feature_extractor = ExtractFeatures(folder, model)
        feature_extractor.execute()

    elif choice == 3:
        pass
def main():
    query = get_input_image("Hands")
    no_images = get_input_k("t")
    get_probability_revelance_feedback(query, no_images)
def main():
    query_image = get_input_image("Hands")
    no_images = get_input_k("t")
    # query_image = get_input_image()
    similar_images, img_vectors, query_image_vector = get_LSH_results(query_image, no_images)
    relevancefeedback.relevance_fdbk("PPR", query_image,similar_images,img_vectors, query_image_vector)