예제 #1
0
def prereq_load_and_compute( SIFT=False):
    # print("Loading feature paths")
    # if SIFT==True:
    #     print("SIFT")
    #     paths = hf.load_sift_paths('test')

    # else:
    #     print("BRISK")
    #     paths = hf.load_brisk_paths('test')
    # print("loading features...")
    # features = hf.load_features(paths)
    # print(str(len(features)) + " items loaded.")    
    # print("Normalizing features")
    # modified_feature_arr = hf.normalize_array(features, mode = 'test')
    # No_Of_Test_Items = len(modified_feature_arr)    

    l_channel_paths = hf.load_luminance_paths('test')
    print("Loading Luma")
    l_channel_chromas = hf.load_luminance(l_channel_paths)
    print(str(len(l_channel_chromas)) + " items loaded.")
    modified_feature_arr = l_channel_chromas
    No_Of_Test_Items = len(modified_feature_arr)


    print("modifying the shape of input and output")
    test_x = np.array(modified_feature_arr).reshape([No_Of_Test_Items, modified_feature_arr[0].shape[0], modified_feature_arr[0].shape[1], 1])

    print("test_x shape: ",test_x.shape)

    return test_x
예제 #2
0
def predict_and_dump(test_x, mode):

    luminance_paths = hf.load_luminance_paths('test')
    print("loading luminance...")
    luminance = hf.load_luminance(luminance_paths)

    if mode == 'a':
        b_channel_paths = hf.load_b_channel_chroma_paths('test')
        print("loading b channel chroma...")
        b_channel_chromas = hf.load_b_channel_chroma(b_channel_paths)
        # try:
        model = load_a_model()
        # except:
        # print("Error loading model")

    if mode == 'b':
        a_channel_paths = hf.load_a_channel_chroma_paths('test')
        print("loading a channel chroma...")
        a_channel_chromas = hf.load_a_channel_chroma(a_channel_paths)
        # try:
        model = load_b_model()
        # except:
        # print("Error loading model")

    predictions = model.predict(test_x)
    print("Dumping predictions")
    if (mode == 'a'):
        hf.save_blob(predictions, 'predicted_a_chroma')
        # for i in range(len(predictions)):
        # a_channel_chroma = hf.scale_image(predictions[i])
        # hf.reconstruct(luminance[i], a_channel_chroma,b_channel_chromas[i], i, 'A')
    if (mode == 'b'):
        hf.save_blob(predictions, 'predicted_b_chroma')
예제 #3
0
def prereq_load_and_compute(mode, SIFT=False):
    # if SIFT==True:
    # print("SIFT")
    # paths = hf.load_sift_paths('train')
    # else:
    # print("BRISK")
    # paths = hf.load_brisk_paths('train')
    # print("loading features...")
    # features = hf.load_features(paths)
    # print(str(len(features)) + " items loaded.")
    # print("Normalizing features")
    # modified_feature_arr = hf.normalize_array(features)
    # No_Of_Test_Items = len(modified_feature_arr)

    l_channel_paths = hf.load_luminance_paths('train')
    print("Loading Luma")
    l_channel_chromas = hf.load_luminance(l_channel_paths)
    print(str(len(l_channel_chromas)) + " items loaded.")
    modified_feature_arr = l_channel_chromas
    No_Of_Test_Items = len(modified_feature_arr)

    if mode == 'a':
        a_channel_paths = hf.load_a_channel_chroma_paths('train')
        print("loading a channel chroma...")
        a_channel_chromas = hf.load_a_channel_chroma(a_channel_paths)
        # print(a_channel_chromas[0])
        # print(a_channel_chromas[1])
        print(str(len(a_channel_chromas)) + " items loaded.")
        train_y_channel = np.array(a_channel_chromas).reshape(
            No_Of_Test_Items, -1)

    else:
        b_channel_paths = hf.load_b_channel_chroma_paths('train')
        print("loading b channel chroma...")
        b_channel_chromas = hf.load_b_channel_chroma(b_channel_paths)
        print(str(len(b_channel_chromas)) + " items loaded.")
        train_y_channel = np.array(b_channel_chromas).reshape(
            No_Of_Test_Items, -1)

    train_y_channel = train_y_channel + 128
    train_y_channel = train_y_channel / 256.0

    print("modifying the shape of input and output")
    train_x = np.array(modified_feature_arr).reshape([
        No_Of_Test_Items, modified_feature_arr[0].shape[0],
        modified_feature_arr[0].shape[1], 1
    ])

    print("Pickling shapes")
    hf.pickle_shape(train_x, train_y_channel)

    print("train_x shape: ", train_x.shape)
    print("train_y shape: ", train_y_channel.shape)

    return train_x, train_y_channel
