something wrong in wx

R

Robert

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
 
T

Tim Roberts

Robert said:
something wrong in wx

I doubt it.
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

How are you launching the GUI version? Are you double-clicking on an icon
somewhere? Are you sure the application is starting in the correct
directory -- the one that contains zapis.txt?

Perhaps you should try hard-code the full path, or at least doing an
os.chdir().
 
R

Robert Tomasik

Dnia Sun, 13 Nov 2005 08:29:49 +0000, Tim Roberts napisa³(a):
How are you launching the GUI version? Are you double-clicking on an icon
somewhere?

I launch the Gui version with terminal.
# python Training.py

Are you sure the application is starting in the correct
directory -- the one that contains zapis.txt?

Yes i'm sure.
Perhaps you should try hard-code the full path, or at least doing an
os.chdir().
it still doesn't work.

Thanks.
 
J

jay.dow

Don't know if this will help or not because it seems like a strange
error if this is the problem. I've always had to run my wxPython apps
with pythonw, otherwise it will give you an error saying it needs the
GUI interpreter or something like that. However, this could be an
operating system specific codition. If that doesn't fix anything all I
can say is check and recheck your path.
 
M

malv

Sorry to be of no help and to raise another question.
How did you manage to get fann going under python?
I can install fann 1.2.0 allright but something doesn't go with the
python setup.
(I run Python 2.4.1 under linux 2.6.13)
When trying to run a small example in python I always get error
messages about missing definitions in _libfann.
I have read about supposed disultils problems and workarounds, but I
didn't manage yet.
Thank you for any suggestion,
malv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top