def _train_one_epoch(self, train_gen):
    'Performs one training epoch.'
    interpreter = tf.lite.Interpreter(model_content=self.train_head_model)
    interpreter.allocate_tensors()
    (x_in, y_in) = interpreter.get_input_details()[:2]
    variable_ins = interpreter.get_input_details()[2:]
    loss_out = interpreter.get_output_details()[0]
    gradient_outs = interpreter.get_output_details()[1:]
    epoch_loss = 0.0
    num_processed = 0
    for (bottlenecks, truth) in train_gen:
        batch_size = bottlenecks.shape[0]
        if (batch_size < BATCH_SIZE):
            bottlenecks = pad_batch(bottlenecks, BATCH_SIZE)
            truth = pad_batch(truth, BATCH_SIZE)
        interpreter.set_tensor(x_in['index'], bottlenecks)
        interpreter.set_tensor(y_in['index'], truth)
        for (variable_in, variable_value) in zip(variable_ins, self.variables):
            interpreter.set_tensor(variable_in['index'], variable_value)
        interpreter.invoke()
        loss = interpreter.get_tensor(loss_out['index'])
        gradients = [interpreter.get_tensor(gradient_out['index']) for gradient_out in gradient_outs]
        self._apply_gradients(gradients)
        epoch_loss += (loss * batch_size)
        num_processed += batch_size
    epoch_loss /= num_processed
    return epoch_loss
Performs one training epoch.
def _train_one_epoch(self, train_gen):
    
    interpreter = tf.lite.Interpreter(model_content=self.train_head_model)
    interpreter.allocate_tensors()
    (x_in, y_in) = interpreter.get_input_details()[:2]
    variable_ins = interpreter.get_input_details()[2:]
    loss_out = interpreter.get_output_details()[0]
    gradient_outs = interpreter.get_output_details()[1:]
    epoch_loss = 0.0
    num_processed = 0
    for (bottlenecks, truth) in train_gen:
        batch_size = bottlenecks.shape[0]
        if (batch_size < BATCH_SIZE):
            bottlenecks = pad_batch(bottlenecks, BATCH_SIZE)
            truth = pad_batch(truth, BATCH_SIZE)
        interpreter.set_tensor(x_in['index'], bottlenecks)
        interpreter.set_tensor(y_in['index'], truth)
        for (variable_in, variable_value) in zip(variable_ins, self.variables):
            interpreter.set_tensor(variable_in['index'], variable_value)
        interpreter.invoke()
        loss = interpreter.get_tensor(loss_out['index'])
        gradients = [interpreter.get_tensor(gradient_out['index']) for gradient_out in gradient_outs]
        self._apply_gradients(gradients)
        epoch_loss += (loss * batch_size)
        num_processed += batch_size
    epoch_loss /= num_processed
    return epoch_loss