# helia_edge.layers.patching

Portable image patch extraction and masked patch embeddings.

## helia_edge.layers.patching.PatchLayer2D

`class` · `python`

```python
PatchLayer2D(height: int, width: int, ch: int, patch_height: int, patch_width: int, **kwargs={})
```

Extract flattened patches from images shaped (batch, height, width, ch).

Source: `helia_edge/layers/patching.py:17`

### helia_edge.layers.patching.PatchLayer2D.height

`attribute` · `python`

```python
height = height
```

Source: `helia_edge/layers/patching.py:30`

### helia_edge.layers.patching.PatchLayer2D.width

`attribute` · `python`

```python
width = width
```

Source: `helia_edge/layers/patching.py:31`

### helia_edge.layers.patching.PatchLayer2D.ch_size

`attribute` · `python`

```python
ch_size = ch
```

Source: `helia_edge/layers/patching.py:32`

### helia_edge.layers.patching.PatchLayer2D.patch_height

`attribute` · `python`

```python
patch_height = patch_height
```

Source: `helia_edge/layers/patching.py:33`

### helia_edge.layers.patching.PatchLayer2D.patch_width

`attribute` · `python`

```python
patch_width = patch_width
```

Source: `helia_edge/layers/patching.py:34`

### helia_edge.layers.patching.PatchLayer2D.resize

`attribute` · `python`

```python
resize = keras.layers.Reshape((-1, patch_height * patch_width * ch))
```

Source: `helia_edge/layers/patching.py:36`

### helia_edge.layers.patching.PatchLayer2D.call

`method` · `python`

```python
call(images: Tensor) -> Tensor
```

Source: `helia_edge/layers/patching.py:38`

### helia_edge.layers.patching.PatchLayer2D.get_config

`method` · `python`

```python
get_config() -> dict[str, Any]
```

Source: `helia_edge/layers/patching.py:49`

### helia_edge.layers.patching.PatchLayer2D.show_patched_image

`method` · `python`

```python
show_patched_image(images: keras.KerasTensor, patches: keras.KerasTensor) -> int
```

Plot one image and its reconstructed patches; return its batch index.

Source: `helia_edge/layers/patching.py:59`

### helia_edge.layers.patching.PatchLayer2D.reconstruct_from_patch

`method` · `python`

```python
reconstruct_from_patch(patch: keras.KerasTensor) -> keras.KerasTensor
```

Reconstruct one image from non-overlapping patches in row-major order.

Source: `helia_edge/layers/patching.py:83`

## helia_edge.layers.patching.MaskedPatchEncoder2D

`class` · `python`

```python
MaskedPatchEncoder2D(
    patch_height: int,
    patch_width: int,
    ch_size: int,
    projection_dim: int,
    mask_proportion: float,
    downstream: bool = False,
    seed: int | None = None,
    **kwargs={},
)
```

Project patches with position embeddings and sample masks from a seeded stream.

Source: `helia_edge/layers/patching.py:95`

### helia_edge.layers.patching.MaskedPatchEncoder2D.patch_height

`attribute` · `python`

```python
patch_height = patch_height
```

Source: `helia_edge/layers/patching.py:110`

### helia_edge.layers.patching.MaskedPatchEncoder2D.patch_width

`attribute` · `python`

```python
patch_width = patch_width
```

Source: `helia_edge/layers/patching.py:111`

### helia_edge.layers.patching.MaskedPatchEncoder2D.ch_size

`attribute` · `python`

```python
ch_size = ch_size
```

Source: `helia_edge/layers/patching.py:112`

### helia_edge.layers.patching.MaskedPatchEncoder2D.projection_dim

`attribute` · `python`

```python
projection_dim = projection_dim
```

Source: `helia_edge/layers/patching.py:113`

### helia_edge.layers.patching.MaskedPatchEncoder2D.mask_proportion

`attribute` · `python`

```python
mask_proportion = mask_proportion
```

Source: `helia_edge/layers/patching.py:114`

### helia_edge.layers.patching.MaskedPatchEncoder2D.downstream

`attribute` · `python`

```python
downstream = downstream
```

Source: `helia_edge/layers/patching.py:115`

### helia_edge.layers.patching.MaskedPatchEncoder2D.seed

`attribute` · `python`

```python
seed = seed
```

Source: `helia_edge/layers/patching.py:116`

### helia_edge.layers.patching.MaskedPatchEncoder2D.seed_generator

`attribute` · `python`

```python
seed_generator = keras.random.SeedGenerator(seed)
```

Source: `helia_edge/layers/patching.py:117`

### helia_edge.layers.patching.MaskedPatchEncoder2D.projection

`attribute` · `python`

```python
projection = keras.layers.Dense(units=self.projection_dim)
```

Source: `helia_edge/layers/patching.py:120`

### helia_edge.layers.patching.MaskedPatchEncoder2D.position_embedding

`attribute` · `python`

```python
position_embedding = None
```

Source: `helia_edge/layers/patching.py:121`

### helia_edge.layers.patching.MaskedPatchEncoder2D.build

`method` · `python`

```python
build(input_shape)
```

Source: `helia_edge/layers/patching.py:123`

### helia_edge.layers.patching.MaskedPatchEncoder2D.call

`method` · `python`

```python
call(patches: Tensor) -> Tensor | tuple[Tensor, Tensor, Tensor, Tensor, Tensor]
```

Source: `helia_edge/layers/patching.py:142`

### helia_edge.layers.patching.MaskedPatchEncoder2D.get_random_indices

`method` · `python`

```python
get_random_indices(batch_size: int) -> tuple[Tensor, Tensor]
```

Source: `helia_edge/layers/patching.py:180`

### helia_edge.layers.patching.MaskedPatchEncoder2D.get_config

`method` · `python`

```python
get_config() -> dict[str, Any]
```

Source: `helia_edge/layers/patching.py:188`

### helia_edge.layers.patching.MaskedPatchEncoder2D.generate_masked_image

`method` · `python`

```python
generate_masked_image(patches: keras.KerasTensor, unmask_indices: keras.KerasTensor)
```

Source: `helia_edge/layers/patching.py:200`
