djl234 commited on
Commit
d86b569
·
1 Parent(s): 472e711

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -16,22 +16,22 @@ from model_video import build_model
16
  import numpy as np
17
  import collections
18
  #import argparse
19
-
20
- net = build_model('cpu').to('cpu')
21
  #net=torch.nn.DataParallel(net)
22
  model_path = 'image_best.pth'
23
  print(model_path)
24
- weight=torch.load(model_path,map_location=torch.device('cpu'))
25
  #print(type(weight))
26
  new_dict=collections.OrderedDict()
27
  for k in weight.keys():
28
  new_dict[k[len('module.'):]]=weight[k]
29
  net.load_state_dict(new_dict)
30
  net.eval()
31
- net = net.to('cpu')
32
  def test(gpu_id, net, img_list, group_size, img_size):
33
  print('test')
34
- device='cpu'
35
 
36
  img_transform = transforms.Compose([transforms.Resize((img_size, img_size)), transforms.ToTensor(),
37
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
@@ -65,7 +65,7 @@ def sepia(img1,img2,img3,img4,img5):
65
  h_list,w_list=[_.shape[0] for _ in img_list],[_.shape[1] for _ in img_list]
66
  #print(type(img1))
67
  #print(img1.shape)
68
- result_list=test('cpu',net,img_list,5,224)
69
  #result_list=[result_list[i].resize((w_list[i], h_list[i]), Image.BILINEAR) for i in range(5)]
70
  img1,img2,img3,img4,img5=result_list#test('cpu',net,img_list,5,224)
71
  return img1,img2,img3,img4,img5
 
16
  import numpy as np
17
  import collections
18
  #import argparse
19
+ device='cuda:0'
20
+ net = build_model(device).to(device)
21
  #net=torch.nn.DataParallel(net)
22
  model_path = 'image_best.pth'
23
  print(model_path)
24
+ weight=torch.load(model_path,map_location=torch.device(device))
25
  #print(type(weight))
26
  new_dict=collections.OrderedDict()
27
  for k in weight.keys():
28
  new_dict[k[len('module.'):]]=weight[k]
29
  net.load_state_dict(new_dict)
30
  net.eval()
31
+ net = net.to(device)
32
  def test(gpu_id, net, img_list, group_size, img_size):
33
  print('test')
34
+ #device=device
35
 
36
  img_transform = transforms.Compose([transforms.Resize((img_size, img_size)), transforms.ToTensor(),
37
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
 
65
  h_list,w_list=[_.shape[0] for _ in img_list],[_.shape[1] for _ in img_list]
66
  #print(type(img1))
67
  #print(img1.shape)
68
+ result_list=test(device,net,img_list,5,224)
69
  #result_list=[result_list[i].resize((w_list[i], h_list[i]), Image.BILINEAR) for i in range(5)]
70
  img1,img2,img3,img4,img5=result_list#test('cpu',net,img_list,5,224)
71
  return img1,img2,img3,img4,img5