Example #1
0
 def fit(self, trX, trY, n_iter=1):
     out_shape = self.model[-1].out_shape
     n = 0.
     t = time()
     costs = []
     for e in range(n_iter):
         epoch_costs = []
         for xmb, ymb in self.iterator.iterXY(trX, trY):
             c = self._train(xmb, ymb)
             epoch_costs.append(c)
             n += len(ymb)
             if self.verbose >= 2:
                 n_per_sec = n / (time() - t)
                 n_left = len(trY) * n_iter - n
                 time_left = n_left / n_per_sec
                 sys.stdout.write(
                     "\rIter %d Seen %d samples Avg cost %0.4f Examples per second %d Time left %d seconds"
                     % (e, n, np.mean(
                         epoch_costs[-250:]), n_per_sec, time_left))
                 sys.stdout.flush()
         costs.extend(epoch_costs)
         n_per_sec = n / (time() - t)
         n_left = len(trY) * n_iter - n
         time_left = n_left / n_per_sec
         status = "Iter %d Seen %d samples Avg cost %0.4f Examples per second %d Time elapsed %d seconds" % (
             e, n, np.mean(epoch_costs[-250:]), n_per_sec, time() - t)
         if self.verbose >= 2:
             sys.stdout.write("\r" + status)
             sys.stdout.flush()
             sys.stdout.write("\n")
         elif self.verbose == 1:
             print(status)
     return costs
Example #2
0
 def fit(self, trX, trY, n_iter=1):
     out_shape = self.model[-1].out_shape
     n = 0.
     t = time()
     costs = []
     for e in range(n_iter):
         epoch_costs = []
         for xmb, ymb in self.iterator.iterXY(trX, trY):
             c = self._train(xmb, ymb)
             epoch_costs.append(c)
             n += len(ymb)
             if self.verbose >= 2:
                 n_per_sec = n / (time() - t)
                 n_left = len(trY)*n_iter - n
                 time_left = n_left/n_per_sec
                 sys.stdout.write("\rIter %d Seen %d samples Avg cost %0.4f Examples per second %d Time left %d seconds" % (e, n, np.mean(epoch_costs[-250:]), n_per_sec, time_left))
                 sys.stdout.flush()
         costs.extend(epoch_costs)
         n_per_sec = n / (time() - t)
         n_left = len(trY)*n_iter - n
         time_left = n_left/n_per_sec
         status = "Iter %d Seen %d samples Avg cost %0.4f Examples per second %d Time elapsed %d seconds" % (e, n, np.mean(epoch_costs[-250:]), n_per_sec, time() - t)
         if self.verbose >= 2:
             sys.stdout.write("\r"+status) 
             sys.stdout.flush()
             sys.stdout.write("\n")
         elif self.verbose == 1:
             print(status)
     return costs