Skip to content

Instantly share code, notes, and snippets.

@kumarvipu1
Last active February 3, 2021 20:45
Show Gist options
  • Save kumarvipu1/92d38f0c3a20b6951702d83340aa1190 to your computer and use it in GitHub Desktop.
Save kumarvipu1/92d38f0c3a20b6951702d83340aa1190 to your computer and use it in GitHub Desktop.
image classifier part 5
#importing and processing input image
import cv2
img = cv2.imread("sample_img.jpg") #loading input image
img = cv2.resize(img, (28, 28), interpolation = cv2.INTER_AREA) #resizing to input shape
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #chaging to grayscale format
img = cv2.bitwise_not(img) #the color scale was inverted, correcting inverted color scale
img = cv2.Canny(img, 50, 50) # removing noise
predict_data = np.array([img])/255 #changing image data to array
predict_data = predict_data.reshape(1,28, 28, 1) #reshaping to input shape
#predicting the input
from tensorflow.keras import models
model = models.load_model('cnn_digitclass.model') #loading pre-savedd model
prediction = model.predict(predict_data) #gives array
predicted_number = np.argmax(prediction) #extracts predicted number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment