Delete chess-figures-classification.py
Browse files
chess-figures-classification.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import tensorflow as tf
|
3 |
-
import numpy as np
|
4 |
-
from PIL import Image
|
5 |
-
|
6 |
-
|
7 |
-
model_path = "chess-predict-model_transferlearning.keras"
|
8 |
-
model = tf.keras.models.load_model(model_path)
|
9 |
-
|
10 |
-
# Define the core prediction function
|
11 |
-
def predict_figure(image):
|
12 |
-
# Preprocess image
|
13 |
-
print(type(image))
|
14 |
-
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
15 |
-
image = image.resize((150, 150)) #resize the image to 150x150
|
16 |
-
image = np.array(image)
|
17 |
-
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
18 |
-
|
19 |
-
# Predict
|
20 |
-
prediction = model.predict(image)
|
21 |
-
|
22 |
-
# Apply softmax to get probabilities for each class
|
23 |
-
prediction = tf.nn.softmax(prediction)
|
24 |
-
|
25 |
-
# Create a dictionary with the probabilities for each Pokemon
|
26 |
-
bishop = np.round(float(prediction[0][0]), 2)
|
27 |
-
king = np.round(float(prediction[0][1]), 2)
|
28 |
-
knight = np.round(float(prediction[0][2]), 2)
|
29 |
-
pawn = np.round(float(prediction[0][3]), 2)
|
30 |
-
queen = np.round(float(prediction[0][4]), 2)
|
31 |
-
rook = np.round(float(prediction[0][5]), 2)
|
32 |
-
|
33 |
-
|
34 |
-
return {'Bishop': bishop, 'King': king, 'Knight': knight, 'Pawn': pawn, 'Queen': queen, 'Rook': rook}
|
35 |
-
|
36 |
-
input_image = gr.Image()
|
37 |
-
iface = gr.Interface(
|
38 |
-
fn=predict_figure,
|
39 |
-
inputs=input_image,
|
40 |
-
outputs=gr.Label(),
|
41 |
-
description="A simple mlp classification model for image classification using the mnist dataset.")
|
42 |
-
iface.launch(share=True)
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|