예제 #1
0
def addPatron(fn, ln):
    conn = sqlite3.connect(Config.getDBFileName())
    c = conn.cursor()
    fn = fn.upper()
    ln = ln.upper()
    date = getAmerDate()
    record = (fn, ln, date)
    c.execute('INSERT INTO vcl VALUES (?,?,?)', record)
    conn.commit()
    conn.close()
 def __init__(self, user, depth=1):
     self.user = user
     self.depth = depth
     self.error_profiles = set()
     self.config = Config()
     self.profiles = {str(user): {"personaname": "", "friends": []}}
     self.db = MySQLdb.connect(host=self.config.db_host,
                               user=self.config.db_user,
                               passwd=self.config.db_pw,
                               db=self.config.db)
예제 #3
0
 def __init__(self, verbose=True):
     self.config = Config()
     self.verbose = verbose
     self.db = MySQLdb.connect(host=self.config.db_host,
                               user=self.config.db_user,
                               passwd=self.config.db_pw,
                               db=self.config.db)
     self.q = Queue()
     self.db.autocommit(on=True)
     self.db.set_character_set('utf8')
     with self.db.cursor() as dbc:
         dbc.execute('SET NAMES utf8;')
         dbc.execute('SET CHARACTER SET utf8;')
         dbc.execute('SET character_set_connection=utf8;')
예제 #4
0
def checkForBan(lnfn):
    conn = sqlite3.connect(Config.getDBFileName())
    c = conn.cursor()
    lnfnarr = nameVAndF(lnfn)
    if not lnfnarr:
        return ["ERROR: Incorrect formatting."]
    ln = lnfnarr[0]
    fn = lnfnarr[1]
    c.execute('SELECT * FROM banned_patrons WHERE fname=? AND lname=?', (fn, ln))
    res = c.fetchall()
    conn.close()
    if res:
        return res[0]
    else:
        return False
예제 #5
0
def addBannedPatron(fn, ln, bd, ed, barcode, muni, reason, additional_info):
    current_table = getAll('banned_patrons')
    if not current_table:
        logTC("First record created")
        idnum = 1
    else:
        highest = current_table[0][0]
        for record in current_table:
            if record[0] > highest:
                highest = record[0]
            else:
                pass
        idnum = highest + 1
    conn = sqlite3.connect(Config.getDBFileName())
    c = conn.cursor()
    fn = fn.upper()
    ln = ln.upper()
    muni = muni.upper()
    record = (idnum, fn, ln, bd, ed, barcode, muni, reason, additional_info)
    c.execute('INSERT INTO banned_patrons VALUES (?,?,?,?,?,?,?,?,?)', record)
    conn.commit()
    conn.close()
예제 #6
0
파일: main.py 프로젝트: MJ-meo-dmt/rollin
    def __init__(self):
        ShowBase.__init__(self)
        # Load app configs
        self.config = Config(self)
        self.debug = False

        ## EVENT HANDLER ##
        self.event = Event(self)

        # Event keeper
        self.events = {
            "player-reset": self.event.doReset,
            "change-movement": self.event.doChangeMovement
        }

        # Accept Events
        for eventName in self.events.keys():
            self.accept(eventName, self.events[eventName])

        # Game.
        self.game = Game(self)

        self.accept('escape', self.game.stopGame)
예제 #7
0
def checkForDB():
    try:
        conn = sqlite3.connect(Config.getDBFileName())
        conn.close()
    except sqlite3.Error:
        return False
예제 #8
0
            mask.append(False)
    return mask


def find_wavdir(index):
    for (root, subdirs, filenames) in walk(config.train_dir):
        for search in subdirs:
            path = root + '/' + search
            for (_, _, filenames) in walk(path):
                for filename in filenames:
                    if index == filename:
                        wavdir = path + '/' + index
                        return wavdir


config = Config('conv')

df = pd.read_csv(config.train_cats + '.csv')
df.set_index('fname', inplace=True)

for f in df.index:
    wavdir = find_wavdir(f)
    try:
        rate, signal, _ = wavfile.read(wavdir)
        df.at[f, 'length'] = signal.shape[0] / rate
    except:
        print(sys.exc_info()[0])
    #gives the legnth of the signal in terms of seconds

