Exemplo n.º 1
0
def CalcSAD(input_png_path, GT_png_path):
    img_input = imread(input_png_path)
    img_GT = imread(GT_png_path)

    # reshape for loop
    img_input = np.reshape(img_input,(-1,1,1,3))
    img_GT = np.reshape(img_GT,(-1,1,1,3))


    MODEL = CreateModel()
    MODEL.load_weights('weights_lecun_normal_Adamax.hdf5')
    img_result = MODEL.predict(img_input, batch_size=256**3)

    img_result = im2uint8(img_result)
    img_GT = im2uint8(img_GT)
    absdiff = np.abs(img_result - img_GT)
    SAD = np.sum(absdiff,axis=1)

    maxSAD = np.max(SAD)
    avgSAD = np.mean(SAD)

    return maxSAD, avgSAD
Exemplo n.º 2
0
    img_GT = imread(png_GT)
    img_GT = np.reshape(img_GT, (-1, 1, 1, 3))
    img_GT = im2uint8(img_GT)

    CSV = f'./experiments/{DIR}/result.csv'
    if os.path.isfile(CSV):
        DF = pd.read_csv(CSV)
    else:
        DF = pd.DataFrame(columns=['hdf5', 'maxSAD', 'avgSAD'])

    hdf5s = sorted(glob(f'./experiments/{DIR}/HDF5/*.hdf5',
                        recursive=True))[5000::3]
    hdf5s = [i for i in hdf5s if i not in DF['hdf5'].tolist()]
    for hdf5 in tqdm(hdf5s):
        MODEL.load_weights(hdf5)
        img_result = MODEL.predict(img_input, batch_size=256**3)
        img_result = im2uint8(img_result)

        # tf.keras.preprocessing.image.save_img(    'test.png', np.reshape(img_result,(256*16,256*16,3)))

        maxSAD, avgSAD = calcSAD(img_result, img_GT)
        DF = DF.append({
            'hdf5': hdf5,
            'maxSAD': maxSAD,
            'avgSAD': avgSAD
        },
                       ignore_index=True)

    DF = DF.sort_values(by=['maxSAD', 'avgSAD'])
    DF.to_csv(CSV, index=False)
Exemplo n.º 3
0
from keras.applications.mobilenetv2 import preprocess_input
import os
from keras.preprocessing.image import load_img, img_to_array
from model import CreateModel
import numpy as np

img = img_to_array(
    load_img(os.sys.argv[1], target_size=(128, 128)).convert('RGB'))
img = preprocess_input(img)
batch = np.expand_dims(img, axis=0)
model = CreateModel()
model.load_weights('model.h5')
predictions = model.predict(batch)
print(predictions[0])