Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,30 @@ dinov2_vits14.to(device)
|
|
22 |
# Define the transformations: convert to tensor, resize, and normalize
|
23 |
transform_image = transforms.Compose([transforms.ToTensor(), transforms.Resize(224), transforms.Normalize([0.5], [0.5])])
|
24 |
|
25 |
-
model = torch.load("dress_model.pth")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
model.eval()
|
27 |
|
28 |
with open('saved_dress_morph.pkl', 'rb') as f:
|
|
|
22 |
# Define the transformations: convert to tensor, resize, and normalize
|
23 |
transform_image = transforms.Compose([transforms.ToTensor(), transforms.Resize(224), transforms.Normalize([0.5], [0.5])])
|
24 |
|
25 |
+
#model = torch.load("dress_model.pth")
|
26 |
+
class Dress_Class(nn.Module):
|
27 |
+
def __init__(self, num_dim, hidden_layers, num_classes):
|
28 |
+
super(Dress_Class, self).__init__()
|
29 |
+
layers = []
|
30 |
+
current_num = num_dim
|
31 |
+
|
32 |
+
for num_neurons in hidden_layers:
|
33 |
+
layers.append(nn.Linear(current_num, num_neurons))
|
34 |
+
layers.append(nn.ReLU())
|
35 |
+
current_num = num_neurons
|
36 |
+
|
37 |
+
layers.append(nn.Linear(current_num, num_classes))
|
38 |
+
layers.append(nn.Softmax(dim=1))
|
39 |
+
self.model = nn.Sequential(*layers)
|
40 |
+
|
41 |
+
def forward(self, x):
|
42 |
+
x = self.model(x)
|
43 |
+
return x
|
44 |
+
|
45 |
+
best = torch.load("best_mo.pth")
|
46 |
+
hidden_layers = [192, 187, 331, 186, 256]
|
47 |
+
model = Dress_Class(384, hidden_layers, 10)
|
48 |
+
model.state_dict(best)
|
49 |
model.eval()
|
50 |
|
51 |
with open('saved_dress_morph.pkl', 'rb') as f:
|