hi so I build a DNN network to classify some objects in an image using the features of the object, like bellow :
contours, _ = cv2.findContours(imgthresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
for contour in contours:
features = np.array([])
(x_start, y_start, character_width, character_height) = cv2.boundingRect(contour)
x_end = x_start + character_width
y_end = y_start + character_height
character_area = character_width * character_height
features = np.append(features, [character_width, character_height, character_area, x_start,
y_start, x_end, y_end, image_width, image_height])
print(features)
print(features.shape)
cv2.rectangle(image, (x_start, y_start), (x_end, y_end), (0, 255, 0), thickness=1)
print(features) output is:
[ 5. 1. 5. 105. 99. 110. 100. 100. 117.]
and print(features.shape) is:
(9,)
I build and trained a DNN using the following code :
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(40, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(30,activation='relu'))
model.add(Dense(2, activation='softmax'))
The input layer has 9 input features. So I tried to get the prediction of the model using:
model.predict_classes(features)
The training data, a CSV file, contains 10 columns (9 features and 1 for the output)
I got the following error :
ValueError: Error when checking input: expected dense_1_input to have shape (9,) but got array with shape (1,)
I tried to reshape the features array by using :
np.reshape(features,(1,9)
but that didn't work either. I am still new at this field
print(features)line outputs? As you initialize your array withnp.array([])and then append something, I suppose that the first element of your array is an list of shape (1,)