NicolasHug / Surprise

A Python scikit for building and analyzing recommender systems
http://surpriselib.com
BSD 3-Clause "New" or "Revised" License
6.34k stars 1.01k forks source link

How can I solve this problem #407

Closed per-ly closed 2 years ago

per-ly commented 2 years ago

import os import argparse

import torch import torch.nn as nn import torch.nn.functional as F import modnet_torchscript

if name == 'main':

define cmd arguments

parser = argparse.ArgumentParser()
parser.add_argument('--ckpt-path', type=str, required=False, help='D:/MODNet-master/pretrained')
parser.add_argument('--output-path', type=str, required=False, help='D:/MODNet-master/output-path')
args = parser.parse_args()
print(type("ckpt_path"))

# check input arguments
if not os.path.exists(args.ckpt_path):
    print(args.ckpt_path)
    print('Cannot find checkpoint path: {0}'.format(args.ckpt_path))
    exit()

# create MODNet and load the pre-trained ckpt
modnet = modnet_torchscript.MODNet(backbone_pretrained=False)
modnet = nn.DataParallel(modnet).cuda()
state_dict = torch.load(args.ckpt_path)
modnet.load_state_dict(state_dict)
modnet.eval()

# export to TorchScript model
scripted_model = torch.jit.script(modnet.module)
torch.jit.save(scripted_model, os.path.join(args.output_path))

Traceback (most recent call last): File "D:/MODNet-master/torchscript/export_torchscript.py", line 32, in if not os.path.exists(args.ckpt_path): File "D:\Anaconda3\envs\pytorch\lib\genericpath.py", line 19, in exists os.stat(path) TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

NicolasHug commented 2 years ago

Sorry @per-ly I think this is related to pytorch, not surprise