-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
30 lines (18 loc) · 732 Bytes
/
model.py
File metadata and controls
30 lines (18 loc) · 732 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
# Adopted from a code base from https://github.com/cetinsamet
# --------------------------------------------------
import random
random.seed(123)
import numpy as np
np.random.seed(123)
import torch
torch.manual_seed(123)
criterion = torch.nn.CrossEntropyLoss(reduction='sum') # <-- Loss Function
class Network(torch.nn.Module):
""" Zero-Shot model """
def __init__(self, feature_dim, vector_dim):
super(Network, self).__init__()
self.wHidden1 = torch.nn.Linear(feature_dim, vector_dim)
def forward(self, imageFeatures, classVectors):
imageFeatures = self.wHidden1(imageFeatures)
out = torch.matmul(imageFeatures, torch.t(classVectors))
return out