From 8d3fb5ca1c3068608d7f4d489fc03e5c480ee327 Mon Sep 17 00:00:00 2001 From: Makoto Shimazu Date: Tue, 11 Sep 2018 09:58:14 +0900 Subject: [PATCH 1/2] More consistent demo --- mozc-nazoru/bin/nazoru-input | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mozc-nazoru/bin/nazoru-input b/mozc-nazoru/bin/nazoru-input index 99839f5..9f7f7d3 100755 --- a/mozc-nazoru/bin/nazoru-input +++ b/mozc-nazoru/bin/nazoru-input @@ -23,6 +23,9 @@ LED_CHASSIS.on() time.sleep(1) LED_CHASSIS.off() +import warnings +warnings.filterwarnings("ignore", category=RuntimeWarning) + import argparse import os from nazoru import get_default_graph_path @@ -67,7 +70,16 @@ def main(): LED_CHASSIS.set_brightness(100) LED_RED.on() - result = predictor.predict_top_n(data, 5) + try: + result = predictor.predict_top_n(data, 5) + except IndexError: + # This is possible when pressing keys we don't use for learning. + print('Invalid input. (out of range)') + continue + except ValueError: + # This is possible when pressing only one key. + print('Invalid input. (one key)') + continue LED_RED.off() LED_CHASSIS.set_brightness(5) From 0fa69ac44013c17fab150650824df28e7720005b Mon Sep 17 00:00:00 2001 From: Makoto Shimazu Date: Tue, 11 Sep 2018 10:53:56 +0900 Subject: [PATCH 2/2] Move filterwarnings to the top and surpress FutureWarning too --- mozc-nazoru/bin/nazoru-input | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mozc-nazoru/bin/nazoru-input b/mozc-nazoru/bin/nazoru-input index 9f7f7d3..9fc0418 100755 --- a/mozc-nazoru/bin/nazoru-input +++ b/mozc-nazoru/bin/nazoru-input @@ -16,6 +16,12 @@ # limitations under the License. from __future__ import print_function + +# Surpress warnings. Please unvail these warnings when development. +import warnings +warnings.filterwarnings("ignore", category=RuntimeWarning) +warnings.filterwarnings("ignore", category=FutureWarning) + from nazoru.led import LED_BLUE, LED_RED, LED_CHASSIS import time LED_RED.blink(1) @@ -23,9 +29,6 @@ LED_CHASSIS.on() time.sleep(1) LED_CHASSIS.off() -import warnings -warnings.filterwarnings("ignore", category=RuntimeWarning) - import argparse import os from nazoru import get_default_graph_path