omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello β€” I'm @olemoritz on Twitter.


    Machine Learning

    Pythonista
    neural network machine learnin
    8
    68
    36248
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mkeywood
      mkeywood last edited by mkeywood

      I don't know if anyone's interested, but I took a combination of the Sketch example, along with some other examples I've seen online, and come up with the following.

      It's a simple Neural Network class, prepare data, train it and it can hopefully guess what you draw to test it with.

      Simply:

      • Draw three positive image, all the same. I.e. Draw three smiley faces.
      • Then draw three negative images, all the same. I.e. Draw three sad faces.
      • Then press the Train button.
      • OK so now it's ready. Draw either a copy of the positive or negative image, and see if it gets it right πŸ˜€

      I don't claim this is the best code ever, or even efficient algorithm and could be tuned much better, but thought I'd share it anyway πŸ˜€

      https://gist.github.com/d77486f38d5d23d6ffd696e7bf0545fc

      cvp 1 Reply Last reply Reply Quote 5
      • mkeywood
        mkeywood last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @mkeywood last edited by

          @mkeywood Nice code, I've tried, not always successfully but I like it....

          mkeywood 1 Reply Last reply Reply Quote 0
          • jmv38
            jmv38 last edited by jmv38

            @mkeywood thank you! Incredible that it is so simple to make some NN. You demystified it.
            How can you add layers?
            Can you make CNN too?

            mkeywood 1 Reply Last reply Reply Quote 0
            • mkeywood
              mkeywood @jmv38 last edited by

              @jmv38, thanks.

              Currently it’s quite simple and so not massively extensible for things like CNN. Although that is the area I’m looking at now πŸ˜„

              As for additional layers, we could add them relatively easy. Basically it’s all geared around variables W1 and W2 that are the weights between the input and hidden layer, and hidden and output layers respectively.
              Extending the init, forward, backward etc should be easy enough to extend.
              Something else I can look at πŸ˜„

              1 Reply Last reply Reply Quote 0
              • mkeywood
                mkeywood @cvp last edited by

                @cvp, thanks πŸ˜„ My daughter played with lots of different sketches and found some more reliable than others.

                1 Reply Last reply Reply Quote 0
                • jmv38
                  jmv38 last edited by

                  @mkeywood i have tried to add some robustness: i shift the drawings in 9 position for the training. I had to decrease the learning rate by x0.1. Is it ok? what do you think?
                  Not sure the performance is better.

                  note: I also changed the layout because i work in landscape.

                  https://gist.github.com/d87a0833a64f0128a12c59547984ad2f

                  1 Reply Last reply Reply Quote 0
                  • jmv38
                    jmv38 last edited by

                    I have changed the learning rate to 0.02 and increased the number of training epochs to 200: i am getting good results now.

                    1 Reply Last reply Reply Quote 0
                    • jmv38
                      jmv38 last edited by jmv38

                      @mkeywood really having fun with your code, thanks so much for sharing!
                      Now i made some more changes: using 2 neurons in the output, to get independant estimates and reliability (and also to see the result with a 3rd template that is not 1 or 2).
                      I have also added a small rotation in the training, and tweeked a little bit the training parameters.
                      https://gist.github.com/e373904d3ccba03803d80173f44b5eee

                      1 Reply Last reply Reply Quote 0
                      • jmv38
                        jmv38 last edited by jmv38

                        @mkeywood
                        update: i have made a Layer class to more easily add layers. I have now 4 layers. It seems to work, but i have not checked if the undeground maths are correct. I’ve assumed your formula to backpropagate the error is recursive.
                        With this implementation you can use the number of layers you want, with the number of neurons you want inside.

                        https://gist.github.com/aea7738590793eefcd786be8657fa88b

                        mkeywood 1 Reply Last reply Reply Quote 0
                        • mkeywood
                          mkeywood @jmv38 last edited by

                          @jmv38 this is awesome!!

                          Glad it was helpful, but you've taken it to another level completely πŸ˜€
                          That's some really great additions. Really amazing. I look forward to see what you do next πŸ˜€

                          Thanks πŸ˜€

                          jmv38 1 Reply Last reply Reply Quote 0
                          • jmv38
                            jmv38 @mkeywood last edited by

                            @mkeywood here is an update:
                            https://gist.github.com/3c9f5917224d8a70ea319af1df973c73

                            i have made 3 inputs, many duplicates, and some live feedback during learning. Works not bad sometimes.

                            1 Reply Last reply Reply Quote 0
                            • jmv38
                              jmv38 last edited by

                              another one: now i display the learning set while creating it
                              https://gist.github.com/549d071893cac00e84fcd1875d422d1a

                              1 Reply Last reply Reply Quote 0
                              • jmv38
                                jmv38 last edited by

                                hello
                                v08: added a white image and a random image should return 0: to improve robustness
                                https://gist.github.com/d21c832208f33fe083b9200b29e1f073

                                Matteo 1 Reply Last reply Reply Quote 1
                                • Matteo
                                  Matteo @jmv38 last edited by

                                  @jmv38 Hi interesting project! I'd like to ask you two things about it:

                                  1. could you easly modify your script in order to allow execution also on little screens (4 in)? Does anyone here (Pythonista forum) know a general way to modify easly a script with UI in order to adapt it automatically according to screen size (through the automatic recognition of the screen size of the device where the script is executed)?
                                  2. only for fun, if you are interested: how about a script (by following your original script) that tries to learn to play tic-tac-toe game? For example with random choice of moves at beginning and positive weight to set of moves for winner player in several matches, in order to create a set of moves (getting closer to being the best ones) for each situation? What would you suggest?

                                  Thank you and feel free to share some reasoning about it.
                                  Regards

                                  jmv38 1 Reply Last reply Reply Quote 0
                                  • jmv38
                                    jmv38 @Matteo last edited by jmv38

                                    @Matteo hello.
                                    Note that mkeywood made the original programm and ui layout. I just made a set of small changes each time that lead me here.
                                    For you questions:
                                    1/ the ui part is at the bottom of the script. You can change the numbers and the layout to match your screen definition. That is some work though (1 hour or less).
                                    2/ that would be quite some thinking to do that. For the moment i am just doing simple things to learn python, by tweaking mkeywood programm, so it is beyond me.
                                    Thanks.

                                    Matteo 1 Reply Last reply Reply Quote 0
                                    • Matteo
                                      Matteo @jmv38 last edited by

                                      @jmv38 Oops, you are right , my mistake, sorry @mkeywood :-), I didn't read the whole thread...

                                      Anyway thank you for the answer. Some times ago I started for fun to study something about ML, and the first test example in my mind was an algorithm able to learn how to play a simple game like tictactoe, without studying any python specific library for ML.

                                      The interesting thing in my opinion is how to create a general algorithm able to learn something without any big python libraries, only as a concept proof and with some little constraints defined by user for the research of the Ml goal/goals. The constraints could change in the algorithm when some situations occur during calculation. So thank you again both for your work, maybe it could give me some technical info for the ML game solver I've in mind.

                                      Regards

                                      1 Reply Last reply Reply Quote 0
                                      • jmv38
                                        jmv38 last edited by jmv38

                                        v09:
                                        1/ cleaned up some code
                                        2/ live color feedback during training on samples
                                        https://gist.github.com/89684d9166746504bba88348240e26ff

                                        1 Reply Last reply Reply Quote 0
                                        • jmv38
                                          jmv38 last edited by

                                          v10: 1/ added a [learn more] button to ... learn more.
                                          https://gist.github.com/f7fc75b727c953e4dbb59c04f88acf74

                                          1 Reply Last reply Reply Quote 0
                                          • mkeywood
                                            mkeywood last edited by

                                            @jmv38, looks like some great updates. I look forward to looking over them this weekend :)

                                            @Matteo, no problem at all. @jmv38 has built on it massively from what I did. Really this is here for anyone to enjoy.

                                            Thanks

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors