Как я могу загрузить .tar и сделать предсказания в django

Я создаю веб-приложение для прогнозирования с помощью PyTorch. Я обучил модель и сохранил веса модели в файле .tar и теперь я хочу загрузить модель и делать предсказания в Django, как я могу это сделать. нужна помощь

Я прикрепляю свой код предсказания ниже

def predicting(model, device, loader):
    model.eval()
    total_preds = torch.Tensor()
    total_labels = torch.Tensor()
    print('Make prediction for {} samples...'.format(len(loader.dataset)))
    with torch.no_grad():
        for solute_graphs, solvent_graphs, solute_lens, solvent_lens in tqdm(loader):
            outputs, i_map = model(
            [solute_graphs.to(device), solvent_graphs.to(device), torch.tensor(solute_lens).to(device),
             torch.tensor(solvent_lens).to(device)])
            total_preds = torch.cat((total_preds, outputs.cpu()), 0)
            # total_labels = torch.cat((total_labels, data.y.view(-1, 1).cpu()), 0)


    # return total_labels.numpy().flatten(),total_preds.numpy().flatten()
    return total_preds.numpy().flatten()
Вернуться на верх