I'm trying to learn Machine Learning, so I'm following a tutorial on how to train a network to recognize digits. I'm at the stage where I've trained the network and I'm trying out some of my own images. However, somehow there is a problem with recognizing the images. I'm not sure what I've done wrong. I've uploaded the images in the same directory folder. You can find the code and errors below.
Errors
img = cv.imread(f'{x}.png')[:,:,0]
TypeError: 'NoneType' object is not subscriptable
I'm also getting this error although it doesn't seem to be affecting anything. Should I be worried about it?
2021-08-04 17:53:03.097193: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-08-04 17:53:03.099366: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
Code
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28)))
model.add(tf.keras.layers.Dense(units=128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(units=128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(units = 10, activation=tf.nn.softmax))
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=3)
accuracy, loss = model.evaluate(x_test, y_test)
print(accuracy)
print(loss)
model.save('digits.model')
for x in range(1,6):
img = cv.imread(f'{x}.png')[:,:,0]
img= np.array([img])
plt.imshow(img[0], cmap=plt.cm.binary)
plt.show()