classes = list(np.unique(df.label))
class_dist = df.groupby(['label'])['length'].mean()
예제 #9
0
n_samples = 2 * int(df['length'].sum() / 0.1)
prob_dist = class_dist / class_dist.sum()
choices = np.random.choice(class_dist.index, p=prob_dist)

fig, ax = plt.subplots()
ax.set_title('Class Distribution', y=1.08)
ax.pie(class_dist,
       labels=class_dist.index,
       autopct='%1.1f%%',
       shadow=False,
       startangle=90)
ax.axis('equal')
plt.show()

config = Config(mode='time')

if config.mode == 'conv':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2], 1)
    model = get_conv_model()

elif config.mode == 'time':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2])
    model = get_recurrent_model()

class_weight = compute_class_weight('balanced', np.unique(y_flat), y_flat)
예제 #10
0
classes = list(np.unique(df.label)) #classes = class names ([burping, hungry,...])
class_dist = df.groupby(['label'])['length'].mean() #average length of each class wav files

#print the class distribution
'''
fig, ax = plt.subplots()
ax.set_title('Class Distribution', y=1.08)
ax.pie(class_dist, labels=class_dist.index, autopct='%1.1f%%',
       shadow=False, startangle=90)
ax.axis('equal')
plt.show()
'''

#initialize variables
config = Config(mode='conv') #basic variables
X, y = build_rand_feat() #return random samples from the classes to prevent class inbalance, and return the mfcc version not the time domain


if config.mode == 'conv':
    input_shape = (X.shape[1], X.shape[2], 1)
    model = get_conv_model()
elif config.mode == 'time':
    input_shape = (X.shape[1], X.shape[2])
    model = get_recurrent_model()


y_flat = np.argmax(y, axis=1) #return the index corresponding to the 1 value in the y array
classWeight = compute_class_weight('balanced', np.unique(y_flat), y_flat) #A way to modify the hyperparameters a little bit to reduce the bias and improve accuracy a little bit
checkpoint = ModelCheckpoint(config.model_path, monitor='val_acc', verbose=1
                             , mode='max', save_best_only=True, save_weights_only=False, period=1) #this line makes us update the model we saved before only if there is an acc improvement
예제 #11
0
        Conv2D(16, (3, 3), activation="relu", strides=(1, 1), padding="same"))
    model.add(MaxPool2D(2, 2))
    model.add(Dropout(0.5))
    model.add(Flatten())
    model.add(Dense(128, activation="relu"))
    model.add(Dense(64, activation="relu"))
    model.add(Dense(10, activation="softmax"))
    model.summary()
    model.compile(loss="categorical_crossentropy",
                  optimizer="adam",
                  metrics=["acc"])
    return model


#build two directoies one "model" "pickle" (model data)
config = Config(mode="time")

#read training set+label csv
df = pd.read_csv('instruments.csv')
df.set_index('fpath', inplace=True)  #set filepath as index

for f in df.index:  #
    rate, signal = wavfile.read('clean/' + f)
    df.at[f, 'length'] = signal.shape[0] / rate

classes = list(np.unique(df.label))
#create a new column of length based on signal length
class_dist = df.groupby(['label'])['length'].mean()

fig, ax = plt.subplots()
ax.set_title('Class Distribution', y=1.08)
import os
import json

from cfg import Config

save_path = './tests/test.json'

cfg = Config()
cfg.save_dir = 'ALEX TESTING'
cfg.batch_size = 144

cfg.save_config(save_path)

with open(save_path, 'r') as f:
    saved_dict = json.load(f)

assert saved_dict['save_dir'] == 'ALEX TESTING'
assert saved_dict['batch_size'] == 144
예제 #13
0
df = pd.read_csv('maestro-v2.0.0.csv')
df['audio_filename'] = df['audio_filename'].str[5:]
df.set_index('audio_filename', inplace=True)

#manually set the classes
classes = ['Baroque', 'Classical', 'Romantic', 'Modern']
classifier = 'period'
class_dist = df.groupby(classifier).period.agg('count').to_frame('countt')

leakyrelu = LeakyReLU(alpha=0.3)
activation_layer = leakyrelu

figsize = 8

#change this for setting machine learning configuration: 'svm', 'time' or 'conv' for mode, and 'chroma' or 'mfcc' for feature
config = Config(mode='svm', feature='chroma')
#for convolutional networks about 6 epochs works best. for LSTMS it is about 9.
epochs = 6


