{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!zip /kaggle/working/submission.zip /kaggle/input/asl-submission/inference_args.json /kaggle/input/asl-submission/model.tflite","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:39:08.557771Z","iopub.execute_input":"2023-08-24T21:39:08.558145Z","iopub.status.idle":"2023-08-24T21:39:11.731518Z","shell.execute_reply.started":"2023-08-24T21:39:08.558111Z","shell.execute_reply":"2023-08-24T21:39:11.730444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_dir = '/kaggle/input/asl-submission'","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:01.673721Z","iopub.execute_input":"2023-08-24T21:15:01.674063Z","iopub.status.idle":"2023-08-24T21:15:01.679413Z","shell.execute_reply.started":"2023-08-24T21:15:01.674031Z","shell.execute_reply":"2023-08-24T21:15:01.67811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nwith open(f'{sub_dir}/inference_args.json', 'r') as fp:\n    j = json.load(fp)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:01.680718Z","iopub.execute_input":"2023-08-24T21:15:01.681013Z","iopub.status.idle":"2023-08-24T21:15:01.693123Z","shell.execute_reply.started":"2023-08-24T21:15:01.680989Z","shell.execute_reply":"2023-08-24T21:15:01.692086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install tflite-runtime-nightly==2.14.0.dev20230508","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:01.694854Z","iopub.execute_input":"2023-08-24T21:15:01.69519Z","iopub.status.idle":"2023-08-24T21:15:15.403251Z","shell.execute_reply.started":"2023-08-24T21:15:01.695161Z","shell.execute_reply":"2023-08-24T21:15:15.402107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\n\n# frames = np.random.uniform(0, 1, (0, 84)).astype(np.float32)\nframes = np.zeros((0, 84)).astype(np.float32)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:15.405921Z","iopub.execute_input":"2023-08-24T21:15:15.406369Z","iopub.status.idle":"2023-08-24T21:15:15.412073Z","shell.execute_reply.started":"2023-08-24T21:15:15.406333Z","shell.execute_reply":"2023-08-24T21:15:15.410756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tflite_runtime.interpreter as tflite\n\ninterpreter = tflite.Interpreter(f\"{sub_dir}/model.tflite\")\n\nREQUIRED_SIGNATURE = \"serving_default\"\nREQUIRED_OUTPUT = \"outputs\"\n\nwith open (\"/kaggle/input/asl-fingerspelling/character_to_prediction_index.json\", \"r\") as f:\n    character_map = json.load(f)\nrev_character_map = {j:i for i,j in character_map.items()}\n\nfound_signatures = list(interpreter.get_signature_list().keys())\n\nif REQUIRED_SIGNATURE not in found_signatures:\n    raise KernelEvalException('Required input signature not found.')\n\nprediction_fn = interpreter.get_signature_runner(\"serving_default\")\noutput = prediction_fn(inputs=frames)\nprediction_str = \"\".join([rev_character_map.get(s, \"\") for s in np.argmax(output[REQUIRED_OUTPUT], axis=1)])\nprint(prediction_str)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:15.413642Z","iopub.execute_input":"2023-08-24T21:15:15.414006Z","iopub.status.idle":"2023-08-24T21:15:15.564682Z","shell.execute_reply.started":"2023-08-24T21:15:15.413974Z","shell.execute_reply":"2023-08-24T21:15:15.5635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%timeit\noutput = prediction_fn(inputs=frames)","metadata":{"execution":{"iopub.status.busy":"2023-08-24T21:15:15.566214Z","iopub.execute_input":"2023-08-24T21:15:15.566667Z","iopub.status.idle":"2023-08-24T21:15:22.448933Z","shell.execute_reply.started":"2023-08-24T21:15:15.566632Z","shell.execute_reply":"2023-08-24T21:15:22.44722Z"},"trusted":true},"execution_count":null,"outputs":[]}]}