ajout dependances
Browse files- TractionModel.py +59 -0
- app.py +1 -2
- model-score0.96-f1_10.9-f1_20.99.pt +3 -0
TractionModel.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Sun Jul 4 15:07:27 2021
|
4 |
+
|
5 |
+
@author: AlexandreN
|
6 |
+
"""
|
7 |
+
from __future__ import print_function, division
|
8 |
+
|
9 |
+
import torch
|
10 |
+
import torch.nn as nn
|
11 |
+
import torchvision
|
12 |
+
|
13 |
+
|
14 |
+
class SingleTractionHead(nn.Module):
|
15 |
+
|
16 |
+
def __init__(self):
|
17 |
+
super(SingleTractionHead, self).__init__()
|
18 |
+
|
19 |
+
self.head_locs = nn.Sequential(nn.Linear(2048, 1024),
|
20 |
+
nn.ReLU(),
|
21 |
+
nn.Dropout(p=0.3),
|
22 |
+
nn.Linear(1024, 4),
|
23 |
+
nn.Sigmoid()
|
24 |
+
)
|
25 |
+
|
26 |
+
# Head class should output the logits over the classe
|
27 |
+
self.head_class = nn.Sequential(nn.Linear(2048, 128),
|
28 |
+
nn.ReLU(),
|
29 |
+
nn.Dropout(p=0.3),
|
30 |
+
nn.Linear(128, 1))
|
31 |
+
|
32 |
+
def forward(self, features):
|
33 |
+
features = features.view(features.size()[0], -1)
|
34 |
+
|
35 |
+
y_bbox = self.head_locs(features)
|
36 |
+
y_class = self.head_class(features)
|
37 |
+
|
38 |
+
res = (y_bbox, y_class)
|
39 |
+
return res
|
40 |
+
|
41 |
+
|
42 |
+
def create_model():
|
43 |
+
# setup the architecture of the model
|
44 |
+
feature_extractor = torchvision.models.resnet50(pretrained=True)
|
45 |
+
model_body = nn.Sequential(*list(feature_extractor.children())[:-1])
|
46 |
+
for param in model_body.parameters():
|
47 |
+
param.requires_grad = False
|
48 |
+
# Parameters of newly constructed modules have requires_grad=True by default
|
49 |
+
# num_ftrs = model_body.fc.in_features
|
50 |
+
|
51 |
+
model_head = SingleTractionHead()
|
52 |
+
model = nn.Sequential(model_body, model_head)
|
53 |
+
return model
|
54 |
+
|
55 |
+
|
56 |
+
def load_weights(model, path='model.pt'):
|
57 |
+
checkpoint = torch.load(path)
|
58 |
+
model.load_state_dict(checkpoint)
|
59 |
+
return model
|
app.py
CHANGED
@@ -5,7 +5,6 @@ import cv2
|
|
5 |
import numpy as np
|
6 |
import matplotlib.pyplot as plt
|
7 |
|
8 |
-
from DataSet import QuestionDataSet
|
9 |
import TractionModel as plup
|
10 |
|
11 |
import random
|
@@ -40,7 +39,7 @@ vanilla_transform = torchvision.transforms.Compose([
|
|
40 |
torchvision.transforms.ToTensor(),
|
41 |
torchvision.transforms.Normalize(norm_mean, norm_std)])
|
42 |
|
43 |
-
model = init_model("
|
44 |
if torch.cuda.is_available():
|
45 |
device = torch.device("cuda")
|
46 |
else:
|
|
|
5 |
import numpy as np
|
6 |
import matplotlib.pyplot as plt
|
7 |
|
|
|
8 |
import TractionModel as plup
|
9 |
|
10 |
import random
|
|
|
39 |
torchvision.transforms.ToTensor(),
|
40 |
torchvision.transforms.Normalize(norm_mean, norm_std)])
|
41 |
|
42 |
+
model = init_model("model-score0.96-f1_10.9-f1_20.99.pt")
|
43 |
if torch.cuda.is_available():
|
44 |
device = torch.device("cuda")
|
45 |
else:
|
model-score0.96-f1_10.9-f1_20.99.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:acf13d3f6f4758fa68c8346478c9a7a5b1323cd96861a3c4266e7b8c438e4c18
|
3 |
+
size 103808501
|