kornia / tutorials

Repository containing the Kornia related tutorials
https://kornia.github.io/tutorials/
Apache License 2.0
45 stars 32 forks source link

DeFMO notebook example #16

Open rozumden opened 3 years ago

rozumden commented 3 years ago

Simple examples to use DeFMO. Images are yet to be uploaded.

review-notebook-app[bot] commented 3 years ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

edgarriba commented 3 years ago

@rozumden could you provide somewhere the data needed to run this example ? If you could send or share a link - don't add in the PR

rozumden commented 3 years ago

@rozumden could you provide somewhere the data needed to run this example ? If you could send or share a link - don't add in the PR

Hi, you can download it here: https://polybox.ethz.ch/index.php/s/SQuVjC6iy8QHsWi

edgarriba commented 3 years ago

@rozumden I'm checking this and I believe that we could structure better the code and first create a more high-level class (that might go in the direction of the library from now). This is my initial proposal (I can spend some time coding this):

/cc @ducha-aiki please, review this proposal


class VideoDeblurring(nn.Module):
    def __init__(selfresolution_x: int, resolution_y: int):
         self.render = K.features.DefMO(...)
         ...

    def initialize(cap: cv2.VideoCapture) -> torch.Tensor:
        # compute median
        ...

    def _preprocess(...):
        bbox, radius = fmo_detect_maxarea(I,B)
        # make the cropping and so here 
        ...

    def _postprocess(...):
        # rgba2hs, etc
        ...

    def forward(self, frame: torch.Tensor) -> torch.Tensor:
        """ Grab one frame compute """
        ### do whatever with median etc
        self._update_median(frame)
        frame_prep = self._preprocess(frame)
        frame_inter = self.render(frame_prep)
        frame_post = self._postprocess(frame_inter)
        return out

Then to use it

cap = cv2.VideoCapture(...)

deblur = VideoDeblurring(...)
deblur.initialized(cap)

while cap.isOpened():
    ret, frame = cap.read()
    out = deblur(frame)

To keep in mind for future too (not for now)

deblur.fine_tune(...)
rozumden commented 3 years ago

@edgarriba this looks good to me. It would definitely make the code more user-friendly and understandable.