예제 #1
0
    def run_epoch(self, session):
        """
        - DOES: runs one epoch, i.e., for each batch it: computes the batch loss
        (forwardprop), computes all gradients w.r.t to the batch loss and updates
        all network variables/parameters accordingly (backprop).
        """

        batch_losses = []
        for step, (captions, imgs,
                   labels) in enumerate(train_data_iterator(self)):
            # create a feed_dict with the batch data:
            feed_dict = self.create_feed_dict(captions,
                                              imgs,
                                              labels_batch=labels,
                                              dropout=self.config.dropout)
            # compute the batch loss and compute & apply all gradients w.r.t to
            # the batch loss (without self.train_op in the call, the network
            # would not train, we would only compute the batch loss):
            batch_loss, _ = session.run([self.loss, self.train_op],
                                        feed_dict=feed_dict)
            batch_losses.append(batch_loss)

            if step % 100 == 0:
                print "batch: %d | loss: %f" % (step, batch_loss)
                log("batch: %d | loss: %f" % (step, batch_loss))

            if step > 5 and self.debug:
                break

        # return a list containing the batch loss for each batch:
        return batch_losses
예제 #2
0
 def run_epoch(self, session):
     batch_losses = []
     for step, (data_batch, labels_batch,
                sequence_length) in enumerate(ut.train_data_iterator(self)):
         feed_dict = self.create_feed_dict(data_batch, labels_batch,
                                           self.config.dropout,
                                           sequence_length)
         batch_loss, _ = session.run([self.loss, self.train_op],
                                     feed_dict=feed_dict)
         batch_losses.append(batch_loss)
     return batch_losses