Beispiel #1
0
import time
import A1.A1 as ax
import A2.A2 as ay
import B1.B1 as bx
import B2.B2 as by

start = time.time()
# ########### Task A1: Gender Detection ###########
# Arg1 - Create: 0, Train: 1, Test: 2
# Arg3 - Hide Confusion Matrix: 0, Show Confusion Matrix: 1
start1 = time.time()
modelax = ax.main(0, None, None)  # Create model
trainax = ax.main(1, modelax, 0)  # Train model
testax = ax.main(2, modelax, 0)  # Test model
end1 = time.time()

# ########### Task A2: Smile Detection ###########
# Arg1 - Create: 0, Train: 1, Test: 2
# Arg3 - Hide Confusion Matrix: 0, Show Confusion Matrix: 1
start2 = time.time()
modelay = ay.main(0, None, None)  # Create model
trainay = ay.main(1, modelay, 0)  # Train model
testay = ay.main(2, modelay, 0)  # Test model
end2 = time.time()

# ########### Task B1: Face Shape Recognition ###########
# Arg1 - Create: 0, Train: 1, Test: 2
# Arg3 - Hide Confusion Matrix: 0, Show Confusion Matrix: 1
start3 = time.time()
modelbx = bx.main(0, None, None)  # Create model
trainbx = bx.main(1, modelbx, 0)  # Train model
Beispiel #2
0
        _X, _y = get_data(path, field)
        X_train, X_valid, y_train, y_valid = train_test_split(_X,
                                                              _y,
                                                              test_size=0.2,
                                                              random_state=1)
        _X, _y = get_data(test_path, field, True)
        return (X_train, y_train), (X_valid, y_valid), (_X, _y)


# ======================================================================================================================
# Data preprocessing
# data_train, data_val, data_test = data_preprocessing(args...)
# ======================================================================================================================
# Task A1
train, val, test = data_preprocessing('celeba', 'gender', use_CNN)
model_A1 = A1(use_CNN)  # Build model object.
acc_A1_train = model_A1.train(train, val)
acc_A1_test = model_A1.test(test)

# acc_A1_train = model_A1.train(args...) # Train model based on the training set (you should fine-tune your model based on validation set.)
# acc_A1_test = model_A1.test(args...)   # Test model based on the test set.
# Clean up memory/GPU etc...             # Some code to free memory if necessary.

# ======================================================================================================================
# Task A2
# model_A2 = A2(args...)
# acc_A2_train = model_A2.train(args...)
# acc_A2_test = model_A2.test(args...)
train, val, test = data_preprocessing('celeba', 'smiling', use_CNN)
model_A2 = A2(use_CNN)  # Build model object.
acc_A2_train = model_A2.train(train, val)
                                                     68,
                                                     split=False)
# Task B1
x_train_B1, x_val_B1, y_train_B1, y_val_B1 = CV2_load_data.pre_processing(
    10000, 'face_shape', './Datasets/cartoon_set/', split=True)
x_test_B1, y_test_B1 = CV2_load_data.pre_processing(
    2500, 'face_shape', './Datasets/cartoon_set_test/', split=False)
# Task B2
x_train_B2, x_val_B2, y_train_B2, y_val_B2 = CV2_load_data.pre_processing(
    10000, 'eye_color', './Datasets/cartoon_set/', split=True)
x_test_B2, y_test_B2 = CV2_load_data.pre_processing(
    2500, 'eye_color', './Datasets/cartoon_set_test/', split=False)
# ======================================================================================================================
#====================================================Modeling===========================================================
# Task A1
model_A1 = A1.A1_SVM(x_train_A1, y_train_A1)  # Build model object.
acc_A1_train = A1.A1_acc(x_train_A1, y_train_A1,
                         model_A1)  # Train model based on the training set
acc_A1_test = A1.A1_acc(x_test_A1, y_test_A1,
                        model_A1)  # Test model based on the test set.
# Task A2
model_A2 = A2.A2_SVM(x_train_A2, y_train_A2)  # Build model object.
acc_A2_train = A2.A2_acc(x_train_A2, y_train_A2,
                         model_A2)  # Train model based on the training set
