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
    36373
    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.
    • 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
              • jmv38
                jmv38 last edited by jmv38

                Please help wanted!
                I am stuck on a bug and i cant find what i am doing wrong.
                here is the gist https://gist.github.com/3af5cf10e59944648ee38d3628282324
                it runs fine. But i have tried to move a small piece of code to a class and then i crash all the time. no idea what is wrong.
                To see the bug happen, replace False by True in this line 294

                    testBug = False # set True to show the bug
                

                with False i directly execute the code, with True i use the piece embedded in the SketchView class.
                the problem seems to appear when i ask the SketchView instance to remember an image: line 230

                self.sImage = pil_image
                

                can anyone help me?
                thanks

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

                  @jmv38, if Pythonista crashes, google for ”dgelessus faulthandler” to get the ObjC exception. If it is not a Pythonista crash, what is the trace?

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

                    it is a pythonista crash

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

                      note that the images stored are very small (25x25) and only 3 SketchView objects are using them. So it cannot be memory overflow.
                      I am probably doing something very wrong somewhere, but what?
                      What is puzzling is that the very same code, executed 200 times works fine. I try to execute it only 3 times, and re-use the result, but then it does not work...
                      Note that it works the 1rst time. This code never crashes

                        def run(self):
                          global X, y, pts, NN
                          n = len(self.vars)
                          count = self.count
                          if count<n:
                            if count == 3: exit()
                      

                      the crash occurs ramdomly during one of the next calls. Not always the same. I must be writing in the memory at a wrong place.

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

                        Crash, with faulthandler, gives an empty faultlog-temp.txt...strange

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

                          @jmv38 Not sure if that helps but no crash with

                            def getImg(self):
                              if self.sImage == None:
                                pil_image = ui2pil(snapshot(self.subviews[0]))
                                _,_,_,pil_image = pil_image.split()
                                pil_image = pil_image.resize((100, 100),PILImage.BILINEAR)
                                pil_image = pil_image.resize((50, 50),PILImage.BILINEAR)
                                pil_image = pil_image.resize((25, 25),PILImage.BILINEAR)
                                return pil_image.copy() <-------------------
                                self.sImage = pil_image
                              return self.sImage.copy()
                          
                          jmv38 1 Reply Last reply Reply Quote 0
                          • jmv38
                            jmv38 @cvp last edited by jmv38

                            @cvp thank you, i feel less alone...
                            your last proposal is not a solution to the problem: the sImage is never updated, so it is recomputed at each cycle, that is what want to avoid.
                            I just tried some more changes (slow down, predefine self.sImage), but nothing works.
                            Must be something stupid (a bad local name, messing with a global?). Or are the some memory bugs in pythonista?
                            I think i must be degrading self.sImage, but how? i return a copy, not the image itself, and i dont modify sketch[] during learning...

                            cvp 2 Replies Last reply Reply Quote 0
                            • cvp
                              cvp @jmv38 last edited by cvp

                              @jmv38 this shows, on my iPad mini 4, that crash arrives after preparing 71/243

                                  if testBug:
                                    pil_image = v.getImg()
                                    time.sleep(0.05)
                              

                              Preparing 74/243... .....always 74 even with time.sleep(0.5)

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

                                @jmv38 Not sure if this modification does destroy the algorithm

                                1. in updateLearninImage
                                  BWlearningSetImage = temp#.convert('RGB')
                                
                                1. in showTraining
                                    global BWlearningSetImage
                                    BWlearningSetImage = BWlearningSetImage.convert('RGB')
                                
                                jmv38 3 Replies Last reply Reply Quote 0
                                • jmv38
                                  jmv38 @cvp last edited by

                                  @cvp does it solve the bug?

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

                                    @cvp no crash, you are right!
                                    Incredible that you found that.
                                    Any insight of what is going on there?

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

                                      @cvp thank you so much for solving my problem!
                                      I wish i understood what was wrong in my code, though...

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

                                        @jmv38 I'm just happy to have been able to help.
                                        Sincerely, I don't understand all your code but I've tried to follow it, step by step by skipping some process until I found this "solution". I agree that it does not explain the problem

                                        Doing the conversion at end is less work, I think, because not converted at each iteration.
                                        Perhaps, a problem of cpu consumption

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

                                          v12 https://gist.github.com/8fa3ac1516ef159284f3090ba9494390
                                          big pef improvement with prior normalization of image size and position

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

                                            Huge update! Now you can inspect the states and weights of the internal layers and get a feeling of how the network decides!
                                            https://gist.github.com/ef4439a8ca76d54a724a297680f98ede

                                            Also I added a copyright because this is a lot of work. @mkeywood if you are uncomfortable with this let me know.

                                            Here is a video showing the code in action
                                            https://youtu.be/yBR80KwYtcE

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