Hi all,
I am trying to deploy my own custom model using handler.py
. Here is my code so far:
class EndpointHandler():
def __init__(self, path=""):
""" Initialize the model and required parameters."""
# model_path = "SRx4_EDTB_Div2kFlickr2K.pth"
config_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'configs')
config_files = [
os.path.splitext(os.path.basename(v))[0] for v in scandir(config_root)
if v.endswith('.py')
]
config_file = os.path.basename("./configs/SRx4_EDTB_Div2kFlickr2K.py").split('.')[0]
assert config_file in config_files, 'Illegal config!'
module_reg = importlib.import_module(f'configs.{config_file}')
self.config = getattr(module_reg, 'Config', None)
self.model = Network(self.config)
if torch.cuda.is_available():
self.device = torch.device('cuda')
else:
self.device = torch.device('cpu')
self.model = self.model.to(self.device)
weights = "SRx4_EDTB_Div2kFlickr2K.pth"
load_model_filter_list(self.model, weights, filter_list=[])
self.model.eval()
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
"""
Data Args:
inputs (:obj: `str` | `PIL.Image` | `np.array`)
kwargs
Return:
A :obj:`list` | `dict`: will be serialized and returned
"""
input_data = data.pop("inputs", data)
img = torch.from_numpy(np.array(input_data))
img = img.permute(2, 0, 1).unsqueeze(0) / 255.0
img = img.to(self.device)
# if model.parameters().dtype == 'fp16':
# input_data = input_data.half()
scales = []
for s in self.config.VAL.SCALES:
scales.append(s)
lqs, _, _ = preprocess_images(img, scales[0], self.config)
with torch.no_grad():
start_time = time.time()
preds = self.model(lqs)
torch.cuda.synchronize()
end_time = time.time()
print("Inference time: ", end_time - start_time, "seconds")
result = np.array(preds[0][0,:,:,:].cpu())
return {"result" : np.transpose(result, (1,2,0))}
Which gives me this error when I initialize the endpoint:
FileNotFoundError: [Errno 2] No such file or directory: 'SRx4_EDTB_Div2kFlickr2K.pth'
It works on my PC in a container, the file exists, I tried many things already and it doesn’t see my model. What is going on? I don’t know how to solve this issue at this point.