Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion hardware/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import json

## Used for printing statements to application console
def debugPrint(message):
print('BACKGROUND DEBUG PRINT:', message)
print('BACKGROUND DEBUG PRINT:', message)

## Call this function to send the predicted emotion to the desktop
## Calling this function will end this process
def sendPredictedEmotion(emotion: str) -> None:
print(json.dumps({ 'emotion' : emotion }))

## Call to signal to desktop that a connection has been established
def confirmConnection() -> None:
print(json.dumps({ 'hasConfirmed' : True }))
25 changes: 11 additions & 14 deletions hardware/hardware_starter.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import time
import json
import random
from common import debugPrint
from common import debugPrint, sendPredictedEmotion, confirmConnection
from LSL_helper import connectToEEG, recordEEG
from model_helper import predict_emotion


## Call this function to send the predicted emotion to the desktop
## Calling this function will end this process
def sendPredictedEmotion(emotion: str) -> None:
print(json.dumps({ 'emotion' : emotion }))

## Call to signal to desktop that a connection has been established
def confirmConnection() -> None:
print(json.dumps({ 'hasConfirmed' : True }))

# TODO: Error handling for None
# TODO: Add remaining model code
# The main EEG script that the desktop calls
stream_connection = connectToEEG()
if stream_connection == None:
debugPrint("Could not connect to EEG stream... disconnecting...")
exit()

confirmConnection()
data = recordEEG(stream_connection)
if data == None:
debugPrint("Could not record data from EEG headset... exiting.....")
exit()
Comment on lines +12 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these were tested?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also using raise RuntimeError('Some error message') to send an exception to standard error may be the better option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does sound like a better option, ill change it


emotion = predict_emotion(data)
debugPrint(f"the emotion was: {emotion}")
debugPrint(f"The predicted emotion was: {emotion}")
sendPredictedEmotion(emotion)
4 changes: 2 additions & 2 deletions hardware/model_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
except ImportError:
debugPrint("Unable to import Tensorflow! Is it installed?")

def predict_emotion(data: deque) -> None:
def predict_emotion(data: deque) -> str:
debugPrint("Loading model....")
model_path = f"{Path.cwd()}/model.h5"
model_path = f"{Path.cwd()}/checkpoints/model.h5"
cpu = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this always going to attempt to use GPU then? Whats the point of having the flag

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops I meant to change that, thank you

model_path
if cpu:
Expand Down
2 changes: 1 addition & 1 deletion hardware/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def build_model():

def train_model(model, train_X, train_Y, batch_size, epochs):
model.fit(train_X, train_y, batch_size=batch_size, epochs=epochs)
model.save("./model.h5")
model.save("./checkpoints/model.h5")