Skip to content

Commit

Permalink
Upload anonymous version
Browse files Browse the repository at this point in the history
  • Loading branch information
PSSF23 committed May 28, 2021
1 parent 2962281 commit 74f9118
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 369 deletions.
5 changes: 0 additions & 5 deletions audio/audio_toolbox.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
Madi Kusmanov
"""
import numpy as np
from sklearn.metrics import accuracy_score
import time
Expand Down
47 changes: 21 additions & 26 deletions audio/fsdd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
Madi Kusmanov
"""
from audio_toolbox import *
import numpy as np
from sklearn.svm import SVC
Expand All @@ -19,7 +14,7 @@

def write_result(filename, acc_ls):
with open(filename, 'a') as testwritefile:
for acc in acc_ls:
for acc in acc_ls:
testwritefile.write(str(acc) + "\n")

# prepare FSDD data
Expand All @@ -31,7 +26,7 @@ def main():
n_classes = int(args.m)
feature_type = str(args.f)
path_recordings = 'recordings/'

#data is normalized upon loading
#load dataset
x_spec, y_number = load_spoken_digit(path_recordings, feature_type)
Expand All @@ -45,16 +40,16 @@ def main():
prefix = args.m + "_class/"
elif feature_type == 'mfcc':
prefix = args.m + "_class_mfcc/"

#create list of classes with const random seed
random.Random(5).shuffle(nums)
classes_space = list(combinations_45(nums, n_classes, comb))
print(classes_space)

#scale the data
x_spec = scale(x_spec.reshape(3000, -1), axis=1).reshape(3000, 32, 32)
y_number = np.array(y_number)

#need to take train/valid/test equally from each class
trainx = np.zeros((1, 32, 32))
trainy = np.zeros((1))
Expand All @@ -65,13 +60,13 @@ def main():
trainx = np.concatenate((trainx, x_spec[i * 300: (i + 1) * 3000][shuffler][:240]))
trainy = np.concatenate((trainy, y_number[i * 300: (i + 1) * 3000][shuffler][:240]))
testx = np.concatenate((testx, x_spec[i * 300: (i + 1) * 3000][shuffler][240:]))
testy = np.concatenate((testy, y_number[i * 300: (i + 1) * 3000][shuffler][240:]))
testy = np.concatenate((testy, y_number[i * 300: (i + 1) * 3000][shuffler][240:]))
trainx = trainx[1:]
trainy = trainy[1:]
trainy = trainy[1:]
testx = testx[1:]
testy = testy[1:]


#3000 samples, 80% train is 2400 samples, 20% test
fsdd_train_images = trainx.reshape(-1, 32 * 32)
fsdd_train_labels = trainy.copy()
Expand All @@ -80,7 +75,7 @@ def main():
fsdd_test_labels = testy.copy()


# Resnet18
# Resnet18
resnet18_acc_vs_n = list()
resnet18_train_time = list()
resnet18_test_time = list()
Expand All @@ -89,7 +84,7 @@ def main():
# accuracy vs num training samples (resnet18)
for samples in samples_space:
resnet = models.resnet18(pretrained=True)

num_ftrs = resnet.fc.in_features
resnet.fc = nn.Linear(num_ftrs, len(classes))
# train data
Expand All @@ -103,12 +98,12 @@ def main():
train_images, train_labels, valid_images, valid_labels, test_images, \
test_labels = prepare_data(train_images, train_labels, test_images, \
test_labels, samples, classes)

#need to duplicate channel because batch norm cant have 1 channel images
train_images = torch.cat((train_images, train_images, train_images), dim=1)
valid_images = torch.cat((valid_images, valid_images, valid_images), dim=1)
test_images = torch.cat((test_images, test_images, test_images), dim=1)

