Update app.py
Browse files
app.py
CHANGED
@@ -213,6 +213,27 @@ def res2net152_v1b_26w_4s(pretrained=False, **kwargs):
|
|
213 |
model.load_state_dict(model_zoo.load_url(model_urls['res2net152_v1b_26w_4s']))
|
214 |
return model
|
215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
pth_path = './add_face_emotion_model_7.pt'
|
217 |
category_num = 7
|
218 |
|
@@ -241,7 +262,9 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
241 |
|
242 |
|
243 |
#增加人脸识别模型
|
244 |
-
model=
|
|
|
|
|
245 |
model.eval()
|
246 |
|
247 |
labels = ['怀旧','伤感','快乐','激励','清新','浪漫','思念']
|
|
|
213 |
model.load_state_dict(model_zoo.load_url(model_urls['res2net152_v1b_26w_4s']))
|
214 |
return model
|
215 |
|
216 |
+
|
217 |
+
class mutil_model(nn.Module):
|
218 |
+
|
219 |
+
def __init__(self,category_num = 7):
|
220 |
+
super(mutil_model, self).__init__()
|
221 |
+
self.model1 = res2net50_v1b_26w_4s(pretrained=False)
|
222 |
+
self.model1.fc = nn.Sequential(
|
223 |
+
nn.Linear(in_features=2048, out_features=category_num, bias=True),
|
224 |
+
)
|
225 |
+
self.model2 = torch.load('./affectnet_emotions/'+'enet_b2_8'+'.pt',map_location=torch.device('cpu'))
|
226 |
+
self.model2.classifier = nn.Sequential(
|
227 |
+
nn.Linear(in_features=1408, out_features=category_num, bias=True),
|
228 |
+
)
|
229 |
+
self.fc = nn.Linear(in_features=category_num*2, out_features=category_num, bias=True)
|
230 |
+
def forward(self, x):
|
231 |
+
x1 = self.model1(x)
|
232 |
+
x2 = self.model2(x)
|
233 |
+
x = torch.cat((x1,x2),1)
|
234 |
+
x = self.fc(x)
|
235 |
+
return x
|
236 |
+
|
237 |
pth_path = './add_face_emotion_model_7.pt'
|
238 |
category_num = 7
|
239 |
|
|
|
262 |
|
263 |
|
264 |
#增加人脸识别模型
|
265 |
+
model = mutil_model(category_num = 7)
|
266 |
+
model_state = torch.load('./add_face_emotion_model_7.pt',map_location=torch.device('cpu')).state_dict()
|
267 |
+
model.load_state_dict(model_state) # 加载模型参数
|
268 |
model.eval()
|
269 |
|
270 |
labels = ['怀旧','伤感','快乐','激励','清新','浪漫','思念']
|