This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = load_model('./models/tr_model.h5') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has_new_triggerword(predictions, chunk_duration, feed_duration, threshold=0.5): | |
""" | |
Function to detect new trigger word in the latest chunk of input audio. | |
It is looking for the rising edge of the predictions data belongs to the | |
last/latest chunk. | |
Argument: | |
predictions -- predicted labels from model | |
chunk_duration -- time in second of a chunk | |
feed_duration -- time in second of the input to model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
from queue import Queue | |
from threading import Thread | |
import sys | |
import time | |
# Queue to communiate between the audio callback and main thread | |
q = Queue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.applications import inception_v3 as inc_net | |
inet_model = inc_net.InceptionV3() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
images = transform_img_fn([os.path.join('data','asian-african-elephants.jpg')]) | |
preds = inet_model.predict(images) | |
for x in decode_predictions(preds)[0]: | |
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lime | |
from lime import lime_image | |
explainer = lime_image.LimeImageExplainer() | |
explanation = explainer.explain_instance(images[0], inet_model.predict, | |
top_labels=5, | |
hide_color=0, | |
num_samples=1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Indian_elephant = get_class_index("Indian_elephant") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.segmentation import mark_boundaries | |
temp, mask = explanation.get_image_and_mask(Indian_elephant, positive_only=True, num_features=5, hide_rest=True) | |
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
African_elephant = get_class_index("African_elephant") | |
temp, mask = explanation.get_image_and_mask(African_elephant, positive_only=True, num_features=5, hide_rest=True) | |
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
temp, mask = explanation.get_image_and_mask(Indian_elephant, positive_only=False, num_features=10, hide_rest=False) | |
plt.imshow(mark_boundaries(temp / 2 + 0.5, mask)) |