accuracy, train_time, test_time = run_dn_image_es(
resnet,
train_images, train_labels,
Expand All @@ -124,7 +119,7 @@ def main():
write_result(prefix + "resnet18_train_time.txt", resnet18_train_time)
write_result(prefix + "resnet18_test_time.txt", resnet18_test_time)


# Support Vector Machine
svm_acc_vs_n = list()
svm_train_time = list()
Expand Down Expand Up @@ -172,7 +167,7 @@ def main():
train_images, train_labels, valid_images, valid_labels, test_images, \
test_labels = prepare_data(train_images, train_labels, test_images, \
test_labels, samples, classes)

accuracy, train_time, test_time = run_dn_image_es(
cnn32,
train_images, train_labels,
Expand All @@ -187,7 +182,7 @@ def main():
write_result(prefix + "cnn32.txt", cnn32_acc_vs_n)
write_result(prefix + "cnn32_train_time.txt", cnn32_train_time)
write_result(prefix + "cnn32_test_time.txt", cnn32_test_time)

# Naive Random Forest
naive_rf_acc_vs_n = list()
naive_rf_train_time = list()
Expand All @@ -206,7 +201,7 @@ def main():
samples,
classes,
)

naive_rf_acc_vs_n.append(accuracy)
naive_rf_train_time.append(train_time)
naive_rf_test_time.append(test_time)
Expand All @@ -225,7 +220,7 @@ def main():

# accuracy vs num training samples (cnn32_2l)
for samples in samples_space:

cnn32_2l = SimpleCNN32Filter2Layers(len(classes))
#3000 samples, 80% train is 2400 samples, 20% test
train_images = trainx.copy()
Expand All @@ -237,7 +232,7 @@ def main():
train_images, train_labels, valid_images, valid_labels, test_images, \
test_labels = prepare_data(train_images, train_labels, test_images, \
test_labels, samples, classes)

accuracy, train_time, test_time = run_dn_image_es(
cnn32_2l,
train_images, train_labels,
Expand All @@ -262,7 +257,7 @@ def main():

# accuracy vs num training samples (cnn32_5l)
for samples in samples_space:

cnn32_5l = SimpleCNN32Filter5Layers(len(classes))
#3000 samples, 80% train is 2400 samples, 20% test
train_images = trainx.copy()
Expand All @@ -274,7 +269,7 @@ def main():
train_images, train_labels, valid_images, valid_labels, test_images, \
test_labels = prepare_data(train_images, train_labels, test_images, \
test_labels, samples, classes)

accuracy, train_time, test_time = run_dn_image_es(
cnn32_5l,
train_images, train_labels,
Expand Down
4 changes: 0 additions & 4 deletions image/cifar_10.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
from toolbox import *

import argparse
Expand Down
4 changes: 0 additions & 4 deletions image/cifar_100.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
from toolbox import *

import argparse
Expand Down
4 changes: 0 additions & 4 deletions image/cifar_100_stc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
from toolbox import *

import argparse
Expand Down
4 changes: 0 additions & 4 deletions image/cifar_10_stc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
from toolbox import *

import argparse
Expand Down
4 changes: 0 additions & 4 deletions image/svhn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
from svhn_toolbox import *

import argparse
Expand Down
4 changes: 0 additions & 4 deletions image/svhn_toolbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
import time
import numpy as np
from sklearn.metrics import accuracy_score
Expand Down
4 changes: 0 additions & 4 deletions image/toolbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Coauthors: Yu-Chung Peng
Haoyin Xu
"""
import time
import numpy as np
from sklearn.metrics import accuracy_score
Expand Down
299 changes: 1 addition & 298 deletions tabular/cc18_figures.ipynb

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions tabular/cc18_hyperparameter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Author: Michael Ainsworth
"""

import numpy as np
import matplotlib.pyplot as plt
from random import sample
Expand Down
4 changes: 0 additions & 4 deletions tabular/cc18_kappaece.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Author: Michael Ainsworth
"""

import numpy as np
import matplotlib.pyplot as plt
from random import sample
Expand Down
4 changes: 0 additions & 4 deletions tabular/cc18_times.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
"""
Author: Michael Ainsworth
"""

import numpy as np
import matplotlib.pyplot as plt
from random import sample
Expand Down

0 comments on commit 74f9118

Please sign in to comment.