Please help me i am getting at the end of my program test
# now we will read images from the folder segment the images and will produce the output
for image_name in listdir('images'):
counter = 1
# constructing the name of the file
file_name = 'images/' + image_name
# getting segmented images
letters_in_image = image_segmentation(file_name)
# sorting the letters so that letters that appear before is addressed first
letters_in_image = sorted(letters_in_image, key=lambda x: x[0])
ans =
for (x,y,w,h) in letters_in_image:
image = cv2.imread(file_name,0)
letter = image[y - 2:y + h + 2, x - 2:x + w + 2]
cv2.imwrite(str(counter)+'.jpg', letter)
counter = counter + 1
letter = resize(letter)/255
X_test = np.asarray(letter)
X_test = np.reshape(X_test, [-1,20,20,1])
output = np.argmax(model.predict(X_test, verbose = 0))
output = label_encoder.inverse_transform(output)
ans +=output
print(image no: , ans)
When running the code above, I am getting the following error:
Traceback (most recent call last)
Input In [13], in cell line: 2()
23 X_test = np.reshape(X_test, [-1,20,20,1])
24 output = np.argmax(model.predict(X_test, verbose = 0))
--- 25 output = label_encoder.inverse_transform(output)
26 ans +=output
27 print(image no: , ans)
File ~/.local/lib/python3.8/site-packages/sklearn/preprocessing/_label.py:154, in LabelEncoder.inverse_transform(self, y)
141 Transform labels back to original encoding.
142
143 Parameters
(...)
151 Original encoding.
152
153 check_is_fitted(self)
-- 154 y = column_or_1d(y, warn=True)
155 # inverse transform of empty array is empty array
156 if _num_samples(y) == 0:
File ~/.local/lib/python3.8/site-packages/sklearn/utils/validation.py:1038, in column_or_1d(y, warn)
1029 warnings.warn(
1030 A column-vector y was passed when a 1d array was
1031 expected. Please change the shape of y to
(...)
1034 stacklevel=2,
1035 )
1036 return np.ravel(y)
- 1038 raise ValueError(
1039 y should be a 1d array, got an array of shape {} instead..format(shape)
1040 )
ValueError: y should be a 1d array, got an array of shape () instead.
Topic convolutional-neural-network
Category Data Science