canvas-recognition/Segment/final-Copy1.ipynb

1495 lines
91 KiB
Text
Raw Permalink Normal View History

2021-03-29 23:26:06 -07:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"import pandas as pd \n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import os\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"import tensorflow as tf\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense\n",
"from keras.layers import Dropout\n",
"from keras.layers import Flatten\n",
"from keras.layers.convolutional import Conv2D\n",
"from keras.layers.convolutional import MaxPooling2D\n",
"from keras import backend as K\n",
"from keras.utils import np_utils\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import confusion_matrix\n",
"\n",
"#ignore warning messages \n",
"import warnings\n",
"warnings.filterwarnings('ignore') \n",
"\n",
"sns.set()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"dataset = pd.read_csv(\"A_Z Handwritten Data.csv\").astype('float32')\n",
"dataset.rename(columns={'0':'label'}, inplace=True)\n",
"\n",
"# Splite data the X - Our data , and y - the prdict label\n",
"X = dataset.drop('label',axis = 1)\n",
"y = dataset['label']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Amount of each labels\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAmcAAAJBCAYAAAADRxI6AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAyR0lEQVR4nO3de3xU5Z3H8e8MAUUyKMSJWANWA0WEVu2iCcLqAm4ghDiIvrYgq22NIq0VS/GCGm3VVK6RqiirldX1VpWCxHjBdOWFCiqKFxBExVsxask4BnMhGTKZs3/4MivVYEJ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jqNAIGBieQAppC07X9kdaxZ5m0Xe5riVtZFy1rt3b9XW7r2HKhaL6eCDDzaxPIAUEo3ue79mOBz63u9B5yFvs8jbnNayDgYDHX78l5HLmunp6TryyCP19NNPt7z28MMPa8SIESaWBwAA8A1j95wtXLhQDz74oE4//XTl5+dr+/btuvbaa00tDwAA4AvGHkJ71FFH6X/+539MLQcAAOBLvjkhYFlxntcjALBcYzzh9QgA0GG+KWexWJ2SScfrMVICN5SaRd4AgG/iOWcAAAAWoZwBAABYhHIGAABgEcoZAACARShnAAAAFqGcAQAAWIRyBgAAYBHKGQAAgEV88xDajp7wjvYJh0Nej5BS3Mq7MZ5QbU2DK+8NAHCHb8pZUUmFqqr5RwZoj/LSiDh7AAD8xUg5u+666/Taa6+pqalJO3bsUHZ2tiTp3HPP1ZlnnmliBAAAAF8wUs5+//v
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"print(\"Amount of each labels\")\n",
"\n",
"# Change label to alphabets\n",
"alphabets_mapper = {0:'A',1:'B',2:'C',3:'D',4:'E',5:'F',6:'G',7:'H',8:'I',9:'J',10:'K',11:'L',12:'M',13:'N',14:'O',15:'P',16:'Q',17:'R',18:'S',19:'T',20:'U',21:'V',22:'W',23:'X',24:'Y',25:'Z'} \n",
"dataset_alphabets = dataset.copy()\n",
"dataset['label'] = dataset['label'].map(alphabets_mapper)\n",
"\n",
"label_size = dataset.groupby('label').size()\n",
"label_size.plot.barh(figsize=(10,10))\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# splite the data\n",
"X_train, X_test, y_train, y_test = train_test_split(X,y)\n",
"\n",
"# scale data\n",
"standard_scaler = MinMaxScaler()\n",
"standard_scaler.fit(X_train)\n",
"\n",
"X_train = standard_scaler.transform(X_train)\n",
"X_test = standard_scaler.transform(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"X_train = X_train.reshape(X_train.shape[0], 28, 28, 1).astype('float32')\n",
"X_test = X_test.reshape(X_test.shape[0], 28, 28, 1).astype('float32')\n",
"\n",
"y_train = np_utils.to_categorical(y_train)\n",
"y_test = np_utils.to_categorical(y_test)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/20\n",
"1092/1092 [==============================] - 156s 141ms/step - loss: 0.5139 - accuracy: 0.8566 - val_loss: 0.0949 - val_accuracy: 0.9747\n",
"Epoch 2/20\n",
"1092/1092 [==============================] - 137s 125ms/step - loss: 0.0984 - accuracy: 0.9732 - val_loss: 0.0700 - val_accuracy: 0.9804\n",
"Epoch 3/20\n",
"1092/1092 [==============================] - 129s 118ms/step - loss: 0.0716 - accuracy: 0.9797 - val_loss: 0.0579 - val_accuracy: 0.9837\n",
"Epoch 4/20\n",
"1092/1092 [==============================] - 129s 118ms/step - loss: 0.0559 - accuracy: 0.9842 - val_loss: 0.0496 - val_accuracy: 0.9861\n",
"Epoch 5/20\n",
"1092/1092 [==============================] - 160s 146ms/step - loss: 0.0469 - accuracy: 0.9862 - val_loss: 0.0476 - val_accuracy: 0.9867\n",
"Epoch 6/20\n",
"1092/1092 [==============================] - 144s 132ms/step - loss: 0.0406 - accuracy: 0.9881 - val_loss: 0.0456 - val_accuracy: 0.9866\n",
"Epoch 7/20\n",
"1092/1092 [==============================] - 177s 162ms/step - loss: 0.0339 - accuracy: 0.9896 - val_loss: 0.0390 - val_accuracy: 0.9891\n",
"Epoch 8/20\n",
"1092/1092 [==============================] - 131s 120ms/step - loss: 0.0294 - accuracy: 0.9910 - val_loss: 0.0363 - val_accuracy: 0.9896\n",
"Epoch 9/20\n",
"1092/1092 [==============================] - 116s 106ms/step - loss: 0.0262 - accuracy: 0.9920 - val_loss: 0.0358 - val_accuracy: 0.9901\n",
"Epoch 10/20\n",
"1092/1092 [==============================] - 131s 120ms/step - loss: 0.0227 - accuracy: 0.9928 - val_loss: 0.0357 - val_accuracy: 0.9897\n",
"Epoch 11/20\n",
"1092/1092 [==============================] - 111s 102ms/step - loss: 0.0199 - accuracy: 0.9936 - val_loss: 0.0325 - val_accuracy: 0.9911\n",
"Epoch 12/20\n",
"1092/1092 [==============================] - 113s 103ms/step - loss: 0.0176 - accuracy: 0.9940 - val_loss: 0.0324 - val_accuracy: 0.9912\n",
"Epoch 13/20\n",
"1092/1092 [==============================] - 113s 103ms/step - loss: 0.0165 - accuracy: 0.9943 - val_loss: 0.0300 - val_accuracy: 0.9925\n",
"Epoch 14/20\n",
"1092/1092 [==============================] - 113s 103ms/step - loss: 0.0156 - accuracy: 0.9946 - val_loss: 0.0313 - val_accuracy: 0.9923\n",
"Epoch 15/20\n",
"1092/1092 [==============================] - 113s 104ms/step - loss: 0.0138 - accuracy: 0.9954 - val_loss: 0.0284 - val_accuracy: 0.9932\n",
"Epoch 16/20\n",
"1092/1092 [==============================] - 112s 102ms/step - loss: 0.0129 - accuracy: 0.9956 - val_loss: 0.0279 - val_accuracy: 0.9936\n",
"Epoch 17/20\n",
"1092/1092 [==============================] - 112s 102ms/step - loss: 0.0122 - accuracy: 0.9957 - val_loss: 0.0305 - val_accuracy: 0.9932\n",
"Epoch 18/20\n",
"1092/1092 [==============================] - 112s 103ms/step - loss: 0.0115 - accuracy: 0.9961 - val_loss: 0.0292 - val_accuracy: 0.9932\n",
"Epoch 19/20\n",
"1092/1092 [==============================] - 115s 105ms/step - loss: 0.0114 - accuracy: 0.9960 - val_loss: 0.0294 - val_accuracy: 0.9937\n",
"Epoch 20/20\n",
"1092/1092 [==============================] - 116s 106ms/step - loss: 0.0111 - accuracy: 0.9961 - val_loss: 0.0275 - val_accuracy: 0.9943\n"
]
}
],
"source": [
"cls = Sequential()\n",
"cls.add(Conv2D(32, (5, 5), input_shape=(28, 28, 1), activation='relu'))\n",
"cls.add(MaxPooling2D(pool_size=(2, 2)))\n",
"cls.add(Dropout(0.3))\n",
"cls.add(Flatten())\n",
"cls.add(Dense(128, activation='relu'))\n",
"cls.add(Dense(len(y.unique()), activation='softmax'))\n",
"\n",
"cls.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n",
"history = cls.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=20, batch_size=256)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"cls.save('my_model.h5')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import PIL\n",
"from PIL import Image, ImageEnhance, ImageDraw, ImageFont\n",
"from IPython.display import display\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"img = Image.open('n_image copy.jpg')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAAoCAAAAABVgMx7AAACTElEQVR4nHWTy3LjNhBFDx96kLQzcpJJVaqySOX/v2syZc/IkvkmCJwsHEn2QnfXwMHtbqCBFyWTZ+dLOJmis5OZvGuhzEl5LLjp+Q8Ab1rCzcL0Lar25hf+dSaVeD2f/bnS8qMmu60x7vJbcN7t51QRNre16Vjlcxov4Zf9ajWRbnXA3/+uH4ryxcDDSa9EBUaXKzD7yhMussTJ4GqE2sV4RcJwAN/EYK/ftYHWcE3Ua8HhPUswaqCqqcfuahH1/bbKZCxDqmKR97gnXZrLQ/eQDVnX4Ggb1YLfMnC4eJw14wvKNJtcpgZWD9Uti/bTlvIkeu57IxUmnrh6jIPtL1uUtde1q/LCpB8fMq1SsZgXM7TNPkWyOHPIFhg4h+X/l0ow6aDUjydVfi06Q7BzNn77B5TO1pW/0DaufgX1fHSJDtKg2BuEPI7q8/yYsai2g06QKyE69tsMXV6S7YbN9mgY9Pgi7GbRk7tmY3dOLroUbDTOaU66NgT5oSkjC446dioPpEH159STKXo220ftPOuslOjkq6uym2SOlp8mPlGjxhS0RvPtshZU6TqucXV4zFbyrkxpepzAIL837W38wvtcRF+nHIyMAvZXoHNeGtBO+coiuikPwwdEF6lIYyc5is8ULL5dtk+r0Td2aKzBiMtTju0Hi9agbCFR00tM3cOk0+2fOHjszdjUsPfTv/2kdVOu9YDkdwBy12KA+T4x87JK2FHeIwoOfZKU362Dti5iirvsbhaKoi82ZPfrGOrvTdfvw/1uOR0wIxb/AetB2NNoPMSRAAAAAElFTkSuQmCC\n",
"text/plain": [
"<PIL.JpegImagePlugin.JpegImageFile image mode=L size=33x40 at 0x7FBE6FF1B490>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"img"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import cv2"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"my_lol_img = cv2.imread('n_image copy.jpg', cv2.IMREAD_GRAYSCALE)\n",
"my_lol_img = cv2.resize(my_lol_img, (28, 28))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7fbc020b4730>"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAATMAAAExCAYAAAAQkEVVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaSElEQVR4nO3df0zU9x3H8Te/DgW0hgR0zRhbbVebTand0qFrIdp42sKVspkWtDhLN8lmyXR2RogdybISRrC2Rto0qaZzmlbbTTuIgiRbbRWSTTNx+gdjqWgNTunsUBCPA777oxnp3X3P7xs4PPjwfPzV78cPn/vcfe5e/d59P5/PN8qyLEsAYJKLjnQHACAcCDMARiDMABiBMANgBMIMgBEIMwBGIMwAG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UlRdWWdm2r5p4C2hUMoeoFlnd3d6va02w28MYbb6jauueee1T1fvazn/kd282e187sD3zvhaJ9H2nYzdi3ew7aXUQ0KwC0KxjuuusuVb0bN26o+mG3k0Yg7gEAAEKYATAEYQbACIQZACMQZgCMQJgBMAJhBsAIhBkAI0Rs0qzdJLrACZuaiYyayXgi+gl52tvD2U1gDSxLS0tTtVVSUqKqp9nhfKwTDwNpJ5Pu3LnTsU7gJNdQtm3bpqq3ePFiv+OHHnpITp8+HVSmoZ1srKWZwGo34Ts2NjaoXDtpVlNP+zyvX7+uqhfu99tYcGYGwAiEGQAjEGYAjECYATACYQbACIQZACMQZgCMQJgBMAJhBsAIEVsBoKGZrTw4OKhq61//+peqnnb
"text/plain": [
"<Figure size 360x360 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize = (5,5))\n",
"plt.imshow(my_lol_img, cmap='gray')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[255, 255, 255, 255, 255, 255, 255, 253, 254, 254, 255, 244, 254,\n",
" 252, 255, 255, 255, 255, 255, 255, 251, 254, 254, 253, 250, 253,\n",
" 251, 254],\n",
" [255, 255, 255, 255, 255, 255, 254, 253, 253, 252, 252, 254, 252,\n",
" 254, 255, 255, 255, 255, 255, 255, 255, 241, 254, 253, 250, 255,\n",
" 250, 254],\n",
" [255, 255, 255, 255, 255, 255, 252, 242, 252, 250, 254, 254, 250,\n",
" 255, 255, 255, 255, 255, 255, 255, 254, 254, 249, 252, 247, 245,\n",
" 250, 255],\n",
" [255, 255, 255, 255, 255, 255, 255, 254, 248, 249, 254, 252, 253,\n",
" 252, 255, 255, 255, 255, 255, 255, 250, 250, 253, 248, 251, 253,\n",
" 250, 254],\n",
" [255, 255, 255, 255, 255, 255, 217, 18, 32, 176, 250, 254, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 255, 239, 254, 205, 22, 146,\n",
" 251, 255],\n",
" [253, 254, 253, 254, 254, 254, 229, 63, 0, 116, 243, 253, 252,\n",
" 254, 255, 255, 255, 255, 255, 255, 252, 253, 237, 7, 7, 141,\n",
" 249, 254],\n",
" [254, 252, 251, 251, 255, 237, 255, 171, 4, 1, 215, 254, 252,\n",
" 253, 255, 255, 255, 255, 255, 255, 250, 253, 249, 5, 5, 140,\n",
" 250, 255],\n",
" [254, 253, 252, 253, 253, 255, 210, 3, 8, 2, 8, 248, 248,\n",
" 255, 255, 255, 255, 255, 255, 255, 254, 254, 247, 3, 2, 111,\n",
" 239, 255],\n",
" [254, 250, 250, 250, 251, 255, 212, 3, 8, 4, 3, 100, 253,\n",
" 251, 255, 255, 255, 255, 255, 255, 249, 252, 244, 5, 7, 5,\n",
" 184, 254],\n",
" [248, 250, 254, 254, 251, 248, 9, 0, 130, 254, 45, 21, 233,\n",
" 255, 255, 255, 255, 255, 255, 255, 255, 254, 246, 200, 4, 2,\n",
" 177, 254],\n",
" [253, 249, 249, 249, 249, 133, 2, 47, 193, 254, 143, 8, 58,\n",
" 252, 255, 255, 255, 255, 255, 255, 252, 250, 253, 201, 7, 3,\n",
" 185, 255],\n",
" [253, 243, 255, 246, 251, 21, 0, 87, 255, 253, 249, 1, 15,\n",
" 113, 253, 255, 246, 253, 244, 250, 253, 254, 252, 205, 0, 4,\n",
" 183, 254],\n",
" [247, 254, 250, 252, 181, 13, 21, 149, 248, 253, 254, 242, 8,\n",
" 8, 147, 253, 253, 247, 249, 250, 251, 254, 250, 196, 15, 2,\n",
" 187, 255],\n",
" [252, 248, 252, 253, 50, 6, 42, 252, 251, 254, 254, 236, 156,\n",
" 6, 32, 205, 255, 252, 252, 250, 246, 254, 253, 200, 1, 2,\n",
" 187, 255],\n",
" [252, 253, 250, 214, 44, 2, 86, 252, 251, 243, 251, 254, 202,\n",
" 34, 3, 5, 229, 254, 250, 250, 254, 243, 239, 216, 35, 4,\n",
" 184, 254],\n",
" [244, 253, 252, 97, 4, 2, 252, 249, 250, 255, 249, 248, 254,\n",
" 217, 68, 7, 86, 253, 250, 253, 253, 254, 244, 250, 156, 2,\n",
" 186, 255],\n",
" [255, 251, 240, 89, 6, 249, 255, 251, 250, 246, 253, 255, 251,\n",
" 255, 115, 7, 1, 239, 253, 251, 245, 252, 252, 255, 160, 4,\n",
" 184, 254],\n",
" [252, 251, 142, 2, 4, 249, 255, 255, 255, 255, 255, 255, 255,\n",
" 254, 252, 156, 11, 21, 166, 254, 254, 249, 253, 254, 161, 6,\n",
" 185, 255],\n",
" [254, 252, 141, 12, 12, 239, 251, 255, 255, 255, 255, 255, 255,\n",
" 255, 252, 254, 13, 1, 77, 255, 254, 254, 240, 203, 12, 1,\n",
" 186, 253],\n",
" [250, 187, 2, 4, 203, 248, 252, 255, 255, 255, 255, 255, 255,\n",
" 252, 252, 252, 250, 86, 1, 81, 224, 247, 251, 205, 5, 6,\n",
" 184, 255],\n",
" [253, 175, 2, 3, 201, 255, 245, 255, 255, 255, 255, 255, 255,\n",
" 250, 249, 254, 252, 247, 133, 3, 38, 221, 253, 205, 5, 0,\n",
" 187, 253],\n",
" [254, 201, 38, 35, 215, 246, 254, 255, 255, 255, 255, 255, 255,\n",
" 254, 254, 248, 253, 252, 252, 157, 22, 1, 5, 162, 3, 4,\n",
" 181, 204],\n",
" [254, 253, 214, 221, 254, 255, 253, 255, 255, 255, 255, 255, 255,\n",
" 254, 254, 255, 252, 254, 249, 253, 193, 26, 4, 4, 4, 2,\n",
" 187, 172],\n",
" [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 253, 255, 17, 20, 11, 10,\n",
" 187, 254],\n",
" [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 250, 254, 243, 249, 203, 197,\n",
" 254, 255],\n",
" [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 255, 245, 252, 254, 251, 249,\n",
" 252, 255],\n",
" [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 252, 249, 246, 248, 251, 250,\n",
" 252, 255],\n",
" [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,\n",
" 255, 255, 255, 255, 255, 255, 255, 253, 244, 250, 254, 252, 254,\n",
" 252, 255]], dtype=uint8)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_lol_img"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(28, 28)"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_lol_img.shape"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"my_lol_img = np.array(my_lol_img) / 255\n",
"my_lol_img = my_lol_img.reshape(-1, 28, 28, 1)\n",
"#y_train = np.array(y_train)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [1. ],\n",
" [0.95686275],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98431373],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.99215686],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.98431373],\n",
" [0.99607843]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99215686],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.94509804],\n",
" [0.99607843],\n",
" [0.99215686],\n",
" [0.98039216],\n",
" [1. ],\n",
" [0.98039216],\n",
" [0.99607843]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.94901961],\n",
" [0.98823529],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.98039216],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.97647059],\n",
" [0.98823529],\n",
" [0.96862745],\n",
" [0.96078431],\n",
" [0.98039216],\n",
" [1. ]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.97254902],\n",
" [0.97647059],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98039216],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.97254902],\n",
" [0.98431373],\n",
" [0.99215686],\n",
" [0.98039216],\n",
" [0.99607843]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.85098039],\n",
" [0.07058824],\n",
" [0.1254902 ],\n",
" [0.69019608],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.9372549 ],\n",
" [0.99607843],\n",
" [0.80392157],\n",
" [0.08627451],\n",
" [0.57254902],\n",
" [0.98431373],\n",
" [1. ]],\n",
"\n",
" [[0.99215686],\n",
" [0.99607843],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.89803922],\n",
" [0.24705882],\n",
" [0. ],\n",
" [0.45490196],\n",
" [0.95294118],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.99215686],\n",
" [0.92941176],\n",
" [0.02745098],\n",
" [0.02745098],\n",
" [0.55294118],\n",
" [0.97647059],\n",
" [0.99607843]],\n",
"\n",
" [[0.99607843],\n",
" [0.98823529],\n",
" [0.98431373],\n",
" [0.98431373],\n",
" [1. ],\n",
" [0.92941176],\n",
" [1. ],\n",
" [0.67058824],\n",
" [0.01568627],\n",
" [0.00392157],\n",
" [0.84313725],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.99215686],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.97647059],\n",
" [0.01960784],\n",
" [0.01960784],\n",
" [0.54901961],\n",
" [0.98039216],\n",
" [1. ]],\n",
"\n",
" [[0.99607843],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [0.99215686],\n",
" [0.99215686],\n",
" [1. ],\n",
" [0.82352941],\n",
" [0.01176471],\n",
" [0.03137255],\n",
" [0.00784314],\n",
" [0.03137255],\n",
" [0.97254902],\n",
" [0.97254902],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.96862745],\n",
" [0.01176471],\n",
" [0.00784314],\n",
" [0.43529412],\n",
" [0.9372549 ],\n",
" [1. ]],\n",
"\n",
" [[0.99607843],\n",
" [0.98039216],\n",
" [0.98039216],\n",
" [0.98039216],\n",
" [0.98431373],\n",
" [1. ],\n",
" [0.83137255],\n",
" [0.01176471],\n",
" [0.03137255],\n",
" [0.01568627],\n",
" [0.01176471],\n",
" [0.39215686],\n",
" [0.99215686],\n",
" [0.98431373],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.97647059],\n",
" [0.98823529],\n",
" [0.95686275],\n",
" [0.01960784],\n",
" [0.02745098],\n",
" [0.01960784],\n",
" [0.72156863],\n",
" [0.99607843]],\n",
"\n",
" [[0.97254902],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.98431373],\n",
" [0.97254902],\n",
" [0.03529412],\n",
" [0. ],\n",
" [0.50980392],\n",
" [0.99607843],\n",
" [0.17647059],\n",
" [0.08235294],\n",
" [0.91372549],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.96470588],\n",
" [0.78431373],\n",
" [0.01568627],\n",
" [0.00784314],\n",
" [0.69411765],\n",
" [0.99607843]],\n",
"\n",
" [[0.99215686],\n",
" [0.97647059],\n",
" [0.97647059],\n",
" [0.97647059],\n",
" [0.97647059],\n",
" [0.52156863],\n",
" [0.00784314],\n",
" [0.18431373],\n",
" [0.75686275],\n",
" [0.99607843],\n",
" [0.56078431],\n",
" [0.03137255],\n",
" [0.22745098],\n",
" [0.98823529],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.78823529],\n",
" [0.02745098],\n",
" [0.01176471],\n",
" [0.7254902 ],\n",
" [1. ]],\n",
"\n",
" [[0.99215686],\n",
" [0.95294118],\n",
" [1. ],\n",
" [0.96470588],\n",
" [0.98431373],\n",
" [0.08235294],\n",
" [0. ],\n",
" [0.34117647],\n",
" [1. ],\n",
" [0.99215686],\n",
" [0.97647059],\n",
" [0.00392157],\n",
" [0.05882353],\n",
" [0.44313725],\n",
" [0.99215686],\n",
" [1. ],\n",
" [0.96470588],\n",
" [0.99215686],\n",
" [0.95686275],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.80392157],\n",
" [0. ],\n",
" [0.01568627],\n",
" [0.71764706],\n",
" [0.99607843]],\n",
"\n",
" [[0.96862745],\n",
" [0.99607843],\n",
" [0.98039216],\n",
" [0.98823529],\n",
" [0.70980392],\n",
" [0.05098039],\n",
" [0.08235294],\n",
" [0.58431373],\n",
" [0.97254902],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.94901961],\n",
" [0.03137255],\n",
" [0.03137255],\n",
" [0.57647059],\n",
" [0.99215686],\n",
" [0.99215686],\n",
" [0.96862745],\n",
" [0.97647059],\n",
" [0.98039216],\n",
" [0.98431373],\n",
" [0.99607843],\n",
" [0.98039216],\n",
" [0.76862745],\n",
" [0.05882353],\n",
" [0.00784314],\n",
" [0.73333333],\n",
" [1. ]],\n",
"\n",
" [[0.98823529],\n",
" [0.97254902],\n",
" [0.98823529],\n",
" [0.99215686],\n",
" [0.19607843],\n",
" [0.02352941],\n",
" [0.16470588],\n",
" [0.98823529],\n",
" [0.98431373],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.9254902 ],\n",
" [0.61176471],\n",
" [0.02352941],\n",
" [0.1254902 ],\n",
" [0.80392157],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [0.98039216],\n",
" [0.96470588],\n",
" [0.99607843],\n",
" [0.99215686],\n",
" [0.78431373],\n",
" [0.00392157],\n",
" [0.00784314],\n",
" [0.73333333],\n",
" [1. ]],\n",
"\n",
" [[0.98823529],\n",
" [0.99215686],\n",
" [0.98039216],\n",
" [0.83921569],\n",
" [0.17254902],\n",
" [0.00784314],\n",
" [0.3372549 ],\n",
" [0.98823529],\n",
" [0.98431373],\n",
" [0.95294118],\n",
" [0.98431373],\n",
" [0.99607843],\n",
" [0.79215686],\n",
" [0.13333333],\n",
" [0.01176471],\n",
" [0.01960784],\n",
" [0.89803922],\n",
" [0.99607843],\n",
" [0.98039216],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [0.95294118],\n",
" [0.9372549 ],\n",
" [0.84705882],\n",
" [0.1372549 ],\n",
" [0.01568627],\n",
" [0.72156863],\n",
" [0.99607843]],\n",
"\n",
" [[0.95686275],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [0.38039216],\n",
" [0.01568627],\n",
" [0.00784314],\n",
" [0.98823529],\n",
" [0.97647059],\n",
" [0.98039216],\n",
" [1. ],\n",
" [0.97647059],\n",
" [0.97254902],\n",
" [0.99607843],\n",
" [0.85098039],\n",
" [0.26666667],\n",
" [0.02745098],\n",
" [0.3372549 ],\n",
" [0.99215686],\n",
" [0.98039216],\n",
" [0.99215686],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.95686275],\n",
" [0.98039216],\n",
" [0.61176471],\n",
" [0.00784314],\n",
" [0.72941176],\n",
" [1. ]],\n",
"\n",
" [[1. ],\n",
" [0.98431373],\n",
" [0.94117647],\n",
" [0.34901961],\n",
" [0.02352941],\n",
" [0.97647059],\n",
" [1. ],\n",
" [0.98431373],\n",
" [0.98039216],\n",
" [0.96470588],\n",
" [0.99215686],\n",
" [1. ],\n",
" [0.98431373],\n",
" [1. ],\n",
" [0.45098039],\n",
" [0.02745098],\n",
" [0.00392157],\n",
" [0.9372549 ],\n",
" [0.99215686],\n",
" [0.98431373],\n",
" [0.96078431],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [1. ],\n",
" [0.62745098],\n",
" [0.01568627],\n",
" [0.72156863],\n",
" [0.99607843]],\n",
"\n",
" [[0.98823529],\n",
" [0.98431373],\n",
" [0.55686275],\n",
" [0.00784314],\n",
" [0.01568627],\n",
" [0.97647059],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.61176471],\n",
" [0.04313725],\n",
" [0.08235294],\n",
" [0.65098039],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.97647059],\n",
" [0.99215686],\n",
" [0.99607843],\n",
" [0.63137255],\n",
" [0.02352941],\n",
" [0.7254902 ],\n",
" [1. ]],\n",
"\n",
" [[0.99607843],\n",
" [0.98823529],\n",
" [0.55294118],\n",
" [0.04705882],\n",
" [0.04705882],\n",
" [0.9372549 ],\n",
" [0.98431373],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [0.05098039],\n",
" [0.00392157],\n",
" [0.30196078],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.94117647],\n",
" [0.79607843],\n",
" [0.04705882],\n",
" [0.00392157],\n",
" [0.72941176],\n",
" [0.99215686]],\n",
"\n",
" [[0.98039216],\n",
" [0.73333333],\n",
" [0.00784314],\n",
" [0.01568627],\n",
" [0.79607843],\n",
" [0.97254902],\n",
" [0.98823529],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [0.98039216],\n",
" [0.3372549 ],\n",
" [0.00392157],\n",
" [0.31764706],\n",
" [0.87843137],\n",
" [0.96862745],\n",
" [0.98431373],\n",
" [0.80392157],\n",
" [0.01960784],\n",
" [0.02352941],\n",
" [0.72156863],\n",
" [1. ]],\n",
"\n",
" [[0.99215686],\n",
" [0.68627451],\n",
" [0.00784314],\n",
" [0.01176471],\n",
" [0.78823529],\n",
" [1. ],\n",
" [0.96078431],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98039216],\n",
" [0.97647059],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.96862745],\n",
" [0.52156863],\n",
" [0.01176471],\n",
" [0.14901961],\n",
" [0.86666667],\n",
" [0.99215686],\n",
" [0.80392157],\n",
" [0.01960784],\n",
" [0. ],\n",
" [0.73333333],\n",
" [0.99215686]],\n",
"\n",
" [[0.99607843],\n",
" [0.78823529],\n",
" [0.14901961],\n",
" [0.1372549 ],\n",
" [0.84313725],\n",
" [0.96470588],\n",
" [0.99607843],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [0.97254902],\n",
" [0.99215686],\n",
" [0.98823529],\n",
" [0.98823529],\n",
" [0.61568627],\n",
" [0.08627451],\n",
" [0.00392157],\n",
" [0.01960784],\n",
" [0.63529412],\n",
" [0.01176471],\n",
" [0.01568627],\n",
" [0.70980392],\n",
" [0.8 ]],\n",
"\n",
" [[0.99607843],\n",
" [0.99215686],\n",
" [0.83921569],\n",
" [0.86666667],\n",
" [0.99607843],\n",
" [1. ],\n",
" [0.99215686],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99607843],\n",
" [0.99607843],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [0.97647059],\n",
" [0.99215686],\n",
" [0.75686275],\n",
" [0.10196078],\n",
" [0.01568627],\n",
" [0.01568627],\n",
" [0.01568627],\n",
" [0.00784314],\n",
" [0.73333333],\n",
" [0.6745098 ]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99215686],\n",
" [1. ],\n",
" [0.06666667],\n",
" [0.07843137],\n",
" [0.04313725],\n",
" [0.03921569],\n",
" [0.73333333],\n",
" [0.99607843]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [0.95294118],\n",
" [0.97647059],\n",
" [0.79607843],\n",
" [0.77254902],\n",
" [0.99607843],\n",
" [1. ]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.96078431],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [0.98431373],\n",
" [0.97647059],\n",
" [0.98823529],\n",
" [1. ]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.98823529],\n",
" [0.97647059],\n",
" [0.96470588],\n",
" [0.97254902],\n",
" [0.98431373],\n",
" [0.98039216],\n",
" [0.98823529],\n",
" [1. ]],\n",
"\n",
" [[1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [1. ],\n",
" [0.99215686],\n",
" [0.95686275],\n",
" [0.98039216],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [0.99607843],\n",
" [0.98823529],\n",
" [1. ]]]])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_lol_img"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"import keras"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"model = keras.models.load_model('my_model.h5')"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"my_lol_prediction = model.predict(my_lol_img)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1.1581924e-07, 4.1368559e-10, 6.4555923e-07, 2.2491538e-05,\n",
" 1.4397167e-12, 3.6010979e-15, 5.0695167e-11, 8.0478216e-08,\n",
" 3.4654861e-12, 6.4896874e-08, 1.4367749e-06, 8.8046843e-05,\n",
" 7.5111379e-06, 2.3038849e-01, 1.7430016e-06, 5.7561249e-09,\n",
" 4.5668517e-07, 4.1635683e-08, 5.5010565e-09, 1.1502559e-11,\n",
" 7.6300371e-01, 6.4844764e-03, 3.5521356e-07, 3.8272912e-08,\n",
" 2.2634480e-07, 2.1373243e-10]], dtype=float32)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_lol_prediction"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Largest element present in given array: 0.7630037\n"
]
}
],
"source": [
"max = my_lol_prediction[0][0]; \n",
" \n",
"#Loop through the array \n",
"for i in range(0, len(my_lol_prediction[0])): \n",
" #Compare elements of array with max \n",
" if(my_lol_prediction[0][i] > max): \n",
" max = my_lol_prediction[0][i]; \n",
" \n",
"print(\"Largest element present in given array: \" + str(max)); "
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n"
]
}
],
"source": [
"for i in range(0, len(my_lol_prediction[0])):\n",
" if(my_lol_prediction[0][i] == max):\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.9999999418151907\n"
]
}
],
"source": [
"mysum = 0\n",
"for i in range(0, len(my_lol_prediction[0])):\n",
" mysum = mysum + my_lol_prediction[0][i]\n",
"print(mysum)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"my_lol_prediction_2 = np_utils.to_categorical(my_lol_prediction)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.],\n",
" [1.]]], dtype=float32)"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_lol_prediction_2"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "in user code:\n\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1478 predict_function *\n return step_function(self, iterator)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1468 step_function **\n outputs = model.distribute_strategy.run(run_step, args=(data,))\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run\n return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica\n return self._call_for_each_replica(fn, args, kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica\n return fn(*args, **kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1461 run_step **\n outputs = model.predict_step(data)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1434 predict_step\n return self(x, training=False)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__\n input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/input_spec.py:234 assert_input_compatibility\n raise ValueError('Input ' + str(input_index) + ' of layer ' +\n\n ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 28, 1)\n",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-45-eaadab8cccde>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmy_lol_prediction_3\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[1;32m 1627\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mstep\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msteps\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1628\u001b[0m \u001b[0mcallbacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_predict_batch_begin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1629\u001b[0;31m \u001b[0mtmp_batch_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1630\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1631\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masync_wait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 826\u001b[0m \u001b[0mtracing_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexperimental_get_tracing_count\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 827\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mtrace\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTrace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_name\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mtm\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 828\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 829\u001b[0m \u001b[0mcompiler\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"xla\"\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_experimental_compile\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;34m\"nonXla\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 830\u001b[0m \u001b[0mnew_tracing_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexperimental_get_tracing_count\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m 860\u001b[0m \u001b[0;31m# In this case we have not created variables on the first call. So we can\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 861\u001b[0m \u001b[0;31m# run the first trace but we should fail if variables are created.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 862\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_stateful_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 863\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_created_variables\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 864\u001b[0m raise ValueError(\"Creating variables on a non-first call to a function\"\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 2939\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_lock\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2940\u001b[0m (graph_function,\n\u001b[0;32m-> 2941\u001b[0;31m filtered_flat_args) = self._maybe_define_function(args, kwargs)\n\u001b[0m\u001b[1;32m 2942\u001b[0m return graph_function._call_flat(\n\u001b[1;32m 2943\u001b[0m filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m_maybe_define_function\u001b[0;34m(self, args, kwargs)\u001b[0m\n\u001b[1;32m 3355\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput_signature\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3356\u001b[0m call_context_key in self._function_cache.missed):\n\u001b[0;32m-> 3357\u001b[0;31m return self._define_function_with_shape_relaxation(\n\u001b[0m\u001b[1;32m 3358\u001b[0m args, kwargs, flat_args, filtered_flat_args, cache_key_context)\n\u001b[1;32m 3359\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m_define_function_with_shape_relaxation\u001b[0;34m(self, args, kwargs, flat_args, filtered_flat_args, cache_key_context)\u001b[0m\n\u001b[1;32m 3277\u001b[0m expand_composites=True)\n\u001b[1;32m 3278\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3279\u001b[0;31m graph_function = self._create_graph_function(\n\u001b[0m\u001b[1;32m 3280\u001b[0m args, kwargs, override_flat_arg_shapes=relaxed_arg_shapes)\n\u001b[1;32m 3281\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_function_cache\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marg_relaxed\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrank_only_cache_key\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgraph_function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/function.py\u001b[0m in \u001b[0;36m_create_graph_function\u001b[0;34m(self, args, kwargs, override_flat_arg_shapes)\u001b[0m\n\u001b[1;32m 3194\u001b[0m \u001b[0marg_names\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbase_arg_names\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mmissing_arg_names\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3195\u001b[0m graph_function = ConcreteFunction(\n\u001b[0;32m-> 3196\u001b[0;31m func_graph_module.func_graph_from_py_func(\n\u001b[0m\u001b[1;32m 3197\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_name\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3198\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_python_function\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py\u001b[0m in \u001b[0;36mfunc_graph_from_py_func\u001b[0;34m(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)\u001b[0m\n\u001b[1;32m 988\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moriginal_func\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_decorator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munwrap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpython_func\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 989\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 990\u001b[0;31m \u001b[0mfunc_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpython_func\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mfunc_args\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mfunc_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 991\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 992\u001b[0m \u001b[0;31m# invariant: `func_outputs` contains only Tensors, CompositeTensors,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py\u001b[0m in \u001b[0;36mwrapped_fn\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 632\u001b[0m \u001b[0mxla_context\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mExit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 633\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 634\u001b[0;31m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mweak_wrapped_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__wrapped__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 635\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 636\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 975\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# pylint:disable=broad-except\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 976\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"ag_error_metadata\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 977\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mag_error_metadata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 978\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 979\u001b[0m \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: in user code:\n\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1478 predict_function *\n return step_function(self, iterator)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1468 step_function **\n outputs = model.distribute_strategy.run(run_step, args=(data,))\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run\n return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica\n return self._call_for_each_replica(fn, args, kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica\n return fn(*args, **kwargs)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1461 run_step **\n outputs = model.predict_step(data)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:1434 predict_step\n return self(x, training=False)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:998 __call__\n input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)\n /Users/nishanthkrishna/opt/anaconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/input_spec.py:234 assert_input_compatibility\n raise ValueError('Input ' + str(input_index) + ' of layer ' +\n\n ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 28, 1)\n"
]
}
],
"source": [
"my_lol_prediction_3 = model.predict(X_train[0])"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(28, 28, 1)"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_train[0].shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
2021-04-01 03:16:00 -07:00
}