Finetuning Torchvision Models Predict?

I’m sorry but I don’t know what code to write to print the target tensor, my training loop is

def train_model()

right? I only know as far as that

In train_model add the print statement in the data loop:

for inputs, labels in dataloaders[phase]:
    inputs = inputs.to(device)
    labels = labels.to(device)
    print(labels)
1 Like

Thank you time and time again!

I would like to know if there is a way to convert .pth file to .h5 or .hdf5 ?

My lecturer asked the model to be loaded in that format because he prefers Keras

So I guess your lecturer would like to load the model in Keras?
If that’s the case, you would have to convert your PyTorch model to a Keras one.
Have a look at ONNX which provides some transformations.
Probably it would be easier to export it in the following way: PyTorch -> Tensorflow -> Keras, but I’ve never done it before so I’m not sure how smoothly it’ll be.
Also this repo seems to provide another way to directly transform your model.

as turns out actually I can use pytorch for submission, he wants a code to load the model and predict a folder of images, is there an example of this that I can use?

I saved the model into .pth

In that case you could create a script where you can specify some arguments for the input and output folder using argparse and just create predictions for each image.
This script is a bit older, but should give you a good starter code.