diff options
Diffstat (limited to 'backend/microservice/cuvanjemodela.ipynb')
-rw-r--r-- | backend/microservice/cuvanjemodela.ipynb | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/backend/microservice/cuvanjemodela.ipynb b/backend/microservice/cuvanjemodela.ipynb new file mode 100644 index 00000000..f24fcc41 --- /dev/null +++ b/backend/microservice/cuvanjemodela.ipynb @@ -0,0 +1,168 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Pre samog čuvanja modela, potrebno je kreirati i obučiti željeni model" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<keras.engine.functional.Functional object at 0x000001B0AA821550>\n" + ] + } + ], + "source": [ + "import tensorflow as tf\n", + "\n", + "\n", + "datainput=tf.keras.Input(shape=(32,))\n", + "dataoutput=tf.keras.layers.Dense(1)(datainput)\n", + "\n", + "model=tf.keras.Model(datainput,dataoutput)\n", + "\n", + "model.compile(optimizer='adam',loss=\"mean_squared_error\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Nakon kreiranja, potrebno je izvršiti trening kreiranog modela" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Za trening će se koristiti nasumicno generisani skup brojeva" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "x=np.random.random((128,32))\n", + "y=np.random.random((128,1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Nakon generisanja, moguće je izvršiti trening " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4/4 [==============================] - 0s 3ms/step - loss: 0.6013\n" + ] + }, + { + "data": { + "text/plain": [ + "<keras.callbacks.History at 0x1b0a99bbf10>" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.fit(x,y)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Kreiranje h5 fajla se izvršava pozivanjem sledeceg koda:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO:tensorflow:Assets written to: primer.onnx\\assets\n" + ] + } + ], + "source": [ + "model.save(\"primer.h5\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Učitavanje postojećeg fajla može se izvršiti pozivanjem sledećeg koda:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "model2=tf.keras.models.load_model('primer.h5')" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "aa60dac3a75d8da79a838f0110309d30613c15866a87f648d4b1206eac7c83af" + }, + "kernelspec": { + "display_name": "Python 3.9.10 64-bit (windows store)", + "language": "python", + "name": "python3" + }, + "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.9.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} |