Skip to content

Commit

Permalink
ml: use test set to evaluate performance
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Gloor <code@stefan-gloor.ch>
  • Loading branch information
stgloorious committed Jun 8, 2024
1 parent a771fbb commit fd79d8e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/eval_testset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def get_spectrogram(waveform):
yes = 0
no = 0
# TODO Change the directories to evaluate HERE
for file in tqdm(os.listdir('../ml/data/mini_speech_commands/train/no')):
for file in tqdm(os.listdir('../ml/data/mini_speech_commands/test/yes')):
#x = '../ml/data/mini_speech_commands/yes/5184ed3e_nohash_0.wav'
x = tf.io.read_file(str(os.path.join('../ml/data/mini_speech_commands/train/no/', file)))
x = tf.io.read_file(str(os.path.join('../ml/data/mini_speech_commands/test/yes/', file)))
x, sample_rate = tf.audio.decode_wav(x, desired_channels=1, desired_samples=16000,)
x = tf.squeeze(x, axis=-1)
waveform = x
Expand Down Expand Up @@ -120,8 +120,12 @@ def required_blocks(filesize, blocksize):
speed = filesize / total_time / 1024.0
#print(f'Transaction completed successfully ({speed:.2f} kiB/s, {naks} retransmissions)')

ser.timeout = 1
# The timeout should be larger than the time it takes for the inference
# on optimized and unoptimized tensorflow kernels
ser.timeout = 0.35
last = False
dt = 0
prediction = '?'
while True:
c = ser.read().decode('utf-8')
if (c == ''): #timeout
Expand All @@ -143,6 +147,6 @@ def required_blocks(filesize, blocksize):

with open('log.csv', 'a') as f:
# TODO change the percentage calculation HERE
f.write(f'{datetime.datetime.now().isoformat()},{file},{dt},{prediction},{yes},{no},{no/(yes+no):.02%}\n')
f.write(f'{datetime.datetime.now().isoformat()},{file},{dt},{prediction},{yes},{no},{yes/(yes+no):.02%}\n')

ser.close()

0 comments on commit fd79d8e

Please sign in to comment.