omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. jmv38

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 17
    • Posts 201
    • Best 14
    • Controversial 0
    • Groups 0

    jmv38

    @jmv38

    17
    Reputation
    2430
    Profile views
    201
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    jmv38 Unfollow Follow

    Best posts made by jmv38

    • RE: Machine Learning

      @JonB hello.
      the bottom plot shows:

      during training: the training set and the color of each element corresponds to the recongnition result of this element.

      during guessing (what you can se above):
      the states of input layer0, then weights 0>1, then states of layer1, then weights 1>2, then states of layer2, then weights 2>3, then states of layer2, then output layer3 = 3 neurons.

      First i display the weights in black and white (white=positive, black=negative), then i display in color and in sequence the signal propagation through the network:

      • the neuron states: green means active (1) and red means inactive (0).
      • neurons x weights values: Green means positive influence on the neuron (excitation) and red negative influence (damping). The brighter the stronger. I.ll call this wxn for weights x neuron.

      The colors of the 3 neurons of layer 3 (red,red,green) are the same under the sketches: they correspond to the same data.
      the group of 3 blocs on the left of these neurons (weights2>3) are the input weights of each neuron x the input of previous layer.

      Let’s analyse this picture

      Here you can see that a single wxn is mainly responsible for the 3 neuron states: its the weight (1/2, 0/2) ((0,0) is top left of each bloc), excited by neuron (1/2, 0/2) (green). Other neurons are desactivated (red) so the wxn are insignificant (black). This neuron is damping the 2 first neurons (red wxn) and exciting the last one (green wxn).

      Now let’s see why neuron (1/2, 0/2) of layer2 is excited. Look in wxn1>2 at the bloc (1/2, 0/2). Several wxn are green, they are responsible for the response. There is no opposite response (red).

      Let’s look at the stonger response wxn (2/4,3/4). The previous layer neuron corresponding is green too (active). look at the corresponding wxn0>1: you can see the the top left part of the ‘o’ drawing is green = detected.

      so we can say the ‘o’ has been detected because of its top left part, which is not present in the 2 other drawings. That makes sense.
      And the 2 other choices have been rejected for the same reason (it might not be the case).

      I hope this explaination is what you were expecting.

      posted in Pythonista
      jmv38
      jmv38
    • RE: Machine Learning

      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

      posted in Pythonista
      jmv38
      jmv38
    • RE: How can I convert a PIL Image to a ui.Image?

      here are the various conversions i have set. Tell me if there is some better code. Thanks.
      [edit] modified according to @ccc comment below.
      [edit] modified to add functions and tests.

      
      #coding: utf-8
      import ui
      import io
      from PIL import ImageOps, ImageDraw
      from PIL import Image 
      import numpy as np
      import StringIO
      
      import console
      
      # numpy <=> pil
      def np2pil(arrayIn):
      		imgOut = Image.fromarray(arrayIn)
      		return imgOut
      	
      def pil2np(imgIn,arrayOut=None):
      	if arrayOut == None:
      		arrayOut = np.array(imgIn)
      		return arrayOut
      	else:
      		arrayOut[:] = np.array(imgIn)
      		return None
      
      
      # pil <=> ui
      def pil2ui(imgIn):
      	with io.BytesIO() as bIO:
      		imgIn.save(bIO, 'PNG')
      		imgOut = ui.Image.from_data(bIO.getvalue())
      	del bIO
      	return imgOut
      
      def ui2pil(imgIn):
      	# create a fake png file in memory
      	memoryFile = StringIO.StringIO( imgIn.to_png() )
      	# this creates the pil image, but does not read the data
      	imgOut = Image.open(memoryFile)
      	# this force the data to be read
      	imgOut.load()
      	# this releases the memory from the png file
      	memoryFile.close()
      	return imgOut
      
      # numpy <=> ui
      def np2ui(arrayIn):
      	# this is a lazy implementation, maybe could be more efficient?
      	return pil2ui( np2pil(arrayIn) )
      	
      def ui2np(imgIn):
      	# this is a lazy implementation, maybe could be more efficient?
      	return pil2np( ui2pil(imgIn) )
      
      
      if __name__ == "__main__":
      	# testing the functions above
      	
      	img = Image.open('Test_Lenna')
      	s = 256
      	img = img.resize((s, s), Image.BILINEAR)
      	img = ImageOps.grayscale(img)
      	
      	console.clear()
      	
      	print( 'test: open a pil image:')
      	img.show()
      	
      	print('- ')
      	print( 'test: pil image => return a new np array')
      	print(' ')
      	arr = pil2np(img)
      	print(arr)
      	
      	print('- ')
      	print( 'test: pil image => write into existing np array')
      	print(' ')
      	pil2np(img.rotate(90), arr)
      	print(arr)
      	
      	print('- ')
      	print( 'test:  np array => return a new pil image')
      	img1 = np2pil(arr)
      	img1.show()
      	
      	# test: pil2ui verification is done via a popover
      	iv = ui.ImageView(frame=(0,0,256,256))
      	iv.name = 'pil2ui'
      	iv.image = pil2ui(img)
      	iv.present('popover', popover_location=(600,100))
      	
      	print('- ')
      	print( 'test:  ui image => return a new pil image (rotated by -90° to prove pil type)')
      	img2 = ui2pil(iv.image).rotate(-90)
      	print( type(img2))
      	img2.show()
      	
      	# test: np2ui verification is done via a popover
      	iv2 = ui.ImageView(frame=(0,0,256,256))
      	iv2.name = 'np2ui'
      	iv2.image = np2ui(arr)
      	iv2.present('popover', popover_location=(300,100))
      	
      	print('- ')
      	print( 'test:  ui image => return a new np array')
      	arr2 = ui2np(iv2.image)
      	print( arr2)
      
      
      posted in Pythonista
      jmv38
      jmv38
    • RE: New Beta for Pythonista 3.3

      @omz welcome back sir. Thank you for the update.

      posted in Pythonista
      jmv38
      jmv38
    • RE: For those that would like to write code on your iPad, look into Pythonista. It's Amazing!

      Sounds amazing! But what langage does it use for coding?

      posted in Pythonista
      jmv38
      jmv38
    • RE: Machine Learning

      @Matteo for your request 2/: it already works. Dont press reset, just start another drawing in one of the boxes and it will replace the previous one. Then tap train.

      posted in Pythonista
      jmv38
      jmv38
    • RE: Machine Learning

      screenshot

      posted in Pythonista
      jmv38
      jmv38
    • RE: Machine Learning

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

      posted in Pythonista
      jmv38
      jmv38
    • RE: how to update ui.Label display during computation?

      hello
      i managed to get it: I launched my function and my loop steps with a ui.delay() call. So my ui.button actions can return and the ui.label can be updated (i followed JonB directions). And then it works.
      I will post the code in the neural networks thread.
      here is the idea:

      def trainAll(self, iterations= None):
          if iterations:
            self.iterations = iterations
            self.lossArray = []
          loss = np.mean(np.square(y - NN.forward(X)))
          if self.iterations > 0:
            self.lossArray.append(loss)
            self.train(X, y)
            showLearning(len(self.lossArray),loss)
            self.iterations-=1
            ui.delay(self.trainAll, 0.1)
      
      posted in Pythonista
      jmv38
      jmv38
    • RE: scene updating every second

      here is another video, technically more useful
      https://youtu.be/6Qi0UBBXZVw

      posted in Pythonista
      jmv38
      jmv38

    Latest posts made by jmv38

    • RE: OS testing

      try in the console:

      import os
      help(os)

      you’ll get instructions

      posted in Pythonista
      jmv38
      jmv38
    • RE: full_screen not working?

      @cvp you are the BEST
      😍😍😍

      posted in Pythonista
      jmv38
      jmv38
    • full_screen not working?

      Hello
      one of my useful code to display photos now presents in popover and not fullscreen any longer...
      Any advice?
      Thanks.

      posted in Pythonista
      jmv38
      jmv38
    • RE: Python script to back up Photos to SD card or HDD

      @cvp what camera do you use? Just curious.

      posted in Pythonista
      jmv38
      jmv38
    • RE: New Beta for Pythonista 3.3

      @omz welcome back sir. Thank you for the update.

      posted in Pythonista
      jmv38
      jmv38
    • RE: AssetCollection.remove_assets()

      yes, it was a bug from me, the function works fine
      thanks

      posted in Pythonista
      jmv38
      jmv38
    • RE: AssetCollection.remove_assets()

      wait, maybe my bad .. i’ll check again and report.
      thanks.

      posted in Pythonista
      jmv38
      jmv38
    • AssetCollection.remove_assets()

      AssetCollection.remove_assets() seems to work only with the albums created during the same run. If I use it in a later run, nothing happens, although AssetCollection.can_remove_assets is True, and no error is raised.
      Any idea on how to have this work? I am making a fast album editor, and this kind of ruins my project... 😢
      Thanks!

      posted in Pythonista
      jmv38
      jmv38
    • RE: For those that would like to write code on your iPad, look into Pythonista. It's Amazing!

      Sounds amazing! But what langage does it use for coding?

      posted in Pythonista
      jmv38
      jmv38
    • RE: Containers for photos, with scroll, drag&drop between them

      @cvp you are correct. My pb was pbly sthg else.

      posted in Pythonista
      jmv38
      jmv38