Commit ·
5cc1ae1
1
Parent(s): 9fbda1e
Remove broken .so file from repo and LFS
Browse files- src/resnet.py +0 -31
src/resnet.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torchvision.models as models
|
| 3 |
-
|
| 4 |
-
_resnet_model = None
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
def load_model():
|
| 8 |
-
global _resnet_model
|
| 9 |
-
if _resnet_model is None:
|
| 10 |
-
_resnet_model = models.resnet50(pretrained=True)
|
| 11 |
-
_resnet_model.eval()
|
| 12 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
-
_resnet_model.to(device)
|
| 14 |
-
return _resnet_model
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def predict(model, input_tensor, **kwargs):
|
| 18 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
-
with torch.no_grad():
|
| 20 |
-
if isinstance(input_tensor, list):
|
| 21 |
-
input_tensor = torch.tensor(input_tensor)
|
| 22 |
-
input_tensor = input_tensor.to(device)
|
| 23 |
-
output = model(input_tensor)
|
| 24 |
-
return output.cpu().numpy().tolist()
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
def unload_model(model):
|
| 28 |
-
global _resnet_model
|
| 29 |
-
_resnet_model = None
|
| 30 |
-
if torch.cuda.is_available():
|
| 31 |
-
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|