import torch
import os
import json
import torchvision.models as models
import torch
from PIL import Image
from torchvision import transforms
#from model import vgg
import numpy as np
# An instance of your model.
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = models.resnet18(pretrained=True)
model.cuda()
# load model weights
weights_path = "./vgg16Net.pth"
assert os.path.exists(weights_path), "file: '{}' dose not exist.".format(weights_path)
#model.load_state_dict(torch.load(weights_path, map_location=device))
print(next(model.parameters()).device)
model.eval()
# An example input you would normally provide to your model's forward() method.
example = torch.rand(1, 3, 224, 224)
example = example.to(device)
# Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing.
一、导出模型import torchimport osimport jsonimport torchvision.models as modelsimport torchfrom PIL import Imagefrom torchvision import transforms#from model import vggimport numpy as np # An instance of your model.device = torch.device("cuda" if