Beispiel #1
0
 def __init__(self, subjectIdependant=True):
     try:
         self.__h5file__ =  tb.openFile(FULL_SPECTROGRAM_BY_SUBJECT_CACHE, mode='r')
     except IOError:
         #todo, needs to regenerate the cache
         generate_per_subject_cache(get_interesting_heartrates(HEART_AV_ROOT))
         self.__h5file__ =  tb.openFile(FULL_SPECTROGRAM_BY_SUBJECT_CACHE, mode='r')
         pass
     self.__subjectIdependant = subjectIdependant
Beispiel #2
0
 def __init__(self, subjectIdependant=True):
     try:
         self.__h5file__ = tb.openFile(FULL_SPECTROGRAM_BY_SUBJECT_CACHE,
                                       mode='r')
     except IOError:
         #todo, needs to regenerate the cache
         generate_per_subject_cache(
             get_interesting_heartrates(HEART_AV_ROOT))
         self.__h5file__ = tb.openFile(FULL_SPECTROGRAM_BY_SUBJECT_CACHE,
                                       mode='r')
         pass
     self.__subjectIdependant = subjectIdependant
Beispiel #3
0
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.callbacks import EarlyStopping
from scipy.stats import pearsonr
from math import sqrt
from sklearn.metrics import mean_squared_error
from sklearn.cross_validation import train_test_split
from kbhit import KBHit

import numpy as np
import code
import itertools

kb = KBHit()
(X_train, y_train), (X_test, y_test) = full_bpm_to_data(get_interesting_heartrates(HEART_AV_ROOT))

# so it fits into memory without paging
reduce_to = int(X_train.shape[0] * 0.7)
X_train = X_train[:reduce_to]
y_train = y_train[:reduce_to]

mean = np.mean(y_train)
sd = np.std(y_train)
print(mean, sd)
# do this
def normalize_bpm(bpm):
    return (bpm - mean) / sd


def unnormalize_bpm(bpm):
Beispiel #4
0
                                                  (0, ), "Y_test")
                    Y_validate = h5file.create_earray(root, 'Y_validate',
                                                      tb.IntAtom(), (0, ),
                                                      "Y_validate")
                    X_append, y_append = X_test, Y_test
                X_append.append(np.array([elem]))
                y_append.append([bpm])
            h5file.flush()
            print("converted " + str(avi) + " for " + X_append.title + " set")
        else:
            print("Skipping " + ss_id + " becuase it isn't unique")
    h5file.close()


if __name__ == "__main__":
    generate_per_subject_cache(get_interesting_heartrates(HEART_AV_ROOT))

#    sw = None
#    for p in iterateThroughWav():
#        v = p.replace(".wav",".avi")
#        print(v)
#        sw = SubjectVideo(v)
#    plotSubjectWav(sw, 31*60+17)

# make_sure_path_exists("dat")
#                filename = os.path.join("dat", subjectStateId + "_" + str(timestamp))
#                memmap_elem = np.memmap(filename,dtype='float32',mode='w+', shape=(elem.shape))
#                memmap_elem[:] = elem[:]
#                del memmap_elem #flushes to disk
#                #make a ro version of it that goes into the list
#                ro_elem = np.memmap(filename,dtype='float32',mode='r', shape=elem.shape)
Beispiel #5
0
from spectrogram import bpm_to_data
from get_heartrates import get_interesting_heartrates
from convertToWav import VIDEO_ROOT
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.optimizers import SGD
from keras.utils import np_utils, generic_utils

import random
import numpy as np
import code
#dumy_data_subject1 = [(i*5 + 1, random.randint(lowest_bpm, highest_bpm)) for i in range(1,200)]
#dumy_data = {35 : dumy_data_subject1}

(X_train, y_train), (X_test, y_test) = bpm_to_data(get_interesting_heartrates("C:\\Uni\\HeartAV"))

lowest_bpm = min(min(y_train) , min(y_test))
highest_bpm = max(max(y_train) , max(y_test))
scale = 1
nb_classes = (highest_bpm - lowest_bpm + 1*scale) // scale
#code.interact(local=locals())

print(highest_bpm, lowest_bpm, nb_classes)

#code.interact(local=locals())
#y_train = list(map(lambda x : (x - lowest_bpm)//scale, y_train))
#y_test = list(map(lambda x : (x - lowest_bpm) //scale, y_test))
# convert class vectors to binary class matrices
# converts a number to unary so 4 is 0001
#Y_train = np_utils.to_categorical(y_train, nb_classes)
Beispiel #6
0
from get_heartrates import get_interesting_heartrates
from convertToWav import VIDEO_ROOT
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.optimizers import SGD
from keras.utils import np_utils, generic_utils

import random
import numpy as np
import code
#dumy_data_subject1 = [(i*5 + 1, random.randint(lowest_bpm, highest_bpm)) for i in range(1,200)]
#dumy_data = {35 : dumy_data_subject1}

