def create_model():
    LENGTH = 5000  # Packet sequence length
    INPUT_SHAPE = (LENGTH, 1)
    NB_CLASSES = 95  # number of outputs = number of classes
    OPTIMIZER = Adamax(lr=0.002,
                       beta_1=0.9,
                       beta_2=0.999,
                       epsilon=1e-08,
                       decay=0.0)  # Optimizer

    model = DFNet.build(input_shape=INPUT_SHAPE, classes=NB_CLASSES)
    model.compile(loss="categorical_crossentropy",
                  optimizer=OPTIMIZER,
                  metrics=["accuracy"])
    return model
# we need a [Length x 1] x n shape as input to the DFNet (Tensorflow)
X_train = X_train[:, :, np.newaxis]
X_valid = X_valid[:, :, np.newaxis]

print(X_train.shape[0], 'training samples')
print(X_valid.shape[0], 'validation samples')

# convert class vectors to binary class matrices
y_train = np_utils.to_categorical(y_train, NB_CLASSES)
y_valid = np_utils.to_categorical(y_valid, NB_CLASSES)

print("Preparing Data for training")
# initialize the optimizer and model
print time.sleep(2)
model = DFNet.build(input_shape=INPUT_SHAPE, classes=NB_CLASSES)

model.compile(loss="categorical_crossentropy",
              optimizer=OPTIMIZER,
              metrics=["accuracy"])
print("Model compiled")

# Start training
history = model.fit(X_train,
                    y_train,
                    batch_size=BATCH_SIZE,
                    epochs=NB_EPOCH,
                    verbose=VERBOSE,
                    validation_data=(X_valid, y_valid))

# Save model
Example #3
0
def create_model():
    model = DFNet.build(input_shape=INPUT_SHAPE, classes=NB_CLASSES)
    model.compile(loss="categorical_crossentropy",
                  optimizer=OPTIMIZER,
                  metrics=["accuracy"])
    return model