Ask Your Question
0

Python ANN not training [SOLVED]

asked 2018-04-27 17:17:10 -0600

sjhalayka gravatar image

updated 2018-04-28 20:31:56 -0600

Below is my code for the ANN in Python. It doesn't seem to want to train however.

As you can see by the code, the image conversion is a complicated mess.

I put lots of comments in the code.

Any ideas?

https://github.com/sjhalayka/python_o...

edit retag flag offensive close merge delete

Comments

1
  • needs more data. you cannot successfully train with 2 images only.
  • you need to resize them to something sensible, like 32x32
  • your "batches" don't work. again with 2 img only, it will overfit very fast (and stop to learn anything)
  • try to get like 20 (or better 200) examples per class, resize & flatten them, put them into a single traindata Mat, and train with a few k iterations(in the termcriteria). again, only use batches here, IF your data does not fit into memory
berak gravatar imageberak ( 2018-04-28 04:04:11 -0600 )edit

64x64 is not unreasonable, nor is 512x512. I am going to try to get more input images, but 4 classifications shouldn't be too little... I am thinking of the python opencv XOR ANN, which only has 4 classifications. I just did that the other day: https://github.com/sjhalayka/python_o...

sjhalayka gravatar imagesjhalayka ( 2018-04-28 13:57:33 -0600 )edit
1

I am thinking of the python opencv XOR ANN,

yea, but that will fool you forever. it's not at all a realistic assumption / problem.

berak gravatar imageberak ( 2018-04-28 17:21:28 -0600 )edit

I also tried the same code (as much as possible) in C++, and it works:

https://github.com/sjhalayka/opencv_i...

sjhalayka gravatar imagesjhalayka ( 2018-04-28 18:41:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-28 20:32:56 -0600

sjhalayka gravatar image

The answer is to set up the network using these functions:

ann = cv2.ml.ANN_MLP_create()
ann.setLayerSizes(np.array([num_input_neurons, num_hidden_neurons, num_output_neurons], dtype=np.int64))
ann.setActivationFunction(cv2.ml.ANN_MLP_SIGMOID_SYM)
ann.setTermCriteria((cv2.TERM_CRITERIA_COUNT | cv2.TERM_CRITERIA_EPS, 1, 0.000001 ))
ann.setTrainMethod(cv2.ml.ANN_MLP_BACKPROP, 0.001)
#ann.setBackpropMomentumScale(0.00001)
ann.setBackpropWeightScale(0.00001)

I swear I tried this approach before, but I guess not. Thanks to @berak for the help again.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-27 17:17:10 -0600

Seen: 439 times

Last updated: Apr 28 '18