Esempio n. 1
0
def example_numerical_flow():
    def numerical_flow(flow, x, out):
        out += flow.is_even(x.features)
        out += flow.predict_positive(x.features) | out.is_even
        out += flow.multiple_three(x.features) | out.predict_positive
        return out

    def full_flow(flow, x, out):
        out += flow.is_interesting(x.features)
        out += flow.numerical_flow(x.features) | out.is_interesting
        return out

    tensor = torch.arange(8).unsqueeze(dim=-1)
    inputs = Values(keys=['inp'], values=[tensor], types=['int'])

    is_even_task = BinaryHardcodedTask(name='is_even', labels=(tensor % 2) == 0)
    predict_positive = BinaryHardcodedTask(name='predict_positive', labels=(tensor > 0.))
    multiple_three = BinaryHardcodedTask(name='multiple_three', labels=(tensor % 3) == 0)
    is_interesting_task = BinaryHardcodedTask(name='is_interesting', labels=torch.tensor(
        [True, True, False, False, False, True, True, True]))

    tasks = [is_even_task, predict_positive, multiple_three]

    numerical_flow_task = TaskFlow(name='numerical_flow', tasks=tasks, inputs=inputs, flow_func=numerical_flow)
    full_task_flow = TaskFlow(name='full_flow', tasks=[is_interesting_task, numerical_flow_task], inputs=inputs, flow_func=full_flow)
    return full_task_flow
Esempio n. 2
0
    def __init__(self, flow: TaskFlow, tensorboard_converters: Optional[TensorboardConverters] = None):
        super().__init__(CallbackOrder.Metric)
        self.flow = flow

        self.overall_loss = flow.get_per_sample_loss()
        self.leaf_losses = self.overall_loss.get_leaf_losses_per_sample()
        self.interpretations = {}
        self.loader_counts = {}

        self.tensorboard_converters = tensorboard_converters
Esempio n. 3
0
 def create_flow(self, flow_func, flow_name=None):
     flow_name = flow_func.__name__ if flow_name is None else flow_name
     used_tasks_tracer = UsedTasksTracer()
     flow_func(used_tasks_tracer, UsedTasksTracer(), UsedTasksTracer())
     used_tasks = []
     for used_task_name in used_tasks_tracer.used_tasks:
         task = self._name_to_task.get(used_task_name, None)
         if task is not None:
             used_tasks.append(task)
     return TaskFlow(flow_name, used_tasks, flow_func, self.inputs)
Esempio n. 4
0
    def __init__(
        self,
        flow: TaskFlow,
        tensorboard_converters: Optional[TensorboardConverters] = None,
        loaders_to_skip=()):
        """
        :param flow: The task flow, which holds the per sample loss functions for every task.

        :param tensorboard_converters: A :class:`TensorboardConverters` object which is responsible for the Tensorboard
        logging settings.

        :param loaders_to_skip: Optional loaders to be skipped, for example because labels aren't available for them.
        """
        super().__init__(CallbackOrder.Metric)
        self.flow = flow
        self.loaders_to_skip = loaders_to_skip

        self.overall_loss = flow.get_per_sample_loss()
        self.leaf_losses = self.overall_loss.get_leaf_losses_per_sample()
        self.interpretations = {}
        self.loader_counts = {}

        self.tensorboard_converters = tensorboard_converters
Esempio n. 5
0
 def add_task_flow(self, task_flow: TaskFlow):
     self.flow_tasks.append(task_flow)
     self._name_to_task[task_flow.get_name()] = task_flow
     return task_flow