Code
####################imports####################
import numpy as np
import tensorflow as tf
sprite=Sprite('Tobi')
sprite1 = Sprite('Iris-versicolor')
sprite1.hide()
####################imports####################
model= tf.keras.models.load_model(
"num_model.h5",
custom_objects=None,
compile=True,
options=None)
SepalLengthCm= int(sprite.input("Enter Sepal Length"))
SepalWidthCm=int(sprite.input("Enter Sepal Width"))
PetalLengthCm=int(sprite.input("Enter Petal Length"))
PetalWidthCm=int(sprite.input("Enter Petal Width"))
class_list = ['Iris-versicolor','Iris-virginica','Iris-setosa',] # List of all the classes
inputValue=[SepalLengthCm,SepalWidthCm,PetalLengthCm,PetalWidthCm,] # Input List
inputTensor = tf.expand_dims(inputValue, 0) # Input Tensor
predict = model.predict(inputTensor) # Making an initial prediction using the model
predict_index = np.argmax(predict[0], axis=0) # Generating index out of the prediction
predicted_class = class_list[predict_index] # Tallying the index with class list
sprite.say(predicted_class)
sprite1.show()
sprite1.switchcostume(predicted_class)
Logic
The example demonstrates how to count nuts and bolts from an image of a stage. Following are the key steps happening:
- Creates a sprite object named “Tobi”. A sprite is typically a graphical element that can be animated or displayed on a screen.
- Creates another sprite by uploading an iris image from the computer; add another image of a different type of iris by clicking at costume place.
- Initialize a new sprite variable in the “Tobi” script and hide another sprite initially.
sprite1 = Sprite('Iris-versicolor') sprite1.hide()
- Write a code for taking input of sepal and petal length and width from the user and storing all of this in a new variable.
SepalLengthCm= int(sprite.input("Enter Sepal Length")) SepalWidthCm=int(sprite.input("Enter Sepal Width")) PetalLengthCm=int(sprite.input("Enter Petal Length")) PetalWidthCm=int(sprite.input("Enter Petal Width"))
- Write a predefined function (sprite.say()) by which ‘Tobi’ will say the name of the predicted class.
- Now show the hidden sprite by calling a predefined function.
sprite1.show()
- Also write a predefined function by which images will switch according to predicted class.
sprite1.switchcostume(predicted_class)