Hu commited on
Commit
a58728b
1 Parent(s): 64c514e

update model

Browse files
Files changed (2) hide show
  1. app.py +13 -9
  2. model.py +14 -14
app.py CHANGED
@@ -23,9 +23,13 @@ article = """
23
  <p>📦 Dataset <a href="https://github.com/eugenesiow/super-image-data">this GitHub repo</a></p>
24
  </div>
25
  """
 
 
 
 
26
 
27
  # load model
28
- print("Loading SRCNN model...")
29
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
30
 
31
  model = SRCNNModel().to(device)
@@ -33,7 +37,8 @@ model.load_state_dict(
33
  torch.load("SRCNNmodel_trained.pt", map_location=torch.device(device))
34
  )
35
  model.eval()
36
- print("SRCNN model loaded!")
 
37
 
38
  # def image_grid(imgs, rows, cols):
39
  # '''
@@ -48,18 +53,17 @@ print("SRCNN model loaded!")
48
  # for i, img in enumerate(imgs):
49
  # grid.paste(img, box=(i%cols*w, i//cols*h))
50
  # return grid
51
- examples = [
52
- ["LR_image.png"],
53
- ["barbara.png"],
54
- ]
55
 
56
 
57
  def sepia(image):
58
  # gradio open image as np array
59
  image = Image.fromarray(image, mode="RGB")
60
- out_final, image_bicubic, image = pred_SRCNN(
61
- model=model, image=image, device=device
62
- )
 
 
 
63
  # grid = image_grid([out_final,image_bicubic],1,2)
64
  return out_final, image_bicubic
65
 
 
23
  <p>📦 Dataset <a href="https://github.com/eugenesiow/super-image-data">this GitHub repo</a></p>
24
  </div>
25
  """
26
+ examples = [
27
+ ["LR_image.png"],
28
+ ["barbara.png"],
29
+ ]
30
 
31
  # load model
32
+ # print("Loading SRCNN model...")
33
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
34
 
35
  model = SRCNNModel().to(device)
 
37
  torch.load("SRCNNmodel_trained.pt", map_location=torch.device(device))
38
  )
39
  model.eval()
40
+ # print("SRCNN model loaded!")
41
+
42
 
43
  # def image_grid(imgs, rows, cols):
44
  # '''
 
53
  # for i, img in enumerate(imgs):
54
  # grid.paste(img, box=(i%cols*w, i//cols*h))
55
  # return grid
 
 
 
 
56
 
57
 
58
  def sepia(image):
59
  # gradio open image as np array
60
  image = Image.fromarray(image, mode="RGB")
61
+
62
+ # prediction
63
+ with torch.no_grad():
64
+ out_final, image_bicubic, image = pred_SRCNN(
65
+ model=model, image=image, device=device
66
+ )
67
  # grid = image_grid([out_final,image_bicubic],1,2)
68
  return out_final, image_bicubic
69
 
model.py CHANGED
@@ -59,22 +59,22 @@ def pred_SRCNN(model,image,device,scale_factor=2):
59
  return out_final,image_bicubic,image
60
 
61
 
62
- def main():
63
- print("Loading SRCNN model...")
64
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
65
 
66
- model = SRCNNModel().to(device)
67
- model.load_state_dict(torch.load('SRCNNmodel_trained.pt'))
68
- model.eval()
69
- print("SRCNN model loaded!")
70
 
71
- image_path = "LR_image.png"
72
 
73
- out_final,image_bicubic,image = pred_SRCNN(model=model,image_path=image_path,device=device)
74
- image.show()
75
- out_final.show()
76
- image_bicubic.show()
77
 
78
 
79
- if __name__=="__main__":
80
- main()
 
59
  return out_final,image_bicubic,image
60
 
61
 
62
+ # def main():
63
+ # print("Loading SRCNN model...")
64
+ # device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
65
 
66
+ # model = SRCNNModel().to(device)
67
+ # model.load_state_dict(torch.load('SRCNNmodel_trained.pt'))
68
+ # model.eval()
69
+ # print("SRCNN model loaded!")
70
 
71
+ # image_path = "LR_image.png"
72
 
73
+ # out_final,image_bicubic,image = pred_SRCNN(model=model,image_path=image_path,device=device)
74
+ # image.show()
75
+ # out_final.show()
76
+ # image_bicubic.show()
77
 
78
 
79
+ # if __name__=="__main__":
80
+ # main()