Spaces:
Runtime error
Runtime error
hcs
commited on
Commit
·
4afdb1d
1
Parent(s):
52e8824
Add application file
Browse files
core.py
CHANGED
@@ -16,27 +16,15 @@ def load_model(pretrained_dict, new):
|
|
16 |
new.load_state_dict(model_dict)
|
17 |
|
18 |
|
19 |
-
# if torch.cuda.is_available():
|
20 |
-
# device = torch.device("cuda")
|
21 |
-
# else:
|
22 |
device = torch.device("cpu")
|
23 |
print("use cpu")
|
24 |
|
25 |
-
# model_ckpt_path = "./models/resnet18.pth"
|
26 |
-
# model_ckpt_path = "https://huggingface.co/M4869/beauty_prediction_fpb5k/blob/main/resnet18.pth"
|
27 |
-
|
28 |
-
# model_ckpt_path = "M4869/beauty_prediction_fpb5k"
|
29 |
-
# model = torch.hub.load("huggingface/transformers", model_ckpt_path)
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
# ans = hf_hub_download(repo_id="google/pegasus-xsum", filename="config.json")
|
35 |
# /home/my/.cache/huggingface/hub/models--google--pegasus-xsum/snapshots/8d8ffc158a3bee9fbb03afacdfc347c823c5ec8b/config.json
|
36 |
|
37 |
model_ckpt_path = hf_hub_download(repo_id="M4869/beauty_prediction_fpb5k", filename="resnet18.pth")
|
38 |
net = Nets.ResNet(block=Nets.BasicBlock, layers=[2, 2, 2, 2], num_classes=1).to(device)
|
39 |
-
load_model(torch.load(model_ckpt_path, encoding='latin1'), net)
|
40 |
net.eval()
|
41 |
|
42 |
transform = transforms.Compose([
|
@@ -53,17 +41,3 @@ def fun(img_path):
|
|
53 |
img = img.unsqueeze(0).to(device)
|
54 |
output = net(img).squeeze(1).cpu().numpy()[0]
|
55 |
return output
|
56 |
-
|
57 |
-
# def main():
|
58 |
-
# for i in range(6, 7):
|
59 |
-
# img = Image.open("./data2/%d.jpg" % i).convert('RGB')
|
60 |
-
# img = transform(img)
|
61 |
-
#
|
62 |
-
# with torch.no_grad():
|
63 |
-
# img = img.unsqueeze(0).to(device)
|
64 |
-
# output = net(img).squeeze(1).cpu().numpy()[0]
|
65 |
-
# print(i, output * 20)
|
66 |
-
|
67 |
-
|
68 |
-
# if __name__ == '__main__':
|
69 |
-
# main()
|
|
|
16 |
new.load_state_dict(model_dict)
|
17 |
|
18 |
|
|
|
|
|
|
|
19 |
device = torch.device("cpu")
|
20 |
print("use cpu")
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# ans = hf_hub_download(repo_id="google/pegasus-xsum", filename="config.json")
|
23 |
# /home/my/.cache/huggingface/hub/models--google--pegasus-xsum/snapshots/8d8ffc158a3bee9fbb03afacdfc347c823c5ec8b/config.json
|
24 |
|
25 |
model_ckpt_path = hf_hub_download(repo_id="M4869/beauty_prediction_fpb5k", filename="resnet18.pth")
|
26 |
net = Nets.ResNet(block=Nets.BasicBlock, layers=[2, 2, 2, 2], num_classes=1).to(device)
|
27 |
+
load_model(torch.load(model_ckpt_path, encoding='latin1', map_location=torch.device('cpu')), net)
|
28 |
net.eval()
|
29 |
|
30 |
transform = transforms.Compose([
|
|
|
41 |
img = img.unsqueeze(0).to(device)
|
42 |
output = net(img).squeeze(1).cpu().numpy()[0]
|
43 |
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|