Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurs when using a custom image #8

Open
823863429 opened this issue Nov 30, 2023 · 2 comments
Open

An error occurs when using a custom image #8

823863429 opened this issue Nov 30, 2023 · 2 comments

Comments

@823863429
Copy link

Thank you for your outstanding work. When I use the image I uploaded and execute sample_i2v.yaml, I will be prompted:
loading video from input/i2v/rocket1.png
loading the input image
Traceback (most recent call last):
File "/content/SEINE/sample_scripts/with_mask_sample.py", line 243, in
main(omega_conf)
File "/content/SEINE/sample_scripts/with_mask_sample.py", line 226, in main
video_input, researve_frames = get_input(args) # f,c,h,w
File "/content/SEINE/sample_scripts/with_mask_sample.py", line 105, in get_input
video_frames = transform_video(video_frames)
File "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/transforms.py", line 95, in call
img = t(img)
File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1501, in call_impl
return forward_call(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/transforms.py", line 277, in forward
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional.py", line 363, in normalize
return F_t.normalize(tensor, mean=mean, std=std, inplace=inplace)
File "/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional_tensor.py", line 928, in normalize
return tensor.sub
(mean).div
(std)
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 1

Is there any way to fix this error ??

@ExponentialML
Copy link

ExponentialML commented Nov 30, 2023

Hey. You can either re-save it as a jpg (your image has an alpha / transparency channel), or create a function in the main sample code by adding:

def get_img(img_path_or_tensor):
    img = torch.as_tensor(
        np.array(
            Image.open(img_path_or_tensor), 
            dtype=np.uint8, copy=True)
        ).unsqueeze(0)
    
    return img[:, :, :, :3]

Then replace all instances like from here with:

first_frame = get_img(first_frame_path)

@823863429
Copy link
Author

Hey. You can either re-save it as a jpg (your image has an alpha / transparency channel), or create a function in the main sample code by adding:

def get_img(img_path_or_tensor):
    img = torch.as_tensor(
        np.array(
            Image.open(img_path_or_tensor), 
            dtype=np.uint8, copy=True)
        ).unsqueeze(0)
    
    return img[:, :, :, :3]

Then replace all instances like from here with:

first_frame = get_img(first_frame_path)

it work, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants