I'm trying to do classification of traffic signs using webcam. I am facing an issue on the reshape line (last 2nd) in the block below. I tried to figure out a lot but can't find solution to it please help. Here I want to make the image array 1D.
while True:
ret, image_seen = cap.read()
image_ = np.asarray(image_seen)
image_ = cv2.resize(image_, (30, 30))
image_ = imgpreprocess(image_)
cv2.imshow("Processed Image", image_)
####
image_ = image_.reshape(1, 30, 30, 1)
####
cv2.putText(image_seen, "CLASS: ", (20,35), font, 0.75, (0,0,255), 2,
cv2.LINE_AA)
Below is my model:
base_model = tf.keras.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu', input_shape=(30, 30, 1)),
tf.keras.layers.Dense(43)
])
And here's how I preprocessed the images:
def imgpreprocess(img):
# to grayscale
img = cv2.cvtColor(np.float32(img), cv2.COLOR_BGR2GRAY)
img = img/225.0
return img
Error is:
Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 2700 but received input with shape [None, 900]
Any help would be appreciated, thanks.
I can not reproduce your error. Your model works:
import tensorflow as tf
base_model = tf.keras.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu', input_shape=(30, 30, 1)),
tf.keras.layers.Dense(43)
])
inp = tf.random.uniform((1, 30, 30, 1))
a = base_model(inp)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.