File size: 1,520 Bytes
3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 73b58d0 3e5fdde 65abef9 3e5fdde 65abef9 3e5fdde 73b58d0 3e5fdde 65abef9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
from gradio import Interface
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import datasets, layers, models
import numpy as np
(X_train, y_train) , (X_test, y_test) = keras.datasets.mnist.load_data()
X_train = np.concatenate((X_train, X_test))
y_train = np.concatenate((y_train, y_test))
X_train = X_train / 255
X_test = X_test / 255
data_augmentation = keras.Sequential([
tf.keras.layers.experimental.preprocessing.RandomRotation(0.2, input_shape=(28, 28, 1)),
])
model = models.Sequential([
data_augmentation,
#cnn
layers.Conv2D(filters=32, kernel_size=(3,3), padding='same', activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Conv2D(filters=32, kernel_size=(3,3), padding='same', activation='relu'),
layers.MaxPooling2D((2,2)),
#dense
layers.Flatten(),
layers.Dense(32, activation='relu'),
layers.Dense(10, activation='softmax'),
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train, y_train, epochs=1)
def predict_image(img):
img_3d = img.reshape(-1, 28,28)
img_scaled = img_3d/255
prediction = model.predict(img_scaled)
pred = np.argmax(prediction)
return pred.item()
iface = gr.Interface(predict_image, inputs='sketchpad', outputs='label', title='Digit Recognition Model By Debamrita Paul', description='Draw a single digit(0 to 9)')
iface.launch() |