Ejemplo n.º 1
0
    def show(self,
             ax: plt.Axes = None,
             figsize: tuple = (3, 3),
             hide_axis: bool = True,
             cmap: str = None,
             y: fvision.Any = None,
             anatomical_plane: str = None,
             **kwargs):
        "Show image on `ax`, using `cmap` if single-channel, overlaid with optional `y`"

        cmap = fvision.ifnone(cmap, fvision.defaults.cmap)

        if type(y) in [Category, FloatItem]:  #classification or regression
            ax = show_image(self,
                            ax=ax,
                            hide_axis=hide_axis,
                            figsize=figsize,
                            anatomical_plane=anatomical_plane)
            y.show(ax=ax, **kwargs)
        else:
            ax = show_image(self,
                            ax=ax,
                            hide_axis=hide_axis,
                            figsize=figsize,
                            y=y,
                            anatomical_plane=anatomical_plane)  #segmentation
Ejemplo n.º 2
0
 def show_xyzs(self, xs, ys, zs, figsize: Tuple[int, int] = None, **kwargs):
     """Show `xs` (inputs), `ys` (targets) and `zs` (predictions) on a figure of `figsize`.
     `kwargs` are passed to the show method."""
     figsize = faiv.ifnone(figsize, (12, 3 * len(xs)))
     fig, axs = plt.subplots(len(xs), 2, figsize=figsize)
     fig.suptitle('Ground truth / Predictions', weight='bold', size=14)
     for i, (x, z) in enumerate(zip(xs, zs)):
         x.to_one().show(ax=axs[i, 0], **kwargs)
         z.to_one().show(ax=axs[i, 1], **kwargs)
Ejemplo n.º 3
0
    def __init__(self, learn, heatmap_func=None, filter_idx=None, acc_thresh=None, niter=1, mean=None):
        super().__init__(learn)
        if filter_idx and acc_thresh:
            raise ValueError('No support for partial keypoints and multilabel classification')

        self.filter_idx = sorted(filter_idx) if filter_idx else range(16)
        self.heatmap_func = heatmap_func if heatmap_func else lambda outputs: outputs
        self.acc_thresh = acc_thresh
        self.niter = niter
        self.mean = fv.ifnone(mean, self.niter > 1)
def unet_learner(
    data: DataBunch,
    arch: Callable,
    pretrained: bool = True,
    blur_final: bool = True,
    norm_type: Optional[NormType] = NormType,
    split_on: Optional[SplitFuncOrIdxList] = None,
    blur: bool = False,
    self_attention: bool = False,
    y_range: Optional[Tuple[float, float]] = None,
    last_cross: bool = True,
    bottle: bool = False,
    cut: Union[int, Callable] = None,
    hypercolumns=True,
    **learn_kwargs: Any,
) -> Learner:
    "Build Unet learner from `data` and `arch`."
    meta = cnn_config(arch)
    body = create_body(arch, pretrained, cut)
    M = DynamicUnet_Hcolumns if hypercolumns else DynamicUnet
    model = to_device(
        M(
            body,
            n_classes=data.c,
            blur=blur,
            blur_final=blur_final,
            self_attention=self_attention,
            y_range=y_range,
            norm_type=norm_type,
            last_cross=last_cross,
            bottle=bottle,
        ),
        data.device,
    )
    learn = Learner(data, model, **learn_kwargs)
    learn.split(ifnone(split_on, meta["split"]))
    if pretrained:
        learn.freeze()
    apply_init(model[2], nn.init.kaiming_normal_)
    return learn