Last active
November 3, 2025 08:33
-
-
Save MuhammetOzturk/e64170a74adca8196fdc1428e7e99c3b to your computer and use it in GitHub Desktop.
Tensorflowjs-MobileNet.ipynb
This file contains hidden or 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
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [], | |
| "authorship_tag": "ABX9TyM2NBk0yWUr2F3b4482Txk3", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/MuhammetOzturk/e64170a74adca8196fdc1428e7e99c3b/tensorflowjs-mobilenet.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 620 | |
| }, | |
| "id": "Tt9-ZKXZ07gs", | |
| "outputId": "0894fc7e-f1f5-43df-8911-3bbe82beee96" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "display_data", | |
| "data": { | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ], | |
| "text/html": [ | |
| "<html>\n", | |
| " <head>\n", | |
| " <script src=\"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs\"></script> \n", | |
| " <script src=\"https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet\"></script>\n", | |
| " <script src=\"https://code.jquery.com/jquery-3.7.1.min.js\"></script>\n", | |
| " </head>\n", | |
| " <body>\n", | |
| " <input type=\"file\" id=\"imageUpload\" accept=\"image/*\"><br/>\n", | |
| " <img id=\"preview\" style=\"display:none;\"><br/>\n", | |
| " <div id=\"result\"></div>\n", | |
| " </body>\n", | |
| " <script>\n", | |
| " var model;\n", | |
| " $(document).ready(async ()=>{\n", | |
| " await tf.setBackend('cpu');\n", | |
| " $('#result').text(\"Model yukleniyor...\");\n", | |
| " model = await mobilenet.load();\n", | |
| " $('#result').text(\"Model yuklendi.\");\n", | |
| " $(document).on('change', '#imageUpload',async function(e){\n", | |
| " var file = e.target.files[0];\n", | |
| " if(!file){\n", | |
| " return false;\n", | |
| " }\n", | |
| " console.log(\"Dosya yuklendi.\");\n", | |
| " var img = $('#preview');\n", | |
| " img.attr('src', URL.createObjectURL(file));\n", | |
| " img.show();\n", | |
| " img.css({\n", | |
| " width:\"50%\",\n", | |
| " height:\"30%\"\n", | |
| " });\n", | |
| " \n", | |
| " img.on('load', async function(){\n", | |
| " console.log(\"Resim yuklendi....\");\n", | |
| " var result = await model.classify(this);\n", | |
| " console.log(result);\n", | |
| " $('#result').text(\"Tahmin : \" + result[0].className);\n", | |
| " });\n", | |
| " });\n", | |
| " });\n", | |
| " </script>\n", | |
| " </html>\n" | |
| ] | |
| }, | |
| "metadata": {} | |
| } | |
| ], | |
| "source": [ | |
| "%%html\n", | |
| "<html>\n", | |
| " <head>\n", | |
| " <script src=\"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs\"></script>\n", | |
| " <script src=\"https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet\"></script>\n", | |
| " <script src=\"https://code.jquery.com/jquery-3.7.1.min.js\"></script>\n", | |
| " </head>\n", | |
| " <body>\n", | |
| " <input type=\"file\" id=\"imageUpload\" accept=\"image/*\"><br/>\n", | |
| " <img id=\"preview\" style=\"display:none;\"><br/>\n", | |
| " <div id=\"result\"></div>\n", | |
| " </body>\n", | |
| " <script>\n", | |
| " var model;\n", | |
| " $(document).ready(async ()=>{\n", | |
| " await tf.setBackend('cpu');\n", | |
| " $('#result').text(\"Model yukleniyor...\");\n", | |
| " model = await mobilenet.load();\n", | |
| " $('#result').text(\"Model yuklendi.\");\n", | |
| " $(document).on('change', '#imageUpload',async function(e){\n", | |
| " var file = e.target.files[0];\n", | |
| " if(!file){\n", | |
| " return false;\n", | |
| " }\n", | |
| " console.log(\"Dosya yuklendi.\");\n", | |
| " var img = $('#preview');\n", | |
| " img.attr('src', URL.createObjectURL(file));\n", | |
| " img.show();\n", | |
| " img.css({\n", | |
| " width:\"50%\",\n", | |
| " height:\"30%\"\n", | |
| " });\n", | |
| "\n", | |
| " img.on('load', async function(){\n", | |
| " console.log(\"Resim yuklendi....\");\n", | |
| " var result = await model.classify(this);\n", | |
| " console.log(result);\n", | |
| " $('#result').text(\"Tahmin : \" + result[0].className);\n", | |
| " });\n", | |
| " });\n", | |
| " });\n", | |
| " </script>\n", | |
| " </html>" | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment