tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

DeFMO notebook example

Open rozumden opened this issue 3 years ago • 5 comments

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

rozumden avatar Aug 27 '21 10:08 rozumden

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@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

edgarriba avatar Aug 28 '21 12:08 edgarriba

@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

rozumden avatar Aug 29 '21 20:08 rozumden

@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(...)

edgarriba avatar Sep 01 '21 14:09 edgarriba

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

rozumden avatar Sep 01 '21 14:09 rozumden