rgny commited on
Commit
403125e
·
verified ·
1 Parent(s): c83d374

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -6,15 +6,23 @@ from timeit import default_timer as timer
6
 
7
  model,transform=create_model()
8
  model=model.to("cpu")
9
- model.load_state_dict(torch.load("deneme_modeli.pth"))
 
 
 
 
 
 
10
  class_names = ["pizza","steak","sushi"]
11
  def predict(model,image):
12
  start=timer()
13
- image=transform(image).unsqueeze(0).to("cpu")
14
- output=model(image)
15
-
16
- pred={class_names[i]:torch.softmax(output,dim=1)[0][i].item() for i in range(len(class_names))}
17
- td=timer()-start
 
 
18
  return pred,td
19
 
20
  inputs = gr.Image(type="pil", label = "Resim")
 
6
 
7
  model,transform=create_model()
8
  model=model.to("cpu")
9
+ model.load_state_dict(
10
+ torch.load(
11
+ f="deneme_modeli.pth",
12
+ map_location=torch.device("cpu"), # load to CPU
13
+ )
14
+ )
15
+
16
  class_names = ["pizza","steak","sushi"]
17
  def predict(model,image):
18
  start=timer()
19
+ image=transform(image).unsqueeze(0)
20
+ model.eval()
21
+ with torch.inference_mode:
22
+ output=model(image)
23
+
24
+ pred={class_names[i]:torch.softmax(output,dim=1)[0][i].item() for i in range(len(class_names))}
25
+ td=timer()-start
26
  return pred,td
27
 
28
  inputs = gr.Image(type="pil", label = "Resim")