Ask Your Question
0

cv2.error: OpenCV(4.3.0) error: (-215:Assertion failed)

asked 2020-06-28 21:20:45 -0600

zjerry gravatar image

updated 2020-06-29 02:44:25 -0600

berak gravatar image

.

ann.train(np.array(image, dtype=np.float32), cv2.ml.ROW_SAMPLE, np.array(trainingLabel, dtype=np.float32))


cv2.error: OpenCV(4.3.0) ..\modules\ml\src\data.cpp:257: error: (-215:Assertion failed) samples.type() == CV_32F || samples.type() == CV_32S in function 'cv::ml::TrainDataImpl::setData'
edit retag flag offensive close merge delete

Comments

we probably need to see more code.

please edit your question, and show, how you construct trainData and labels

berak gravatar imageberak ( 2020-06-29 01:10:36 -0600 )edit
1

fact that you tried to wrap your data with np.array() already looks desperate / suspect ...

berak gravatar imageberak ( 2020-06-29 01:43:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-06-29 04:03:48 -0600

supra56 gravatar image

updated 2020-06-29 05:55:30 -0600

As @berak point out that suspect. I was looking at my code. The suspect is image in parameter. You can't used image in numpy array. You usually used index array. I have snippet code:

m1 = [270, 110, 150, 120, 370, 570, 110, 290, 350,380]
m2 = [55, 55, 51, 92, 78, 27, 14, 8, 26,54]
m3 = [38, 35, 39, 98, 57, 62, 10, 62, 43,89]

n1 = [0, 0, 1]
n2 = [0, 1, 0]
n3 = [1, 0, 0]

SAMPLES = 5000  
for x in range(0, SAMPLES):
  print(f'Samples {}{}'.format(x, SAMPLES)
  ann.train(np.array([m1, m2, m3],  np.float32),
            cv2.ml.ROW_SAMPLE,
            np.array([n1, n2, n3], np.float32))

Edit: As @berak point out w//out looping. I was doing tensorflow and keras. You can do like this:

ann.train(np.array([m1, m2, m3],  np.float32),
                cv2.ml.ROW_SAMPLE,
                np.array([n1, n2, n3], np.float32))
edit flag offensive delete link more

Comments

1

btw, you don't need the loop to show how it works (and it would be even wrong)

berak gravatar imageberak ( 2020-06-29 04:26:13 -0600 )edit

I will test it w/out looping. And will report back.

supra56 gravatar imagesupra56 ( 2020-06-29 05:36:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-06-28 21:20:45 -0600

Seen: 3,959 times

Last updated: Jun 29 '20