#check if data already exists and open it if yes
def check_data():
    if os.path.isfile(config.p_path):
        print('Loading existing data for {} model with {} features'.format(
            config.mode, config.feature))
        with open(config.p_path, 'rb') as handle:
            tmp = pickle.load(handle)
            return tmp
    else:
        return None
예제 #14
0
prob_dist = class_dist / class_dist.sum(
)  #this will convert everything between 0 and 1 (probability)
choices = np.random.choice(class_dist.index,
                           p=prob_dist)  #no clue what this does

fig, ax = plt.subplots()
ax.set_title('Class Distribution', y=1.08)
ax.pie(class_dist,
       labels=class_dist.index,
       autopct='%1.1f%%',
       shadow=False,
       startangle=90)
ax.axis('equal')
plt.show()

config = Config(
    mode='time')  #use mode = 'conv' for cnn and mode = 'time' for rnn

#what happens if it runs in convolution
if config.mode == 'conv':
    X, y = build_rand_feat(
    )  #this will form the feature set from the random sampling done above
    y_flat = np.argmax(
        y, axis=1
    )  #we are returning the hot encoded index value of labels to the original string labels
    input_shape = (X.shape[1], X.shape[2], 1)
    model = get_conv_model()

elif config.mode == 'time':  #for reccurent neural network
    X, y = build_rand_feat()
    y_flat = np.argmax(
        y, axis=1
예제 #15
0
import cv2
import numpy as np
from vo import vo
from cfg import Config
from frame import Frame
from matplotlib import pyplot as plt

conf = Config('./cfg/freiburg.json')

vio = vo(conf)
outfile = './out.txt'
x = 1.33
y = 0.64
z = 1.65
# imgs = []
# deps=[]
#
# f=plt.figure()
#
# for i in [1,2]:
#     imgs.append(cv2.imread('./data/'+str(i)+'.png'))
#     deps.append(cv2.imread('./data/'+str(i)+'d.png', -1))
#
# for i in range(len(imgs)):
#     id = int(i)
#     fr = Frame(id=id,
#                img=imgs[i],
#                depth=deps[i],
#                camera=vio.camera
#                )
#     vio.add_frame(fr,visual=True)
예제 #16
0
from datasets import get_dataloaders
from cfg import Config

cfg = Config()
train_loader, val_loader, test_loader = get_dataloaders(cfg)
예제 #17
0
    return X, y


df = pd.read_csv(
    "/content/drive/MyDrive/Audio Signal Processing/Clean Data/instruments_clean.csv"
)
df.set_index('Index', inplace=True)

classes = list(np.unique(df.Label))
class_dist = df.groupby(['Label'])['length'].mean()

n_samples = 2 * int(df['length'].sum() / 0.1)
prob_dist = class_dist / class_dist.sum()  #Probability Distribution
choices = np.random.choice(class_dist.index, p=prob_dist)

config = Config(mode='conv')
if config.mode == 'conv':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2], 1)
    model = get_conv_model()

elif config.mode == 'time':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2])
    model = get_recurrent_model()

class_weight = compute_class_weight('balanced', np.unique(y_flat), y_flat)
model.fit(X,
          y,
예제 #18
0
파일: model.py 프로젝트: ma75442/projects
n_samples = 2 * int(df['length'].sum() / 0.1)
prob_dist = class_dist / class_dist.sum()
choices = np.random.choice(class_dist.index, p=prob_dist)

fig, ax = plt.subplots()
ax.set_title('Class Distribution', y=1.08)
ax.pie(class_dist,
       labels=class_dist.index,
       autopct='%1.1f%%',
       shadow=False,
       startangle=90)
ax.axis('equal')
#plt.show()

config = Config(mode='time')  #For selecting between CNN and RNN

if config.mode == 'conv':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2], 1)
    model = get_conv_model()
elif config.mode == 'time':
    X, y = build_rand_feat()
    y_flat = np.argmax(y, axis=1)
    input_shape = (X.shape[1], X.shape[2])
    model = get_recurrent_model()

class_weight = compute_class_weight('balanced', np.unique(y_flat), y_flat)

checkpoint = ModelCheckpoint(config.model_path,