예제 #1
0
from scipy.spatial.distance import euclidean
from fastdtw import fastdtw
from data import character_trajectories
import os
import numpy as np
from keras.models import load_model
import matplotlib.pyplot as plt
from rnn import create_rnn
from minisom import MiniSom

DIR_PATH = os.path.dirname(os.path.realpath(__file__))
DIR_MODEL = os.path.join(DIR_PATH, "rnn_models")
RNN_FILE_MODEL = os.path.join(DIR_MODEL, "model_RNN_205_4_noise_04_v0.hdf5")
"""reshape in and outputs"""

(X_train, Y_train), (X_test, Y_test) = character_trajectories.load_data(
    '../RNN/data/char_trajectories_4.pkl')
print("x_train shape: ", X_train.shape)
print("y_train shape: ", Y_train.shape)
print("x_test shape: ", X_test.shape)
print("y_test shape: ", Y_test.shape)
"""load model"""
rnn = create_rnn(clip=True,
                 noise=True,
                 std_dev=0,
                 hidden_size=205,
                 double_stacked=False,
                 input_shape=(X_train.shape[1], X_train.shape[2]))
rnn.load_weights(RNN_FILE_MODEL)


def pad_class(class_vector, x=1):
from data import character_trajectories
import os
import numpy as np
from keras.models import load_model
import matplotlib.pyplot as plt

DIR_PATH = os.path.dirname(os.path.realpath(__file__))
DIR_MODEL = os.path.join(DIR_PATH, "rnn_models")

dim = 20
types = False
"""reshape in and outputs"""
(X_train, Y_train), (X_test, Y_test) = character_trajectories.load_data(
    '../RNN/data/char_trajectories_{}.pkl'.format(dim))
"""remove the padding of the x_data"""
X_train = X_train[:, 0, :]
X_test = X_test[:, 0, :]

if types:
    """reduce the types to characters by taking the max along the axis"""
    print("test sample before the type reduction: ", X_test[0])
    X_train = np.amax(X_train, axis=2)
    X_test = np.amax(X_test, axis=2)
    print("test sample after type reduction: ", print(X_test[0]))

print("x_train shape: ", X_train.shape)
print("y_train shape: ", Y_train.shape)
print("x_test shape: ", X_test.shape)
print("y_test shape: ", Y_test.shape)

for i in range(5):
예제 #3
0
import os
import numpy as np
import keras.backend as K

DIR_PATH = os.path.dirname(os.path.realpath(__file__))
DIR_MODEL = os.path.join(DIR_PATH, "rnn_models")
#RNN_FILE_MODEL = os.path.join(DIR_MODEL, "model_RNN_205_2_naked_v0.hdf5")
print(K.tensorflow_backend._get_available_gpus())

types = False
dim = 20
batch_size = 1
sparse = False
sparse_val = True
# load training and validation data  #x4_types_centers_only
(X_train, Y_train), (X_test, Y_test) = character_trajectories.load_data(
    '../RNN/data/char_trajectories_{}_adverserial.pkl'.format(dim))
(X_val, Y_val), (_, _) = character_trajectories.load_data(
    '../RNN/data/char_trajectories_{}x1_types_centers_only.pkl'.format(dim))

if sparse:
    """reduce the types to characters by taking the max along the axis"""
    print("test sample before the type reduction: ", X_train[0])
    X_train = np.amax(X_train, axis=3)
    X_test = np.amax(X_test, axis=3)
    print("test sample after type reduction: ", print(X_train[0]))

if sparse_val:
    #reshape validation set
    X_val = np.amax(X_val, axis=3)

print("x_train shape: ", X_train.shape)
from keras.models import Model, Sequential
from keras.layers import Input, LSTM, Dense, Flatten
from data import character_trajectories
from keras.callbacks import ModelCheckpoint
import os
import numpy as np

DIR_PATH = os.path.dirname(os.path.realpath(__file__))
DIR_MODEL = os.path.join(DIR_PATH, "rnn_models")
#RNN_FILE_MODEL_weights = os.path.join(DIR_MODEL, "weights_RNN_v1.hdf5")

types = False
sparse = True
dim = 20
# load training and validation data
(x_train, y_train), (x_test, y_test) = character_trajectories.load_data(
    "../RNN/data/char_trajectories_{}x1_types_centers_only.pkl".format(dim))
"""remove the padding of the x_data"""
x_train = x_train[:, 0, :]
x_test = x_test[:, 0, :]

if types or sparse:
    """reduce the types to characters by taking the max along the axis"""
    print("test sample before the type reduction: ", x_train[0])
    x_train = np.amax(x_train, axis=2)
    x_test = np.amax(x_test, axis=2)
    print("test sample after type reduction: ", print(x_train[0]))

print("x_train shape: ", x_train.shape)
print("y_train shape: ", y_train.shape)
print("x_test shape: ", x_test.shape)
print("y_test shape: ", y_test.shape)
from data import character_trajectories
import os
import numpy as np
from keras.models import load_model
from sklearn.preprocessing import normalize
import matplotlib.pyplot as plt



DIR_PATH = os.path.dirname(os.path.realpath(__file__))
DIR_MODEL = os.path.join(DIR_PATH, "rnn_models")
RNN_FILE_MODEL = os.path.join(DIR_MODEL, "model_RNN_one_shot_std.hdf5")


# load training and validation data
(x_train, y_train), (x_val, y_val), (x_test, y_test) = character_trajectories.load_data()
print("x_train/val/test shape: " ,x_train.shape)
print("y_train/val/test shape: " ,y_train.shape)

"""reshape data"""

x_train = np.reshape(x_train, (len(x_train), 1, 20))
y_train = np.reshape(y_train, (len(y_train), 205, 2))
x_test = np.reshape(x_test, (len(x_test), 1, 20))
y_test = np.reshape(y_test, (len(y_test), 2, 205))

"""load model"""

rnn = load_model(RNN_FILE_MODEL)