File size: 1,486 Bytes
e12111a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Module for diffusion segmentation."""
from __future__ import annotations

from dataclasses import dataclass

import jax.numpy as jnp

from imgx.diffusion.diffusion import Diffusion


@dataclass
class DiffusionSegmentation(Diffusion):
    """Base class for segmentation."""

    def mask_to_x(self, mask: jnp.ndarray) -> jnp.ndarray:
        """Convert mask to x.

        Args:
            mask: boolean segmentation mask.

        Returns:
            array in diffusion space.
        """
        raise NotImplementedError

    def x_to_mask(self, x: jnp.ndarray) -> jnp.ndarray:
        """Convert x to mask.

        Args:
            x: array in diffusion space.

        Returns:
            boolean segmentation mask.
        """
        raise NotImplementedError

    def x_to_logits(self, x: jnp.ndarray) -> jnp.ndarray:
        """Convert x into model output space, which is logits.

        Args:
            x: array in diffusion space.

        Returns:
            unnormalised logits.
        """
        raise NotImplementedError

    def model_out_to_logits_start(
        self, model_out: jnp.ndarray, x_t: jnp.ndarray, t_index: jnp.ndarray
    ) -> jnp.ndarray:
        """Convert model outputs to logits at time 0, noiseless.

        Args:
            model_out: model outputs.
            x_t: noisy x at time t.
            t_index: storing index values < self.num_timesteps.

        Returns:
            logits.
        """
        raise NotImplementedError