{"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":"import pandas as pd\nimport numpy as np\nimport tensorflow as tf","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-24T18:52:05.231969Z","iopub.execute_input":"2023-02-24T18:52:05.232369Z","iopub.status.idle":"2023-02-24T18:52:05.238268Z","shell.execute_reply.started":"2023-02-24T18:52:05.232334Z","shell.execute_reply":"2023-02-24T18:52:05.236993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create a model using high-level tf.keras.* APIs\nmodel = tf.keras.models.Sequential([\n    tf.keras.layers.Input(shape=(None, 3), batch_size=1, name='inputs'),\n    tf.keras.layers.GlobalAveragePooling1D(), #this is here to convert from (-1, 3) input into (3) shaped input \n    tf.keras.layers.Dense(units=3),\n    tf.keras.layers.Dense(units=16, activation='relu'),\n    tf.keras.layers.Dense(units=250, name='outputs', activation='sigmoid')\n])\nmodel.compile(optimizer='sgd', loss='mean_squared_error') # compile the model\n#model.fit(x=X, y=Y, epochs=5) # train the model\n# (to generate a SavedModel) tf.saved_model.save(model, \"saved_model_keras_dir\")\n\n# Convert the model.\nconverter = tf.lite.TFLiteConverter.from_keras_model(model)\ntflite_model = converter.convert()\n\n# Save the model.\nwith open('model.tflite', 'wb') as f:\n    f.write(tflite_model)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:52:06.917185Z","iopub.execute_input":"2023-02-24T18:52:06.917683Z","iopub.status.idle":"2023-02-24T18:52:07.736411Z","shell.execute_reply.started":"2023-02-24T18:52:06.917638Z","shell.execute_reply":"2023-02-24T18:52:07.734796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nROWS_PER_FRAME = 543  # number of landmarks per frame\n\ndef load_relevant_data_subset(pq_path):\n    data_columns = ['x', 'y', 'z']\n    data = pd.read_parquet(pq_path, columns=data_columns)\n    n_frames = int(len(data) / ROWS_PER_FRAME)\n    data = data.values.reshape(n_frames, ROWS_PER_FRAME, len(data_columns))\n    return data.astype(np.float32)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:52:08.683872Z","iopub.execute_input":"2023-02-24T18:52:08.684308Z","iopub.status.idle":"2023-02-24T18:52:08.692326Z","shell.execute_reply.started":"2023-02-24T18:52:08.684266Z","shell.execute_reply":"2023-02-24T18:52:08.690599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frames = load_relevant_data_subset('/kaggle/input/asl-signs/train_landmark_files/16069/100015657.parquet')","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:52:11.943560Z","iopub.execute_input":"2023-02-24T18:52:11.944566Z","iopub.status.idle":"2023-02-24T18:52:11.959169Z","shell.execute_reply.started":"2023-02-24T18:52:11.944509Z","shell.execute_reply":"2023-02-24T18:52:11.957987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install tflite-runtime","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:52:12.849092Z","iopub.execute_input":"2023-02-24T18:52:12.850544Z","iopub.status.idle":"2023-02-24T18:52:21.960104Z","shell.execute_reply.started":"2023-02-24T18:52:12.850451Z","shell.execute_reply":"2023-02-24T18:52:21.958447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tflite_runtime.interpreter as tflite\nREQUIRED_SIGNATURE=\"serving_default\"\n\nmodel_path = \"model.tflite\"\ninterpreter = tflite.Interpreter(model_path)\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\")\n\noutput = prediction_fn(inputs=frames)\nsign = np.argmax(output[\"outputs\"])\nprint(sign)","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:52:22.688036Z","iopub.execute_input":"2023-02-24T18:52:22.688458Z","iopub.status.idle":"2023-02-24T18:52:22.699745Z","shell.execute_reply.started":"2023-02-24T18:52:22.688421Z","shell.execute_reply":"2023-02-24T18:52:22.698076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-02-24T18:44:02.377652Z","iopub.execute_input":"2023-02-24T18:44:02.378075Z","iopub.status.idle":"2023-02-24T18:44:02.387406Z","shell.execute_reply.started":"2023-02-24T18:44:02.378028Z","shell.execute_reply":"2023-02-24T18:44:02.385395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}