Exemple #1
0
 def batchloop():
     c = 0
     prevperc = -1.
     terr = [0.0]
     numdigs = 2
     tt = TT("iter progress", verbose=verbose)
     tt.tick()
     while datafeeder.hasnextbatch():
         perc = round(c*100.*(10**numdigs)/datafeeder._numbats)/(10**numdigs)
         if perc > prevperc:
             s = ("%."+str(numdigs)+"f%% \t error: %.3f") % (perc, terr[0])
             tt.live(s)
             prevperc = perc
         sampleinps = datafeeder.nextbatch()
         try:
             eterr = trainf(*sampleinps)
             if len(terr) != len(eterr) and terr.count(0.0) == len(terr):
                 terr = [0.0]*len(eterr)
         except Exception, e:
             raise e
         if self.average_err is True:
             terr = [xterr*(1.0*(c)/(c+1)) + xeterr*(1.0/(c + 1)) for xterr, xeterr in zip(terr, eterr)]
         else:
             terr = [xterr + xeterr for xterr, xeterr in zip(terr, eterr)]
         c += 1
Exemple #2
0
 def batchloop():
     c = 0
     prevperc = -1.
     terr = [0.0]
     numdigs = 2
     tt = TT("iter progress", verbose=verbose)
     tt.tick()
     while datafeeder.hasnextbatch():
         perc = round(c * 100. * (10**numdigs) /
                      datafeeder._numbats) / (10**numdigs)
         if perc > prevperc:
             s = ("%." + str(numdigs) +
                  "f%% \t error: %.3f") % (perc, terr[0])
             tt.live(s)
             prevperc = perc
         sampleinps = datafeeder.nextbatch()
         sampleinps = sampletransf(*sampleinps)
         try:
             eterr = trainf(*sampleinps)
             if len(terr) != len(eterr) and terr.count(0.0) == len(
                     terr):
                 terr = [0.0] * len(eterr)
         except Exception, e:
             raise e
         if self.average_err is True:
             terr = [
                 xterr * (1.0 * (c) / (c + 1)) + xeterr *
                 (1.0 / (c + 1)) for xterr, xeterr in zip(terr, eterr)
             ]
         else:
             terr = [
                 xterr + xeterr for xterr, xeterr in zip(terr, eterr)
             ]
         c += 1
Exemple #3
0
 def batchloop():
     c = 0
     prevperc = -1.
     terrs = [[0.0] if tf is not None else None for tf in trainfs]
     numdigs = 2
     tt = TT("iter progress", verbose=verbose)
     tt.tick()
     for dataf in datafeeders:
         if dataf is not None:
             dataf.reset()
     while datafeeders[0].hasnextbatch():
         perc = round(c * 100. * (10**numdigs) /
                      datafeeders[0].getnumbats()) / (10**numdigs)
         if perc > prevperc:
             s = ("%." + str(numdigs) + "f%% \t error: %s") \
                 % (perc, " - ".join(map(lambda x: "%.3f" % x[0], terrs)))
             tt.live(s)
             prevperc = perc
         for df in datafeeders:
             if not df.hasnextbatch():
                 df.reset()
         sampleinps = [df.nextbatch() for df in datafeeders]
         # embed()
         sampleinps = [
             stf(*si, phase=phase)
             for (stf, si) in zip(sampletransfs, sampleinps)
         ]
         try:
             eterrs = [tf(*si) for (tf, si) in zip(trainfs, sampleinps)]
             for i in range(len(terrs)):
                 if len(terrs[i]) != len(
                         eterrs[i]) and terrs[i].count(0.0) == len(
                             terrs[i]):
                     terrs[i] = [0.0] * len(eterrs[i])
         except Exception, e:
             raise e
         for i, subt in enumerate(this.spts):
             if subt.original.average_err is True:
                 terrs[i] = [
                     xterr * (1.0 * (c) / (c + 1)) + xeterr * (1.0 /
                                                               (c + 1))
                     for xterr, xeterr in zip(terrs[i], eterrs[i])
                 ]
             else:
                 terrs[i] = [
                     xterr + xeterr
                     for xterr, xeterr in zip(terrs[i], eterrs[i])
                 ]
         c += 1
Exemple #4
0
 def batchloop():
     c = 0
     numex = 0
     prevperc = -1.
     terr = [0.0]
     numdigs = 2
     tt = TT("iter progress", verbose=verbose)
     tt.tick()
     while datafeeder.hasnextbatch():
         perc = round(c * 100. * (10**numdigs) /
                      datafeeder._numbats) / (10**numdigs)
         if perc > prevperc:
             terr0 = terr[0] * 1.0 / numex if numex > 0 else 0.0
             s = ("%." + str(numdigs) + "f%% \t error: %.3f") % (perc,
                                                                 terr0)
             tt.live(s)
             prevperc = perc
         sampleinps, batsize = datafeeder.nextbatch(withbatchsize=True)
         numex += batsize
         sampleinps = sampletransf(*sampleinps)
         eterr = trainf(*sampleinps)
         if len(terr) != len(eterr) and terr.count(0.0) == len(terr):
             terr = [0.0] * len(
                 eterr
             )  # ensure compatible size of terr (number of output scores)
         if self.average_err is True:
             terr = [
                 xterr + xeterr * batsize
                 for xterr, xeterr in zip(terr, eterr)
             ]
         else:
             terr = [
                 xterr + xeterr for xterr, xeterr in zip(terr, eterr)
             ]
         c += 1
     tt.stoplive()
     if self.average_err is True:
         terr = [xterr * 1.0 / numex for xterr in terr]
     return terr
Exemple #5
0
 def batchloop():
     c = 0
     numex = 0
     prevperc = -1.
     terr = [0.0]
     numdigs = 2
     tt = TT("iter progress", verbose=verbose)
     tt.tick()
     datafeeder.reset()
     while datafeeder.hasnextbatch():
         perc = round(c * 100. * (10**numdigs) /
                      datafeeder.getnumbats()) / (10**numdigs)
         if perc > prevperc:
             terr0 = terr[0] * 1.0 / numex if numex > 0 else 0.0
             s = ("%." + str(numdigs) + "f%% \t error: %.3f") % (perc,
                                                                 terr0)
             tt.live(s)
             prevperc = perc
         sampleinps, batsize = datafeeder.nextbatch(withbatchsize=True)
         numex += batsize
         #embed()
         sampleinps = sampletransf(*sampleinps, phase=phase)
         try:
             eterr = trainf(*sampleinps)
             if len(terr) != len(eterr) and terr.count(0.0) == len(
                     terr):
                 terr = [0.0] * len(eterr)
         except Exception, e:
             raise e
         if self.average_err is True:
             terr = [
                 xterr + xeterr * batsize
                 for xterr, xeterr in zip(terr, eterr)
             ]
         else:
             terr = [
                 xterr + xeterr for xterr, xeterr in zip(terr, eterr)
             ]
         c += 1