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
                                                      mode='min',
                                                      verbose=0,
                                                      save_best_only=True,
                                                      save_weights_only=True)
csv_logger = tf.keras.callbacks.CSVLogger(
    f'./Logs/{NOW}_{kernel_initializer[ki]}_{Optimizers[opt]}.csv')
my_callbacks = [
    model_checkpoint,
    csv_logger,
    # tf.keras.callbacks.EarlyStopping(patience=2),
    # tf.keras.callbacks.TensorBoard(log_dir=f'./Logs/{NOW}_{kernel_initializer[ki]}_{Optimizers[opt]}'),
]
# =============================================================================
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
    MODEL = CreateModel(KI=kernel_initializer[ki], nfs=nfs)
    MODEL.compile(loss=MeanSquaredError(),
                  optimizer=optimizer,
                  metrics=[myAcc, maxSAD, avgSAD])

if os.path.isfile(HDF5):
    print(f"restore from {HDF5}")
    MODEL.load_weights(HDF5)

MODEL.evaluate(X, Y, batch_size=256**3)
MODEL.fit(X, Y, epochs=SUB_EPOCH, batch_size=256**2, callbacks=my_callbacks)

MODEL.evaluate(X, Y, batch_size=256**3)
MODEL.load_weights(HDF5)
MODEL.evaluate(X, Y, batch_size=256**3)
Exemplo n.º 3
0
        png_GT = "../egis_3dluts/DATASET/PNGs/3DLUT_256_train_out_hsv(0.014).png"
    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.º 4
0
                    save_best_only=False),
    CSVLogger(f"./experiments/{conf['name']}/log.csv"),
    TensorBoard(f"./experiments/{conf['name']}/Logs"),
    # tf.keras.callbacks.EarlyStopping(patience=2),
]
# =============================================================================
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
    MODEL = CreateModel(KI=conf['parameter']['kernel_initializer'],
                        nfs=conf['nfs'])
    MODEL.compile(loss=MeanSquaredError(),
                  optimizer=optimizer,
                  metrics=[myAcc, maxSAD, avgSAD])

if conf['restore_from']:
    print(f"restore from conf['restore_from']")
    MODEL.load_weights(conf['restore_from'])

npzfile = np.load(conf['dataset']['XY_npz'])
X = npzfile['arr_0']
Y = npzfile['arr_1']
del npzfile

MODEL.evaluate(X, Y, batch_size=256**3)
MODEL.fit(X,
          Y,
          epochs=conf['parameter']['epoch'],
          batch_size=256**2,
          callbacks=callbacks)
MODEL.evaluate(X, Y, batch_size=256**3)
Exemplo n.º 5
0
import tensorflowjs as tfjs
from model import CreateModel

model = CreateModel()
model.load_weights('model.h5')
tfjs.converters.save_keras_model(model, 'extension/model')
Exemplo n.º 6
0
from keras.applications.mobilenetv2 import preprocess_input
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
import keras.activations as activations

# load image
img = Image.open(os.sys.argv[1]).resize((128, 128)).convert('RGB')
img = img_to_array(img)
preprocessed_img = preprocess_input(img.copy())
batch = np.expand_dims(preprocessed_img, axis=0)

# get the last 8x8 conv layer of model
classifier = CreateModel()
classifier.load_weights('model.h5')
conv_layer = classifier.get_layer('Conv_1')

# compute activation map
gradient_var = K.gradients(classifier.output, conv_layer.output)[0]
activation_map_var = K.sum(gradient_var * conv_layer.output, axis=3)
activation_map = K.function([classifier.input],
                            [activation_map_var])([batch])[0][0]
activation_map -= activation_map.min()
activation_map /= activation_map.max()
plt.imshow(img / 255)
plt.imshow(activation_map,
           cmap=plt.cm.PiYG,
           extent=(0, 128, 128, 0),
           alpha=0.8,
           interpolation=None)