Test a pretrained model saved in the pth.tar format

I downloaded a pytorch model and trained it. After the training was completed, the model was saved as “C3D-ucf101_epoch-99.pth.tar”.Because I am a complete beginner in the field of Deep Learning and Pytorch, can you tell me how do i test now my model for different videos?

Since you trained the model I’m assuming you are able to create dataloaders for the videos you want to test it on.
The following is a rough outline of how to load your saved model and test on different datasets:

device = 'cuda'
 # create an instance of your model with required args
model = Model(**kwargs) 

 # assuming you saved your weights as torch.save(f='weights.pth', obj=model.state_dict())
saved_weights = torch.load(weights_path)
model.load_state_dict(saved_weights) 

model.to(device)
model.eval()

for video_frames, targets  in test_loader:
  video_frames, targets = video_frames.to(device), targets.to(device)
  out = model(video)
  # evaluation logic goes here
1 Like