forked from zhouyw16/SEM-MacridVAE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed.py
More file actions
33 lines (24 loc) · 673 Bytes
/
Copy pathembed.py
File metadata and controls
33 lines (24 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from PIL import Image
import torch
import torch.nn as nn
from torchvision import models, transforms
def load_embed():
return
def load_embed_docs(dir):
return
def load_embed_pics(dir):
model = models.resnet18(pretrained=True)
model.fc = nn.Identity()
transform = transforms.Compose(
[transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor()]
)
dir = os.path.join("data", dir, "pic1.jpg")
img = Image.open(dir)
img = torch.unsqueeze(transform(img), dim=0)
with torch.no_grad():
feats = model(img)
print(feats)
if __name__ == "__main__":
dir = "test"
load_embed_pics(dir)