# Medical Image Segmentation with Limited Data

## Usage

### As an executable

Using this package is easiest as a CLI using a yaml specification file. For an
example of spec file refer to `spec.example.yaml`. Then, training the models
declared in the spec file is as simple as 

```shell
$ python3 ivus_segmentation <spec.yaml> train
```

### As a library

The class `ivus_segmentation.models.IVUSModel` is the basic model class. Using
the modules `ivus_segmentation.architecture`, `ivus_segmentation.augment` and
`ivus_segmentation.metrics` a model can be built from an underlying
architecture, a list of augments and a loss: 

```python
input_shape = (382, 382, 3)
augments = [
  ElasticDeformation(alpha=2.375, sigma=0.172)
]
model = IvusModel(input_shape=input_shape,
                  arch=architecture.unet,
                  loss=metrics.HausdorffDTLoss(),
                  augments=self.augments)
```

`compile` and `fit` receive the same parameters as
[keras.Model](https://keras.io/api/models/model/).


## Documentation 

Here we display a list of the parameters that can be used for the `spec.yaml`.

**Architectures**:
- `resnet_unet`: unet using ResNet as an encoder
- `resnet_unet#frozen`: unet using ResNet as a frozen encoder
- `unet`

**Augments**:
- `RandomZoom(range: float)`: range as a fraction of the unit.
- `RandomRotation(range: float)`: rotation in fractions of `2π`.
- `RandomFlip()`: horizontal and vertical flips.
- `ElasticDeformation(alpha: float, sigma: float)`
- `EDMask(alpha: float, sigma: float)`: elastic deformation applied **only** to
  the mask.


**Losses**:
- `categorical_crossentropy`
- `hausdorff_dt`: Hausdorff distance approximation base on distance transforms.
- `jaccard`: Jaccard loss