acc_A2_test = A2.A2_acc(x_test_A2, y_test_A2,
                        model_A2)  # Test model based on the test set.
# Task B1
model_B1 = B1.B1_CNN(x_train_B1, x_val_B1, y_train_B1,
                     y_val_B1)  # Build model object.
acc_B1_train = B1.B1_acc(x_train_B1, y_train_B1,
                         model_B1)  # Train model based on the training set
Beispiel #4
0
def load_file():
    data = A1(entry_file.get())
    print(data.get_statistics())
Beispiel #5
0
    else:
        #create histogram (vertical)
        pass


app = tk.Tk()
app.title("COMPSCI130 A1")
app.geometry('900x500')

label1 = tk.Label(app, text="File:")
label1.grid(column=0, row=0)

entry_file = tk.Entry(app)
entry_file.grid(column=1, row=0)
entry_file.insert(tk.END, 'trace40.txt')
data = A1(entry_file.get())

load_file_button = ttk.Button(app, text="Load", command=load_file)
load_file_button.grid(column=2, row=0)

entry_ip = tk.Entry(app)
entry_ip.grid(column=3, row=0)
entry_ip.insert(tk.END, '192.168.0.24')

label2 = tk.Label(app, text="Choose type:")
label2.grid(column=4, row=0)

comboData = ttk.Combobox(app, values=["Sum", "Freq", "Average"])
comboData.grid(column=5, row=0)
comboData.current(0)
import A1.A1 as A1
import A2.A2 as A2
import B1.B1 as B1
import B2.B2 as B2

# If this program does not work, try to change file names

# ======================================================================================================================
# Task A1
model_A1 = A1.A1()  # Build model object
print('A1 is processing...')
X_train_A1, y_train_A1 = model_A1.preprocess('./Datasets/celeba/img',
                                             './Datasets/celeba/labels.csv')
X_test_A1, y_test_A1 = model_A1.preprocess(
    './Datasets/celeba_test/img', './Datasets/celeba_test/labels.csv')

lr_model_A1 = model_A1.lr_model(X_train_A1,
                                y_train_A1)  # Logistic regression model
acc_A1_train = model_A1.train(
    X_train_A1, y_train_A1,
    lr_model_A1)  # Train model based on the training set
acc_A1_test = model_A1.test(X_test_A1, y_test_A1,
                            lr_model_A1)  # Test model based on the test set
print('A1 is finished')
# ======================================================================================================================
# Task A2
model_A2 = A2.A2()  # Build model object
print('A2 is processing...')
X_train_A2, y_train_A2 = model_A2.preprocess('./Datasets/celeba/img',
                                             './Datasets/celeba/labels.csv')
X_test_A2, y_test_A2 = model_A2.preprocess(
Beispiel #7
0
import pandas as pd
import seaborn as sns
from sklearn.model_selection import train_test_split
from data_preprocessing import get_data
from A1 import A1
from A2 import A2
from B1 import B1
from B2 import B2

# ======================================================================================================================
# Data preprocessing
smile_X_train, smile_y_train, smile_X_test, smile_y_test, gender_X_train, gender_y_train, gender_X_test, gender_y_test, eye_X_train, eye_y_train, eye_X_test, eye_y_test, face_X_train, face_y_train, face_X_test, face_y_test = get_data(
)
# ======================================================================================================================
# Task A1
model_A1 = A1.create_model()  # Build model object.
acc_A1_train, model_A1_trained = A1.train_model(
    model_A1, gender_X_train, gender_y_train
)  # Train model based on the training set (you should fine-tune your model based on validation set.)
acc_A1_test = A1.test_model(model_A1_trained, gender_X_test,
                            gender_y_test)  # Test model based on the test set.

#Clean up memory/GPU etc...             # Some code to free memory if necessary.

# ======================================================================================================================
# Task A2
model_A2 = A2.create_model()
acc_A2_train, model_A2_trained = A2.train_model(model_A2, smile_X_train,
                                                smile_y_train)
acc_A2_test = A2.test_model(model_A2_trained, smile_X_test, smile_y_test)