pytorch to onnx
import torch
import numpy as np
import sys
from torchsummary import summary
sys.path.append('.')
import logging.config
logging.config.fileConfig("config/logging.conf")
logger = logging.getLogger('api')
from core.model_loader.face_recognition.FaceRecModelLoader import FaceRecModelLoader
from core.model_handler.face_recognition.FaceRecModelHandler import FaceRecModelHandler
if __name__ == '__main__':
# img = np.random.randint(0, 255, size=(112,112,3), dtype=np.uint8)
# img = img[:,:,::-1].astype(np.float32)
# img = (img.transpose((2, 0, 1)) - 127.5) * 0.0078125
# img = torch.from_numpy(img).unsqueeze(0).float().cuda()
img = torch.randn(1,3,112,112).cuda()
save_path = "models.onnx"
model = torch.load('models.pkl')
model.eval()