(X_train, y_train), (X_test, y_test) = bpm_to_data(
    get_interesting_heartrates("C:\\Uni\\HeartAV"))

lowest_bpm = min(min(y_train), min(y_test))
highest_bpm = max(max(y_train), max(y_test))
scale = 1
nb_classes = (highest_bpm - lowest_bpm + 1 * scale) // scale
#code.interact(local=locals())

print(highest_bpm, lowest_bpm, nb_classes)

#code.interact(local=locals())
#y_train = list(map(lambda x : (x - lowest_bpm)//scale, y_train))
#y_test = list(map(lambda x : (x - lowest_bpm) //scale, y_test))
# convert class vectors to binary class matrices
# converts a number to unary so 4 is 0001
#Y_train = np_utils.to_categorical(y_train, nb_classes)
Beispiel #7
0
                    Y_train = h5file.create_earray(root,'Y_train',tb.IntAtom(), (0,),"Y_train")
                    Y_test = h5file.create_earray(root,'Y_test',tb.IntAtom(), (0,),"Y_test")
                    Y_validate = h5file.create_earray(root,'Y_validate',tb.IntAtom(), (0,),"Y_validate")
                    X_append, y_append = X_test, Y_test
                X_append.append(np.array([elem]))
                y_append.append([bpm])
            h5file.flush()
            print("converted " + str(avi) +  " for " + X_append.title + " set")
        else:
            print("Skipping " + ss_id + " becuase it isn't unique")
    h5file.close()



if __name__ == "__main__":
    generate_per_subject_cache(get_interesting_heartrates(HEART_AV_ROOT))

#    sw = None
#    for p in iterateThroughWav():
#        v = p.replace(".wav",".avi")
#        print(v)
#        sw = SubjectVideo(v)
#    plotSubjectWav(sw, 31*60+17)

# make_sure_path_exists("dat")
#                filename = os.path.join("dat", subjectStateId + "_" + str(timestamp))
#                memmap_elem = np.memmap(filename,dtype='float32',mode='w+', shape=(elem.shape))
#                memmap_elem[:] = elem[:]
#                del memmap_elem #flushes to disk
#                #make a ro version of it that goes into the list
#                ro_elem = np.memmap(filename,dtype='float32',mode='r', shape=elem.shape)
Beispiel #8
0
import os
import sys
import numpy as np
from face_analyser import analyse_video

path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data_analysis'))
if not path in sys.path:
    sys.path.insert(1, path)
del path
from get_heartrates import get_heartrates, get_interesting_heartrates

PATH_TO_HEARTAV =  "E:\\HeartAV"
WINDOW_SIZE = 4

heartrates = get_heartrates(PATH_TO_HEARTAV)
intersting_heartrates = get_interesting_heartrates(PATH_TO_HEARTAV, window=1)

def write_cache(cache_file, data):
    with open(cache_file,'wb') as f:
        pickle.dump(data, f, protocol=pickle.HIGHEST_PROTOCOL)


face_data = {}
specifications = {}
for subject_state in intersting_heartrates.keys():
    times = []
    data_for_subject = intersting_heartrates[subject_state]

    start_of_section = int(data_for_subject[0][1])
    last_time = start_of_section
    for datum in data_for_subject:
Beispiel #9
0
import sys
import numpy as np
from face_analyser import analyse_video

path = os.path.abspath(
    os.path.join(os.path.dirname(__file__), '../data_analysis'))
if not path in sys.path:
    sys.path.insert(1, path)
del path
from get_heartrates import get_heartrates, get_interesting_heartrates

PATH_TO_HEARTAV = "E:\\HeartAV"
WINDOW_SIZE = 4

heartrates = get_heartrates(PATH_TO_HEARTAV)
intersting_heartrates = get_interesting_heartrates(PATH_TO_HEARTAV, window=1)


def write_cache(cache_file, data):
    with open(cache_file, 'wb') as f:
        pickle.dump(data, f, protocol=pickle.HIGHEST_PROTOCOL)


face_data = {}
specifications = {}
for subject_state in intersting_heartrates.keys():
    times = []
    data_for_subject = intersting_heartrates[subject_state]

    start_of_section = int(data_for_subject[0][1])
    last_time = start_of_section
Beispiel #10
0
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.callbacks import EarlyStopping
from scipy.stats import pearsonr
from math import sqrt
from sklearn.metrics import mean_squared_error
from sklearn.cross_validation import train_test_split
from kbhit import KBHit

import numpy as np
import code
import itertools

kb = KBHit()
(X_train, y_train), (X_test, y_test) = full_bpm_to_data(get_interesting_heartrates(HEART_AV_ROOT))

#so it fits into memory without paging
reduce_to = int(X_train.shape[0] * 0.7)
X_train = X_train[:reduce_to]
y_train = y_train[:reduce_to]

mean = np.mean(y_train)
sd = np.std(y_train)
print(mean,sd)
#do this
def normalize_bpm(bpm):
    return (bpm - mean) / sd

def unnormalize_bpm(bpm):
    return (bpm  * sd) + mean