Example #1
0
from sklearn.model_selection import train_test_split
from keras.models import Sequential, Model, model_from_json
from keras.layers import Input, LSTM, Dropout, Dense
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint
from fileRead import file_read

# np.random.seed(0)

n_step = 50

file_path = sys.argv[1]
benchmark = file_path.split('_')[0]

# --------------------read data--------------------
seqTest, targetsTest = file_read(n_step, file_path)

# --------------------load model--------------------
lstm_model = model_from_json(
    open('models/lstm_model_%s.json' % benchmark).read())
lstm_model.load_weights("weights/lstm_weights_%s.hdf5" % benchmark)

# --------------------evaluate--------------------
print 'evaluating...'
seq_num = xrange(len(seqTest))
A = 0
B = 0
C = 0
D = 0
print seqTest.shape
for test_num in seq_num:
Example #2
0
n_step = 50
n_epoch = 100
n_hidden = 256

dropout_flag = 0
learning_rate = 0.01
decay_rate = learning_rate / n_epoch

# --------------------read data--------------------
if (len(sys.argv) == 3):
    # 2 arguments
    file_path = sys.argv[1]
    file_path2 = sys.argv[2]
    benchmark = file_path.split('_')[0]
    seq, targets, seqTest, targetsTest = file_read(n_step, file_path,
                                                   file_path2)
    print seq.shape, targets.shape
    print seqTest.shape, targetsTest.shape
    n_out = seq.shape[2]
else:
    # 1 argument
    file_path = sys.argv[1]
    benchmark = file_path.split('_')[1]
    seq, targets = file_read(n_step, file_path)
    seq, seqTest, targets, targetsTest = train_test_split(seq,
                                                          targets,
                                                          test_size=0.2)
    print seq.shape, targets.shape
    print seqTest.shape, targetsTest.shape
    n_out = seq.shape[2]
Example #3
0
# np.random.seed(0)

n_step = 50

file_path = sys.argv[1]
benchmark = file_path.split('_')[1]
pos = file_path.split('_')[2]

if file_path.split('_')[0] == 'inputdata':
    faulty_label = 0
else:
    faulty_label = 1

# --------------------read data--------------------
seqTest, targetsTest = file_read(n_step,
                                 file_path,
                                 hasLabel=False,
                                 label=faulty_label)
if faulty_label:
    # affected for inputerror
    file_path2 = sys.argv[2]
    affected_raw = np.loadtxt(file_path2,
                              dtype='int64').reshape(-1, n_step,
                                                     seqTest.shape[2])
    affected = np.zeros((affected_raw.shape[0], n_step - 1, seqTest.shape[2]),
                        dtype='int64')
    for i in range(affected.shape[0]):
        affected[i] = np.delete(affected_raw[i], 0, axis=0)

# --------------------load model--------------------
lstm_model = model_from_json(
    open('models/lstm_model_%s.json' % benchmark).read())