something wrong in wx

Robert Tomasik at 2kop.mil.pl
Fri Nov 11 08:54:24 EST 2005


something wrong in wx

I wrote program training na Artificial Neural Network. It work well in
console mode, but when I try to add GUI there is an error:
FANN Error 10: Error reading info from train data file "zapis.txt", line: 2

There is a code:
##### this work ############
#!/usr/bin/python
import fann

connection_rate = 1
learning_rate = 0.7
num_layers = 3
num_input = 319
num_neurons_hidden = 50
num_output = 5


ann = fann.fann_create(connection_rate, learning_rate, num_layers,num_input,
num_neurons_hidden, num_output)

desired_error = 0.00001
max_iterations = 500000
iterations_between_reports = 1000

fann.fann_train_on_file(ann, "zapis.txt", max_iterations,
iterations_between_reports, desired_error)
print fann.fann_get_MSE(ann)
fann.fann_save(ann, "po_nauce.net")

fann.fann_destroy(ann)

######### with GUI (not work) #########
#!/usr/bin/python

import wx
import fann

class TestFrame(wx.Frame):
        def __init__(self):
                wx.Frame.__init__(self, None, -1, "Trenowanie sieci", pos=(50, 50))
                panel = wx.Panel(self)

                # First create the controls
                topLbl = wx.StaticText(panel, -1, "Trenowanie sieci", size=wx.Size(400,                 
21), style=wx.ALIGN_CENTRE)
                topLbl.Center(wx.HORIZONTAL)
                topLbl.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))


                polaczenia_Lbl = wx.StaticText(panel, -1, u'Stopie\u0144        
po\u0142\u0105cze\u0144 [%]:')
                self.polaczenia = wx.SpinCtrl(panel, -1, "")
                self.polaczenia.SetRange(0,100)
                self.polaczenia.SetValue(100)

                ilosc_warstw_Lbl = wx.StaticText(panel, -1, u'Ilo\u015b\u0107 warstw:')
                self.ilosc_warstw = wx.SpinCtrl(panel, -1, "")
                self.ilosc_warstw.SetRange(0,5)
                self.ilosc_warstw.SetValue(3)

                cstLbl1 = wx.StaticText(panel, -1, '\n'
                u'Poszczeg\xf3lne warstwy sieci: ')
                cstLbl = wx.StaticText(panel, -1, '\n'
                u'wej\u015biowa ukryta wyj\u015biowa')
        
                self.ilosc_wejsc = wx.SpinCtrl(panel, -1, "")
                self.ilosc_wejsc.SetRange(0,2000)
                self.ilosc_wejsc.SetValue(319)
                self.ukryte = wx.SpinCtrl(panel, -1, "")
                self.ukryte.SetRange(0,500)
                self.ukryte.SetValue(50)
                self.ilosc_wyjsc = wx.SpinCtrl(panel, -1, "")
                self.ilosc_wyjsc.SetRange(0,100)
                self.ilosc_wyjsc.SetValue(5)

                uczenie_Lbl = wx.StaticText(panel, -1, u'Cz\u0119sto\u015b\u0107 uczenia
[%]:')
                self.uczenie = wx.SpinCtrl(panel, -1, "")
                self.uczenie.SetRange(0,100)
                self.uczenie.SetValue(70)
                
                oczekiwany_blad_Lbl = wx.StaticText(panel, -1, u'Oczekiwany
b\u0142\u0105d: [1/x]')
                self.oczekiwany_blad = wx.SpinCtrl(panel, -1, "")
                self.oczekiwany_blad.SetRange(0,100000000)
                self.oczekiwany_blad.SetValue(100000)
                
                powtorzen_Lbl = wx.StaticText(panel, -1, u'Maxymalna liczba     
powt\xf3rze\u0144:')
                self.powtorzen = wx.SpinCtrl(panel, -1, "")
                self.powtorzen.SetRange(0,100000)
                self.powtorzen.SetValue(50000)

                raporty_Lbl = wx.StaticText(panel, -1, u'raport co:')
                self.raporty = wx.SpinCtrl(panel, -1, "")
                self.raporty.SetRange(0,10000)
                self.raporty.SetValue(1000)


                trenujBtn = wx.Button(panel, -1, "Trenuj Siec")
                self.Bind(wx.EVT_BUTTON, self.on_trenujBtn, trenujBtn)
                cancelBtn = wx.Button(panel, -1, "Cancel")


# Now do the layout.

                # mainSizer is the top-level one that manages everything
                mainSizer = wx.BoxSizer(wx.VERTICAL)
                mainSizer.Add(topLbl, 0, wx.ALL, 5)
                ainSizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)

                # addrSizer is a grid that holds all of the address info
                addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
                addrSizer.AddGrowableCol(1)
                addrSizer.Add(polaczenia_Lbl, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.polaczenia, 0, wx.EXPAND)
                addrSizer.Add(ilosc_warstw_Lbl, 0, wx.ALIGN_RIGHT|      
wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.ilosc_warstw, 0, wx.EXPAND)
                #addrSizer.Add((10,10)) # some empty space
                #addrSizer.Add(addr2, 0, wx.EXPAND)

                addrSizer.Add(cstLbl1, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(cstLbl, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add((10,10)) # some empty space

# the city, state, zip fields are in a sub-sizer
                cstSizer = wx.BoxSizer(wx.HORIZONTAL)
                cstSizer.Add(self.ilosc_wejsc, 1)
                cstSizer.Add(self.ukryte, 0, wx.LEFT|wx.RIGHT, 5)
                cstSizer.Add(self.ilosc_wyjsc)
                addrSizer.Add(cstSizer, 0, wx.EXPAND)

                addrSizer.Add(uczenie_Lbl, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.uczenie, 0, wx.EXPAND)
                addrSizer.Add(oczekiwany_blad_Lbl, 0, wx.ALIGN_RIGHT|   
wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.oczekiwany_blad, 0, wx.EXPAND)
                addrSizer.Add(powtorzen_Lbl, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.powtorzen, 0, wx.EXPAND)
                addrSizer.Add(raporty_Lbl, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
                addrSizer.Add(self.raporty, 0, wx.EXPAND)

# now add the addrSizer to the mainSizer
                mainSizer.Add(addrSizer, 0, wx.EXPAND|wx.ALL, 10)

# The buttons sizer will put them in a row with resizeable
# gaps between and on either side of the buttons
                btnSizer = wx.BoxSizer(wx.HORIZONTAL)
                btnSizer.Add((20,20), 1)
                btnSizer.Add(trenujBtn)
                btnSizer.Add((20,20), 1)
                btnSizer.Add(cancelBtn)
                btnSizer.Add((20,20), 1)

                mainSizer.Add(btnSizer, 0, wx.EXPAND|wx.BOTTOM, 10)


# Finally, tell the panel to use the sizer for layout
                panel.SetSizer(mainSizer)

# Fit the frame to the needs of the sizer. The frame will
# automatically resize the panel as needed. Also prevent the
# frame from getting smaller than this size.
                mainSizer.Fit(self)
                self.SetSizeHints(*self.GetSize())


        def on_trenujBtn(self, event):

                connection_rate = float(self.polaczenia.GetValue()*0.01)
                learning_rate = float(self.uczenie.GetValue()*0.01)
                num_layers = int(self.ilosc_warstw.GetValue())
                num_input = int(self.ilosc_wejsc.GetValue())
                num_neurons_hidden = int(self.ukryte.GetValue())
                num_output = int(self.ilosc_wyjsc.GetValue())

                ann = fann.fann_create(connection_rate, learning_rate, num_layers,      
num_input, num_neurons_hidden, num_output)

                max_iterations = int(self.powtorzen.GetValue())
                iterations_between_reports = int(self.raporty.GetValue())
                desired_error = 0.00001 #float(1/(self.oczekiwany_blad.GetValue()))
                print desired_error
                fann.fann_train_on_file(ann, "zapis.txt", max_iterations,
iterations_between_reports, desired_error)
                fann.fann_save(ann, "po_nauce.net")

                fann.fann_destroy(ann)

app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()


#######################################################
Thanks for any help.

Robert



More information about the Python-list mailing list