Last active
April 23, 2023 23:36
-
-
Save tuna2134/026e959e395ff686af66d974149ea9f7 to your computer and use it in GitHub Desktop.
ume-or-sakura.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": [], | |
"mount_file_id": "1nacSmSSnoG7X4SEuKJF80npkJHp4rEQO", | |
"authorship_tag": "ABX9TyOHtlLTFLU7sNLIivYnplcU", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"accelerator": "GPU", | |
"gpuClass": "standard" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/tuna2134/026e959e395ff686af66d974149ea9f7/untitled2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "p8OqHCHKPZ2h", | |
"outputId": "8b13d701-c5cb-4d28-c880-49e6b2ce6c9c" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
"Collecting icrawler\n", | |
" Downloading icrawler-0.6.6-py2.py3-none-any.whl (35 kB)\n", | |
"Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.9/dist-packages (from icrawler) (1.16.0)\n", | |
"Requirement already satisfied: Pillow in /usr/local/lib/python3.9/dist-packages (from icrawler) (8.4.0)\n", | |
"Requirement already satisfied: beautifulsoup4>=4.4.1 in /usr/local/lib/python3.9/dist-packages (from icrawler) (4.11.2)\n", | |
"Requirement already satisfied: lxml in /usr/local/lib/python3.9/dist-packages (from icrawler) (4.9.2)\n", | |
"Requirement already satisfied: requests>=2.9.1 in /usr/local/lib/python3.9/dist-packages (from icrawler) (2.27.1)\n", | |
"Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.9/dist-packages (from beautifulsoup4>=4.4.1->icrawler) (2.4.1)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests>=2.9.1->icrawler) (2022.12.7)\n", | |
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests>=2.9.1->icrawler) (3.4)\n", | |
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests>=2.9.1->icrawler) (1.26.15)\n", | |
"Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests>=2.9.1->icrawler) (2.0.12)\n", | |
"Installing collected packages: icrawler\n", | |
"Successfully installed icrawler-0.6.6\n" | |
] | |
} | |
], | |
"source": [ | |
"!pip install icrawler" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from icrawler.builtin import GoogleImageCrawler\n", | |
"\n", | |
"google_crawler = GoogleImageCrawler(\n", | |
" feeder_threads=1,\n", | |
" parser_threads=1,\n", | |
" downloader_threads=4,\n", | |
" storage={'root_dir': 'images/ume'})\n", | |
"google_crawler.crawl(keyword='梅の花', max_num=1000)" | |
], | |
"metadata": { | |
"id": "8lqvrjU5Pee-" | |
}, | |
"execution_count": 37, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"google_crawler = GoogleImageCrawler(\n", | |
" feeder_threads=1,\n", | |
" parser_threads=1,\n", | |
" downloader_threads=4,\n", | |
" storage={'root_dir': 'images/sakura'}\n", | |
")\n", | |
"google_crawler.crawl(keyword='桜の花', max_num=1000)" | |
], | |
"metadata": { | |
"id": "jvyGuE7RQOQr" | |
}, | |
"execution_count": 38, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from glob import glob\n", | |
"from PIL import Image" | |
], | |
"metadata": { | |
"id": "l7ewMATnRJ_y" | |
}, | |
"execution_count": 39, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"for name in glob(\"images/**/*.jpg\"):\n", | |
" img = Image.open(name)\n", | |
" img = img.resize((224, 224))\n", | |
" img.save(name)" | |
], | |
"metadata": { | |
"id": "PQKtCzzORWTV" | |
}, | |
"execution_count": 40, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"from tensorflow import keras\n", | |
"import tensorflow_hub as hub" | |
], | |
"metadata": { | |
"id": "_PgiNqobTQ-c" | |
}, | |
"execution_count": 41, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model = keras.Sequential([\n", | |
" hub.KerasLayer(\n", | |
" \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_b0/feature_vector/2\",\n", | |
" trainable=False\n", | |
" ),\n", | |
" keras.layers.Dense(1, activation='sigmoid')\n", | |
"])\n", | |
"model.build([None, 224, 224, 3])" | |
], | |
"metadata": { | |
"id": "t76W5RtSTq09" | |
}, | |
"execution_count": 42, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.compile(\n", | |
" optimizer=keras.optimizers.Adam(),\n", | |
" loss=\"binary_crossentropy\",\n", | |
" metrics=[\"accuracy\"],\n", | |
")" | |
], | |
"metadata": { | |
"id": "sfxGRdZxU_E9" | |
}, | |
"execution_count": 43, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"train_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=(1.0 / 255))\n", | |
"train_generator = train_datagen.flow_from_directory(\n", | |
" \"./images\",\n", | |
" target_size=(224, 224),\n", | |
" batch_size=20,\n", | |
" class_mode=\"binary\",\n", | |
")" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "EykP4ScSUfho", | |
"outputId": "0214ce19-8f6f-4d48-d3c8-4e3fa56d55db" | |
}, | |
"execution_count": 44, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Found 204 images belonging to 2 classes.\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.fit(train_generator, epochs=60)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "e5pOSsOdU0r9", | |
"outputId": "2a4f95c3-06ff-429b-dce8-b7b3676161e0" | |
}, | |
"execution_count": 45, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Epoch 1/60\n", | |
"11/11 [==============================] - 10s 124ms/step - loss: 0.6758 - accuracy: 0.5490\n", | |
"Epoch 2/60\n", | |
"11/11 [==============================] - 1s 62ms/step - loss: 0.5909 - accuracy: 0.6814\n", | |
"Epoch 3/60\n", | |
"11/11 [==============================] - 1s 56ms/step - loss: 0.5302 - accuracy: 0.7745\n", | |
"Epoch 4/60\n", | |
"11/11 [==============================] - 1s 75ms/step - loss: 0.4877 - accuracy: 0.7843\n", | |
"Epoch 5/60\n", | |
"11/11 [==============================] - 1s 66ms/step - loss: 0.4596 - accuracy: 0.7990\n", | |
"Epoch 6/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.4343 - accuracy: 0.8284\n", | |
"Epoch 7/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.4104 - accuracy: 0.8137\n", | |
"Epoch 8/60\n", | |
"11/11 [==============================] - 1s 71ms/step - loss: 0.3913 - accuracy: 0.8284\n", | |
"Epoch 9/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.3787 - accuracy: 0.8578\n", | |
"Epoch 10/60\n", | |
"11/11 [==============================] - 1s 61ms/step - loss: 0.3565 - accuracy: 0.8578\n", | |
"Epoch 11/60\n", | |
"11/11 [==============================] - 1s 87ms/step - loss: 0.3444 - accuracy: 0.8431\n", | |
"Epoch 12/60\n", | |
"11/11 [==============================] - 1s 107ms/step - loss: 0.3304 - accuracy: 0.8725\n", | |
"Epoch 13/60\n", | |
"11/11 [==============================] - 1s 89ms/step - loss: 0.3163 - accuracy: 0.8873\n", | |
"Epoch 14/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.3044 - accuracy: 0.9020\n", | |
"Epoch 15/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.2941 - accuracy: 0.9020\n", | |
"Epoch 16/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.2822 - accuracy: 0.9020\n", | |
"Epoch 17/60\n", | |
"11/11 [==============================] - 1s 69ms/step - loss: 0.2733 - accuracy: 0.9216\n", | |
"Epoch 18/60\n", | |
"11/11 [==============================] - 1s 62ms/step - loss: 0.2668 - accuracy: 0.9265\n", | |
"Epoch 19/60\n", | |
"11/11 [==============================] - 1s 71ms/step - loss: 0.2570 - accuracy: 0.9265\n", | |
"Epoch 20/60\n", | |
"11/11 [==============================] - 1s 69ms/step - loss: 0.2464 - accuracy: 0.9314\n", | |
"Epoch 21/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.2401 - accuracy: 0.9363\n", | |
"Epoch 22/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.2352 - accuracy: 0.9412\n", | |
"Epoch 23/60\n", | |
"11/11 [==============================] - 1s 72ms/step - loss: 0.2279 - accuracy: 0.9412\n", | |
"Epoch 24/60\n", | |
"11/11 [==============================] - 1s 76ms/step - loss: 0.2238 - accuracy: 0.9412\n", | |
"Epoch 25/60\n", | |
"11/11 [==============================] - 1s 102ms/step - loss: 0.2174 - accuracy: 0.9363\n", | |
"Epoch 26/60\n", | |
"11/11 [==============================] - 1s 105ms/step - loss: 0.2082 - accuracy: 0.9461\n", | |
"Epoch 27/60\n", | |
"11/11 [==============================] - 1s 69ms/step - loss: 0.2047 - accuracy: 0.9461\n", | |
"Epoch 28/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.1985 - accuracy: 0.9657\n", | |
"Epoch 29/60\n", | |
"11/11 [==============================] - 1s 72ms/step - loss: 0.1934 - accuracy: 0.9657\n", | |
"Epoch 30/60\n", | |
"11/11 [==============================] - 1s 71ms/step - loss: 0.1898 - accuracy: 0.9657\n", | |
"Epoch 31/60\n", | |
"11/11 [==============================] - 1s 73ms/step - loss: 0.1839 - accuracy: 0.9657\n", | |
"Epoch 32/60\n", | |
"11/11 [==============================] - 1s 65ms/step - loss: 0.1796 - accuracy: 0.9657\n", | |
"Epoch 33/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.1763 - accuracy: 0.9657\n", | |
"Epoch 34/60\n", | |
"11/11 [==============================] - 1s 73ms/step - loss: 0.1734 - accuracy: 0.9706\n", | |
"Epoch 35/60\n", | |
"11/11 [==============================] - 1s 76ms/step - loss: 0.1684 - accuracy: 0.9755\n", | |
"Epoch 36/60\n", | |
"11/11 [==============================] - 1s 72ms/step - loss: 0.1656 - accuracy: 0.9804\n", | |
"Epoch 37/60\n", | |
"11/11 [==============================] - 1s 71ms/step - loss: 0.1620 - accuracy: 0.9804\n", | |
"Epoch 38/60\n", | |
"11/11 [==============================] - 1s 106ms/step - loss: 0.1588 - accuracy: 0.9755\n", | |
"Epoch 39/60\n", | |
"11/11 [==============================] - 1s 78ms/step - loss: 0.1531 - accuracy: 0.9804\n", | |
"Epoch 40/60\n", | |
"11/11 [==============================] - 1s 66ms/step - loss: 0.1509 - accuracy: 0.9804\n", | |
"Epoch 41/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1469 - accuracy: 0.9853\n", | |
"Epoch 42/60\n", | |
"11/11 [==============================] - 1s 69ms/step - loss: 0.1446 - accuracy: 0.9853\n", | |
"Epoch 43/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1424 - accuracy: 0.9853\n", | |
"Epoch 44/60\n", | |
"11/11 [==============================] - 1s 65ms/step - loss: 0.1391 - accuracy: 0.9853\n", | |
"Epoch 45/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1355 - accuracy: 0.9902\n", | |
"Epoch 46/60\n", | |
"11/11 [==============================] - 1s 66ms/step - loss: 0.1334 - accuracy: 0.9902\n", | |
"Epoch 47/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1309 - accuracy: 0.9902\n", | |
"Epoch 48/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.1284 - accuracy: 0.9902\n", | |
"Epoch 49/60\n", | |
"11/11 [==============================] - 1s 102ms/step - loss: 0.1264 - accuracy: 0.9902\n", | |
"Epoch 50/60\n", | |
"11/11 [==============================] - 1s 106ms/step - loss: 0.1236 - accuracy: 0.9902\n", | |
"Epoch 51/60\n", | |
"11/11 [==============================] - 1s 64ms/step - loss: 0.1217 - accuracy: 0.9902\n", | |
"Epoch 52/60\n", | |
"11/11 [==============================] - 1s 72ms/step - loss: 0.1198 - accuracy: 0.9902\n", | |
"Epoch 53/60\n", | |
"11/11 [==============================] - 1s 62ms/step - loss: 0.1175 - accuracy: 0.9902\n", | |
"Epoch 54/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1159 - accuracy: 0.9902\n", | |
"Epoch 55/60\n", | |
"11/11 [==============================] - 1s 72ms/step - loss: 0.1134 - accuracy: 0.9902\n", | |
"Epoch 56/60\n", | |
"11/11 [==============================] - 1s 68ms/step - loss: 0.1119 - accuracy: 0.9902\n", | |
"Epoch 57/60\n", | |
"11/11 [==============================] - 1s 65ms/step - loss: 0.1096 - accuracy: 0.9902\n", | |
"Epoch 58/60\n", | |
"11/11 [==============================] - 1s 70ms/step - loss: 0.1079 - accuracy: 0.9902\n", | |
"Epoch 59/60\n", | |
"11/11 [==============================] - 1s 71ms/step - loss: 0.1061 - accuracy: 0.9902\n", | |
"Epoch 60/60\n", | |
"11/11 [==============================] - 1s 74ms/step - loss: 0.1041 - accuracy: 0.9902\n" | |
] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<keras.callbacks.History at 0x7f7a0c0c1dc0>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 45 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.evaluate(train_generator)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "y9SqHWV1Yk6-", | |
"outputId": "2cc8b1ae-3c3a-4159-d62c-26caf60130ca" | |
}, | |
"execution_count": 48, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
" 2/11 [====>.........................] - ETA: 0s - loss: 0.1082 - accuracy: 0.9750 " | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"name": "stderr", | |
"text": [ | |
"/usr/local/lib/python3.9/dist-packages/PIL/Image.py:975: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images\n", | |
" warnings.warn(\n" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"11/11 [==============================] - 2s 100ms/step - loss: 0.1025 - accuracy: 0.9902\n" | |
] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"[0.102511465549469, 0.9901960492134094]" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 48 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import numpy as np\n", | |
"\n", | |
"image = Image.open(\"./images/ume/000001.jpg\").convert(\"RGB\").resize((224, 224))\n", | |
"image = np.array(image) / 255\n", | |
"image = np.expand_dims(image, 0)\n", | |
"predictions = model.predict(image)\n", | |
"print(predictions)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "XTSgWx4wWK-_", | |
"outputId": "de0dd6a1-fa72-4df8-9e5f-04edaca8fadf" | |
}, | |
"execution_count": 49, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"1/1 [==============================] - 0s 26ms/step\n", | |
"[[0.87228066]]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"model.save(\"./model\")" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "dgP_yp3AYgw3", | |
"outputId": "f9c626b1-9ecd-440e-ee65-e3e21f5dd18d" | |
}, | |
"execution_count": 51, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stderr", | |
"text": [ | |
"WARNING:absl:Found untraced functions such as restored_function_body, restored_function_body, restored_function_body, restored_function_body, restored_function_body while saving (showing 5 of 334). These functions will not be directly callable after loading.\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install tf2onnx\n", | |
"!python -m tf2onnx.convert --saved-model model --output model.onnx" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 857 | |
}, | |
"id": "6yG0AR4RYzNq", | |
"outputId": "94286d80-97f2-4442-aad9-7f2f0fc7df18" | |
}, | |
"execution_count": 53, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", | |
"Collecting tf2onnx\n", | |
" Downloading tf2onnx-1.14.0-py3-none-any.whl (451 kB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m451.2/451.2 kB\u001b[0m \u001b[31m11.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hCollecting flatbuffers<3.0,>=1.12\n", | |
" Downloading flatbuffers-2.0.7-py2.py3-none-any.whl (26 kB)\n", | |
"Collecting onnx>=1.4.1\n", | |
" Downloading onnx-1.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.5 MB)\n", | |
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.5/13.5 MB\u001b[0m \u001b[31m98.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | |
"\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from tf2onnx) (2.27.1)\n", | |
"Requirement already satisfied: six in /usr/local/lib/python3.9/dist-packages (from tf2onnx) (1.16.0)\n", | |
"Requirement already satisfied: numpy>=1.14.1 in /usr/local/lib/python3.9/dist-packages (from tf2onnx) (1.22.4)\n", | |
"Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.9/dist-packages (from onnx>=1.4.1->tf2onnx) (4.5.0)\n", | |
"Requirement already satisfied: protobuf<4,>=3.20.2 in /usr/local/lib/python3.9/dist-packages (from onnx>=1.4.1->tf2onnx) (3.20.3)\n", | |
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->tf2onnx) (1.26.15)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->tf2onnx) (2022.12.7)\n", | |
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->tf2onnx) (3.4)\n", | |
"Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests->tf2onnx) (2.0.12)\n", | |
"Installing collected packages: flatbuffers, onnx, tf2onnx\n", | |
" Attempting uninstall: flatbuffers\n", | |
" Found existing installation: flatbuffers 23.3.3\n", | |
" Uninstalling flatbuffers-23.3.3:\n", | |
" Successfully uninstalled flatbuffers-23.3.3\n", | |
"Successfully installed flatbuffers-2.0.7 onnx-1.13.1 tf2onnx-1.14.0\n" | |
] | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.colab-display-data+json": { | |
"pip_warning": { | |
"packages": [ | |
"flatbuffers" | |
] | |
} | |
} | |
}, | |
"metadata": {} | |
}, | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"2023-04-23 13:53:21.767874: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n", | |
"/usr/lib/python3.9/runpy.py:127: RuntimeWarning: 'tf2onnx.convert' found in sys.modules after import of package 'tf2onnx', but prior to execution of 'tf2onnx.convert'; this may result in unpredictable behaviour\n", | |
" warn(RuntimeWarning(msg))\n", | |
"2023-04-23 13:53:24.345123: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:47] Overriding orig_value setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n", | |
"2023-04-23 13:53:24,346 - WARNING - '--tag' not specified for saved_model. Using --tag serve\n", | |
"2023-04-23 13:53:31,810 - INFO - Signatures found in model: [serving_default].\n", | |
"2023-04-23 13:53:31,811 - WARNING - '--signature_def' not specified, using first signature: serving_default\n", | |
"2023-04-23 13:53:31,812 - INFO - Output names: ['dense_3']\n", | |
"2023-04-23 13:53:35,713 - INFO - Using tensorflow=2.12.0, onnx=1.13.1, tf2onnx=1.14.0/8f8d49\n", | |
"2023-04-23 13:53:35,713 - INFO - Using opset <onnx, 15>\n", | |
"2023-04-23 13:53:35,971 - INFO - Computed 0 values for constant folding\n", | |
"2023-04-23 13:53:36,579 - INFO - Optimizing ONNX model\n", | |
"2023-04-23 13:53:39,241 - INFO - After optimization: BatchNormalization -54 (59->5), Const -194 (394->200), GlobalAveragePool +17 (0->17), Identity -2 (2->0), ReduceMean -17 (17->0), Reshape -16 (16->0), Squeeze +1 (0->1), Transpose -315 (316->1)\n", | |
"2023-04-23 13:53:39,282 - INFO - \n", | |
"2023-04-23 13:53:39,282 - INFO - Successfully converted TensorFlow model model to ONNX\n", | |
"2023-04-23 13:53:39,282 - INFO - Model inputs: ['keras_layer_3_input']\n", | |
"2023-04-23 13:53:39,283 - INFO - Model outputs: ['dense_3']\n", | |
"2023-04-23 13:53:39,283 - INFO - ONNX model is saved at model.onnx\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!cp model.onnx drive/MyDrive/models" | |
], | |
"metadata": { | |
"id": "5pGGr7o4ZLSH" | |
}, | |
"execution_count": 54, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment