vt-vl-lab / FGVC

[ECCV 2020] Flow-edge Guided Video Completion
Other
1.55k stars 263 forks source link

RuntimeError: grid_sampler(): expected grid and input to have same batch size #41

Closed AnimeshMaheshwari22 closed 2 years ago

AnimeshMaheshwari22 commented 3 years ago

To solve #40, I compressed the images and reduced the quality. But in doing so, I am facing this error: RuntimeError: grid_sampler(): expected grid and input to have same batch size, but got input with sizes [3225, 1, 43, 75] and grid with sizes [3150, 9, 9, 2]

gaochen315 commented 3 years ago

I think this error is caused by the deepfill module. It requires that the height and weight should be divisible by 8. Please let me know if this helps.

AnimeshMaheshwari22 commented 3 years ago

I think this error is caused by the deepfill module. It requires that the height and weight should be divided by 8. Please let me know if this helps.

Thank you so much for the suggestion! Will try this and update here

AnimeshMaheshwari22 commented 3 years ago

Hello @gaochen315 I used cv2.resize(frame,(width//8, height//8),fx=0, fy=0) But it leads me to the same issue.

richuntt commented 3 years ago

I'm no expert but I encountered the same issue and solved it by keeping the height and weight diviSIBLE by 8.

Careful with your actual resolution, your code may lead to a floating number and not an integer, resulting to the same error. For example if your resolution is 1080p your code gives you a resolution of 240x135 and 135 divided by 8 is 16,875 which is not an integer, so it's not divisible by 8. Both your height and weight you input should by divisible by 8.

This may help find your resolution to feed (take one divisible by 8) https://pacoup.com/2011/06/12/list-of-true-169-resolutions/

gaochen315 commented 3 years ago

Hello @gaochen315 I used cv2.resize(frame,(width//8, height//8),fx=0, fy=0) But it leads me to the same issue.

You have to determine a new height and width that is divisible by 8, and then resize your images to this new pair of height and width. Let me know if this works.

AnimeshMaheshwari22 commented 3 years ago

I think this error is caused by the deepfill module. It requires that the height and weight should be divisible by 8. Please let me know if this helps.

This works! Thank you

AnimeshMaheshwari22 commented 3 years ago

I'm no expert but I encountered the same issue and solved it by keeping the height and weight diviSIBLE by 8.

Careful with your actual resolution, your code may lead to a floating number and not an integer, resulting to the same error. For example if your resolution is 1080p your code gives you a resolution of 240x135 and 135 divided by 8 is 16,875 which is not an integer, so it's not divisible by 8. Both your height and weight you input should by divisible by 8.

This may help find your resolution to feed (take one divisible by 8) https://pacoup.com/2011/06/12/list-of-true-169-resolutions/

Thank you! This works

lec0dex commented 3 years ago

With #48 the program return an exception if the resolution is not divisible by 8. It also round the extrapolated resolution to the closest dimension that is divisible by 8.

CreativeSelf0 commented 2 years ago
> 

def get_smallest_divisible_size_by_8(H, W):
        """
        Parameters
        ----------
        H : TYPE
            height of the image.
        W : TYPE
            width of the image.

        Returns
        -------
        H : TYPE
            adjusted height to be divisible by 8.
        W : TYPE
            adjusted width to be divisible by 8.
        """

        if W % 8 != 0:
           w = W % 8
           W = W - min(w - 8, w)

        if H % 8 != 0:
           h = H % 8
           H = H - min(h - 8, h)

        return H, W

This will work I think, then you can basically convert all images to this adjusted size.