Ejemplo n.º 1
0
def main():
    problem_name = 'packiging'
    train_sets = [None] * 2
    test_sets = [None] * 2
    models = [None] * 2

    # fully connected
    train_sets[0] = lipnet_input.get_dataset_vironova_svm(problem_name, 'train', do_oversampling=False)
    train_sets[0].oversample()
    test_sets[0] = lipnet_input.get_dataset_vironova_svm(problem_name, 'test', do_oversampling=False)
    from model_fully_connected import ModelFullyConneted
    models[0] = ModelFullyConneted(verbose=False, compile_on_build=False)

    # CNN
    train_sets[1] = lipnet_input.get_dataset_images_keras(problem_name, 'train', (28, 28))
    train_sets[1].oversample()
    test_sets[1] = lipnet_input.get_dataset_images_keras(problem_name, 'test', (28, 28))
    from model_cnn import ModelCNN
    models[1] = ModelCNN(verbose=False, compile_on_build=False)

    model_combined = ModelCombined(verbose=True)
    model_combined.fit_combined(models, train_sets, nb_epoch=20)

    # print confusion matrix of train set
    cf = model_combined.evaluate_combined(train_sets, models)
    print 'Train:'
    print cf.as_str

    # print confusion matrix of test set
    cf = model_combined.evaluate_combined(test_sets, models)
    print 'Test:'
    print cf.as_str
Ejemplo n.º 2
0
Archivo: svm.py Proyecto: 2php/lipnet-1
def main():
    problem_name = 'packiging'

    train_set = lipnet_input.get_dataset_vironova_svm(problem_name=problem_name,
                                                      set_name='train',
                                                      do_oversampling=False,
                                                      batch_size=None)

    test_set = lipnet_input.get_dataset_vironova_svm(problem_name=problem_name,
                                                     set_name='test',
                                                     do_oversampling=False,
                                                     batch_size=None)

    cf = svm(train_set, test_set)
    print cf.as_str
Ejemplo n.º 3
0
def main():
    problem_name = 'packiging'

    train_set = lipnet_input.get_dataset_vironova_svm(problem_name, 'train', do_oversampling=False)
    test_set = lipnet_input.get_dataset_vironova_svm(problem_name, 'test', do_oversampling=False)
    #fit(train_set, test_set, nb_epoch=40, verbose=True)

    model = ModelFullyConneted(verbose=True)
    train_set.oversample()
    model.fit(train_set, nb_epoch=40)

    # print confusion matrix of train set
    cf = model.evaluate(train_set)
    print 'Train:'
    print cf.as_str

    # print confusion matrix of test set
    cf = model.evaluate(test_set)
    print 'Test:'
    print cf.as_str
Ejemplo n.º 4
0
def main():
    problem_name = 'packiging'
    train_sets = [None] * 2
    test_sets = [None] * 2
    models = [None] * 2

    # fully connected
    train_sets[0] = lipnet_input.get_dataset_vironova_svm(
        problem_name, 'train', do_oversampling=False)
    train_sets[0].oversample()
    test_sets[0] = lipnet_input.get_dataset_vironova_svm(problem_name,
                                                         'test',
                                                         do_oversampling=False)
    from model_fully_connected import ModelFullyConneted
    models[0] = ModelFullyConneted(verbose=False, compile_on_build=False)

    # CNN
    train_sets[1] = lipnet_input.get_dataset_images_keras(
        problem_name, 'train', (28, 28))
    train_sets[1].oversample()
    test_sets[1] = lipnet_input.get_dataset_images_keras(
        problem_name, 'test', (28, 28))
    from model_cnn import ModelCNN
    models[1] = ModelCNN(verbose=False, compile_on_build=False)

    model_combined = ModelCombined(verbose=True)
    model_combined.fit_combined(models, train_sets, nb_epoch=20)

    # print confusion matrix of train set
    cf = model_combined.evaluate_combined(train_sets, models)
    print 'Train:'
    print cf.as_str

    # print confusion matrix of test set
    cf = model_combined.evaluate_combined(test_sets, models)
    print 'Test:'
    print cf.as_str
Ejemplo n.º 5
0
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
import numpy as np
import lipnet_input
from confusion_matrix import ConfusionMatrix

problem_name = 'packiging'

train_set = lipnet_input.get_dataset_vironova_svm(problem_name,
                                                  'train',
                                                  do_oversampling=False)
x = train_set._df[train_set.feature_names].values
y = train_set._df[train_set._class_columns].values

model = Sequential()

model.add(Dense(output_dim=100, input_dim=x.shape[1]))
model.add(Activation('relu'))
model.add(Dropout(0.2))

model.add(Dense(output_dim=100, input_dim=100))
model.add(Activation('relu'))
model.add(Dropout(0.2))

model.add(Dense(output_dim=y.shape[1]))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
Ejemplo n.º 6
0
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
import numpy as np
import lipnet_input
from confusion_matrix import ConfusionMatrix

problem_name = 'packiging'

train_set = lipnet_input.get_dataset_vironova_svm(problem_name, 'train', do_oversampling=False)
x = train_set._df[train_set.feature_names].values
y = train_set._df[train_set._class_columns].values

model = Sequential()

model.add(Dense(output_dim=100, input_dim=x.shape[1]))
model.add(Activation('relu'))
model.add(Dropout(0.2))

model.add(Dense(output_dim=100, input_dim=100))
model.add(Activation('relu'))
model.add(Dropout(0.2))

model.add(Dense(output_dim=y.shape[1]))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

class_weights_balanced = train_set.balanced_class_weights
class_weights = {}