예제 #4
0
파일: test.py 프로젝트: Coloriser/Final
def main():

    args = parse_arguments()
    DATASET_PATH = args.path
    mode = 'NONE'
    if not (args.a or args.b or args.ab):  #Check if only one case is true
        print("ERROR: use -h for HELP")
        exit()
        return
    # print(args)
    if args.a:
        print("Testing model based on a-channel")
        mode = 'a'
    if args.b:
        print("Testing model based on b-channel")
        mode = 'b'
    if args.ab:
        print("Testing model based on a&b-channel")
        mode = 'ab'

    # FOR AKHEEL
    # print("processing images")
    # pre_works.process_images(DATASET_PATH)

    if (mode != 'ab'):
        test_x = prereq_load_and_compute(SIFT=True)
        predict_and_dump(test_x, mode)
        return

    # IF AB MODE
    print("Loading a_chroma")
    predictions_A = hf.load_from_pickle("predicted_a_chroma")
    # print("a_channel_chroma", predictions_A[0][1])
    # print("a_channel_chroma", predictions_A[1][1])
    # print("a_channel_chroma", predictions_A[2][1])

    print("Loading b_chroma")
    predictions_B = hf.load_from_pickle("predicted_b_chroma")
    luminance_paths = hf.load_luminance_paths('test')
    print("loading luminance...")
    luminance = hf.load_luminance(luminance_paths)
    for i in range(len(predictions_A)):
        a_channel_chroma = hf.scale_image(predictions_A[i])
        # print("a_channel_chroma", a_channel_chroma)
        b_channel_chroma = hf.scale_image(predictions_B[i])
        hf.reconstruct(luminance[i], a_channel_chroma, b_channel_chroma, i,
                       'AB')
        # to reconstruct grayscale images
        empty_array = np.zeros((200, 200))
        hf.reconstruct(luminance[i], empty_array, empty_array, i, 'G')
예제 #5
0
파일: test.py 프로젝트: Coloriser/Final
def start(mode, callbackFn):

    if (mode != 'ab'):
        test_x = prereq_load_and_compute(SIFT=True)
        predict_and_dump(test_x, mode)
        if (mode == 'a'):
            print("A COMPLETED")
            return callbackFn('b')
        else:
            print("B COMPLETED")
            return callbackFn('ab')

    # IF AB MODE
    print("Loading a_chroma")
    predictions_A = hf.load_from_pickle("predicted_a_chroma")
    # print("a_channel_chroma", predictions_A[0][1])
    # print("a_channel_chroma", predictions_A[1][1])
    # print("a_channel_chroma", predictions_A[2][1])

    print("Loading b_chroma")
    predictions_B = hf.load_from_pickle("predicted_b_chroma")
    luminance_paths = hf.load_luminance_paths('test')
    print("loading luminance...")
    luminance = hf.load_luminance(luminance_paths)
    empty_array = np.zeros((200, 200))

    b_channel_paths = hf.load_b_channel_chroma_paths('test')
    print("loading b channel chroma...")
    b_channel_chromas = hf.load_b_channel_chroma(b_channel_paths)
    a_channel_paths = hf.load_a_channel_chroma_paths('test')
    print("loading a channel chroma...")
    a_channel_chromas = hf.load_a_channel_chroma(a_channel_paths)

    for i in range(len(predictions_A)):
        a_channel_chroma = hf.scale_image(predictions_A[i])
        # print("a_channel_chroma", a_channel_chroma)
        b_channel_chroma = hf.scale_image(predictions_B[i])
        hf.reconstruct(luminance[i], a_channel_chroma, b_channel_chroma, i,
                       'AB')
        # to reconstruct grayscale images
        hf.reconstruct(luminance[i], empty_array, empty_array, i, 'G')
        hf.reconstruct(luminance[i], a_channel_chromas[i],
                       b_channel_chromas[i], i, 'GT')

    return callbackFn(mode)
예제 #6
0
def predict_and_dump(test_x, mode):
    
    luminance_paths = hf.load_luminance_paths('test')
    print("loading luminance...")
    luminance = hf.load_luminance(luminance_paths)

    if mode=='a':
        b_channel_paths = hf.load_b_channel_chroma_paths('test')
        print("loading b channel chroma...")
        b_channel_chromas = hf.load_b_channel_chroma(b_channel_paths)
        # try:
        model = load_a_model()
        # except:
            # print("Error loading model")

    if mode=='b':    
        a_channel_paths = hf.load_a_channel_chroma_paths('test')
        print("loading a channel chroma...")
        a_channel_chromas = hf.load_a_channel_chroma(a_channel_paths)
        # try:
        model = load_b_model()
        # except:
            # print("Error loading model")

    predictions = model.predict(test_x)
    print("Dumping predictions")
    empty_array = np.zeros((200,200))
    if(mode == 'a'):
        hf.save_blob(predictions, 'predicted_a_chroma')
        for i in range(len(predictions)):
            a_channel_chroma = hf.scale_image(predictions[i])
            print("a_channel_chroma", a_channel_chroma)
            a_channel_chroma = a_channel_chroma*20
            hf.reconstruct(empty_array, a_channel_chroma,empty_array, i, 'A')
    if(mode == 'b'):
        hf.save_blob(predictions, 'predicted_b_chroma')    
        for i in range(len(predictions)):
            b_channel_chroma = hf.scale_image(predictions[i])
            b_channel_chroma = b_channel_chroma*20
            hf.reconstruct(empty_array, empty_array,b_channel_chroma, i, 'B')