{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "g9qov3ORzJow" }, "source": [ "# TensorBird execute saved model\n", "\n", "The model has been train in [this notebook](https://colab.research.google.com/drive/1ZVIR-rOjYBwsmaxewlTT9alLnwLdFfy9#scrollTo=s4dIb12FKR4i)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 467, "status": "ok", "timestamp": 1615375390011, "user": { "displayName": "Samuel ORTION", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjRGue2iC2EdXEyjeJY4NsXRcpEkauti9jPXOLyzQ=s64", "userId": "18350365121775402037" }, "user_tz": -60 }, "id": "ZdLxvb7VzFgK", "outputId": "685add3b-7b1e-4415-ccfb-ec2f146911ca" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.4.1\n" ] } ], "source": [ "import os\n", "import pickle\n", "import glob\n", "from PIL import Image\n", "import numpy as np\n", "\n", "import tensorflow as tf\n", "\n", "print(tf.version.VERSION)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "executionInfo": { "elapsed": 29824, "status": "ok", "timestamp": 1615374397372, "user": { "displayName": "Samuel ORTION", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjRGue2iC2EdXEyjeJY4NsXRcpEkauti9jPXOLyzQ=s64", "userId": "18350365121775402037" }, "user_tz": -60 }, "id": "eiTEfd_zzcI_" }, "outputs": [], "source": [ "model = tf.keras.models.load_model('../models/saved_model.pbtxt')" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "executionInfo": { "elapsed": 700, "status": "ok", "timestamp": 1615374976499, "user": { "displayName": "Samuel ORTION", "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GjRGue2iC2EdXEyjeJY4NsXRcpEkauti9jPXOLyzQ=s64", "userId": "18350365121775402037" }, "user_tz": -60 }, "id": "K6EKAevy2ZAp" }, "outputs": [ { "data": { "text/plain": [ "array(['fricoe', 'prumod', 'pasdom', 'felcat', 'erirub', 'caycae',\n", " 'parmaj'], dtype='" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "import random\n", "image_paths = glob.glob('/home/ortion/Documents/PiCameraTrap/captures/raw/2021-03-03/*.jpg')\n", "fig = plt.figure(figsize=(10, 10))\n", "rows = 3\n", "cols = 3\n", "axes=[]\n", "for a in range(rows*cols):\n", " im = Image.open(random.choice(image_paths))\n", " im = im.resize((100, 75))\n", " im = np.array(im)\n", " im = im / 255\n", " predictions = model.predict(im[None, :, :])\n", " idx = np.argmax(predictions)\n", " prediction = CLASS_NAMES[idx]\n", " axes.append(fig.add_subplot(rows, cols, a+1))\n", " axes[-1].set_title(prediction)\n", " axes[-1].imshow(im)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "authorship_tag": "ABX9TyM/DfSJLUs+DeUzpchkAict", "name": "TensorBird_execute_saved_model.ipynb", "provenance": [] }, "kernelspec": { "display_name": "tb-venv", "language": "python", "name": "tb-venv" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 1 }