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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

inference gives arbitrary output from trained model on np.ones #8304

Closed
innat opened this issue Mar 8, 2024 · 1 comment
Closed

inference gives arbitrary output from trained model on np.ones #8304

innat opened this issue Mar 8, 2024 · 1 comment

Comments

@innat
Copy link

innat commented Mar 8, 2024

馃悰 Describe the bug

I tired to do some simple inference using torchvision.models.video.swin3d_t model with input of np.ones but each time I run the inference the output gets changed.

import torch
import numpy as np
import torchvision

torch_model = torchvision.models.video.swin3d_t(
    pretrained=True
) 

np_input = np.ones(((1, 3, 32, 224, 224))).astype('float32')
torch_input = torch.from_numpy(np_input)

def run():
    with torch.no_grad():
        out_pt = torch_model(torch_input)
        print(out_pt[0, :5])

run()
tensor([ 0.2096,  0.8295,  0.2413, -1.1546, -0.0913])

run()
tensor([ 0.0429,  0.8538,  0.3214, -1.2695,  0.0097])

run()
tensor([-0.0245,  0.6934,  0.5590, -1.1861,  0.2010])

Versions

torchvision.version == 0.16.0+cu121

@NicolasHug
Copy link
Member

Hi @innat , use .eval() on the model. Also preferably use the weights= API:

from torchvision.models.video import Swin3D_T_Weights
torch_model = torchvision.models.video.swin3d_t(
    weights=Swin3D_T_Weights.KINETICS400_V1
).eval()

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