-
-
Save kiransair/acb664912071933630d87bfaa3ccf159 to your computer and use it in GitHub Desktop.
TF_Forum_17061.ipynb
This file contains 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": "ABX9TyPO5D4+IiGfOfbQiGiAA0Yp", | |
"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/kiransair/acb664912071933630d87bfaa3ccf159/tf_forum_17061.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": "1p9VimQ1ljYw", | |
"outputId": "534f3630-3f85-4deb-dccb-76f7160c2ddd" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Epoch 1/10\n", | |
"1/1 [==============================] - 2s 2s/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 2/10\n", | |
"1/1 [==============================] - 0s 20ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 3/10\n", | |
"1/1 [==============================] - 0s 20ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 4/10\n", | |
"1/1 [==============================] - 0s 23ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 5/10\n", | |
"1/1 [==============================] - 0s 48ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 6/10\n", | |
"1/1 [==============================] - 0s 23ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 7/10\n", | |
"1/1 [==============================] - 0s 24ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 8/10\n", | |
"1/1 [==============================] - 0s 21ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 9/10\n", | |
"1/1 [==============================] - 0s 24ms/step - loss: 0.6931 - accuracy: 0.5000\n", | |
"Epoch 10/10\n", | |
"1/1 [==============================] - 0s 21ms/step - loss: 0.6931 - accuracy: 0.5000\n" | |
] | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"<keras.callbacks.History at 0x7f75b1cd6950>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 1 | |
} | |
], | |
"source": [ | |
"import numpy as np\n", | |
"import tensorflow as tf\n", | |
"\n", | |
"# Create the model\n", | |
"model = tf.keras.Sequential([\n", | |
" tf.keras.layers.Dense(3, activation='relu', input_shape=(None, 9)), # Adjusted input shape\n", | |
" tf.keras.layers.Dense(2, activation='softmax')\n", | |
"])\n", | |
"\n", | |
"# Compile the model\n", | |
"model.compile(optimizer='adam',\n", | |
" loss='sparse_categorical_crossentropy',\n", | |
" metrics=['accuracy'])\n", | |
"\n", | |
"# Train the model\n", | |
"data = np.array([[[2, 3, 5], [6, 8, 9], [10, 11, 12]], [[2, 1, 3], [3, 5, 6], [4, 5, 2]]])\n", | |
"labels = np.array([0, 1]) # One label for each group of arrays\n", | |
"\n", | |
"# Reshape the data to combine all groups into one sample\n", | |
"data = np.reshape(data, (2, -1))\n", | |
"\n", | |
"model.fit(data, labels, epochs=10)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"to_predict = np.array([[2,14,3],[3,56,6]])\n", | |
"x=np.pad(to_predict,((0, 0), (0, 6)), 'constant', constant_values=0)\n", | |
"predictions = model.predict(x)\n", | |
"print(predictions)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "wCoS1t0JlrTh", | |
"outputId": "0fdb666b-8b18-41d8-9288-661819decfdf" | |
}, | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"1/1 [==============================] - 0s 404ms/step\n", | |
"[[0.5 0.5 ]\n", | |
" [0.49962947 0.50037056]]\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [], | |
"metadata": { | |
"id": "bicOUQ9eltrd" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment