Example #1
0
test_provider = DoubleSourceProvider3(nofWindows=args.nosOfWindows,
                                      offset=offset)

# TensorFlow placeholders
x = tf.placeholder(
    tf.float32,
    shape=[None, params_appliance[args.appliance_name]['windowlength']],
    name='x')

y_ = tf.placeholder(tf.float32, shape=[None, 1], name='y_')

# -------------------------------- Keras Network - from model.py -------------------------------------
inp = Input(tensor=x)

model = get_model(args.appliance_name,
                  inp,
                  params_appliance[args.appliance_name]['windowlength'],
                  n_dense=args.dense_layers)[0]

y = model.outputs
# ----------------------------------------------------------------------------------------------------

sess.run(tf.global_variables_initializer())

# Load path depending on the model kind
if args.transfer:
    print('arg.transfer'.format(args.transfer))
    param_file = args.trained_model_dir + '/cnn_s2p_' + appliance_name + '_transf_' + args.cnn + '_pointnet_model'
else:
    print('arg.transfer'.format(args.transfer))
    param_file = args.trained_model_dir + '/cnn_s2p_' + args.appliance_name + '_pointnet_model'
# TensorFlow placeholders
x = tf.placeholder(tf.float32,
                   shape=[None, params_appliance[args.appliance_name]['windowlength']],
                   name='x')

y_ = tf.placeholder(tf.float32,
                    shape=[None, 1],
                    name='y_')

# -------------------------------- Keras Network - from model.py -----------------------------------------
inp = Input(tensor=x)
model, cnn_check_weights = get_model(args.appliance_name,
                                     inp,
                                     params_appliance[args.appliance_name]['windowlength'],
                                     transfer_dense=args.transfer_model,
                                     transfer_cnn=args.transfer_cnn,
                                     cnn=args.cnn,
                                     pretrainedmodel_dir=args.pretrainedmodel_dir)
y = model.outputs
# -------------------------------------------------------------------------------------------------------

# cost function
cost = tf.reduce_mean(tf.reduce_mean(tf.squared_difference(y, y_), 1))

# model's weights to be trained
train_params = tf.trainable_variables()
log("All network parameters: ")
log([v.name for v in train_params])
# if transfer learning is selected, just the dense layer will be trained
if not args.transfer_model and args.transfer_cnn:
Example #3
0
from cnnModel import get_model, weights_loader
from Arguments import *
from dataset_management.refit.dataset_infos import *
from keras.layers import Input
import numpy as np
import matplotlib.pyplot as plt

length = params_appliance[args.appliance_name]['windowlength']

# ------------------------------ KERAS NETWORK - from cnnModel.py ------------------------------------------------------

uno = Input(shape=(1, length))
model = get_model(
    uno,
    params_appliance[args.appliance_name]['windowlength'],
    transfer_cnn=args.transfer,
    cnn=args.cnn,
)

y = model.outputs

# Load path depending on the model kind
if args.transfer:
    param_file = '../models/cnn_s2p_' + args.appliance_name + '_transf_' + args.cnn + '_pointnet_model'
else:
    param_file = '../models/cnn_s2p_' + args.appliance_name + '_pointnet_model'
# Loading weigths
weights_loader(model, param_file)
# ----------------------------------------------------------------------------------------------------------------------

# ---------------------------------------- Plot CNN weights ------------------------------------------------------------