czkaiweb commited on
Commit
6a31e95
·
1 Parent(s): f345c9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -15,8 +15,9 @@ os.system("wget https://github.com/liuxiaoyuyuyu/vanGogh-and-Other-Artist/blob/m
15
  model = models.mobilenet_v2()
16
  num_ftrs = model.classifier[1].in_features
17
  model.classifier[1] = nn.Linear(num_ftrs, 6)
 
18
  #model = model.to(device)
19
- model.load_state_dict(torch.load('model_weights_mobilenet_v2_valp1trainp2.pth'))
20
 
21
  #torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
22
 
@@ -35,6 +36,8 @@ def inference(input_image):
35
  if torch.cuda.is_available():
36
  input_batch = input_batch.to('cuda')
37
  model.to('cuda')
 
 
38
 
39
  with torch.no_grad():
40
  output = model(input_batch)
 
15
  model = models.mobilenet_v2()
16
  num_ftrs = model.classifier[1].in_features
17
  model.classifier[1] = nn.Linear(num_ftrs, 6)
18
+ device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
19
  #model = model.to(device)
20
+ model.load_state_dict(torch.load('model_weights_mobilenet_v2_valp1trainp2.pth',map_location=device))
21
 
22
  #torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
23
 
 
36
  if torch.cuda.is_available():
37
  input_batch = input_batch.to('cuda')
38
  model.to('cuda')
39
+ else:
40
+ model.to('cpu')
41
 
42
  with torch.no_grad():
43
  output = model(input_batch)