morinop commited on
Commit
115b639
·
1 Parent(s): b9bb955

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -9,19 +9,34 @@ model.train()
9
 
10
  import os
11
 
 
 
 
 
 
 
 
 
 
 
12
  def greet(image):
13
  # url = f'https://huggingface.co/spaces?p=1&sort=modified&search=GPT'
14
  # html = request_url(url)
15
  # key = os.getenv("OPENAI_API_KEY")
16
  # x = torch.ones([1,3,224,224])
17
- print(type(image))
18
- image = torch.tensor(image).float()
19
- print(image.min(), image.max())
20
- image = image/255.0
21
- image = torch.permute(image, [0,2,3,1])
22
- out = model(image)
 
 
 
 
 
23
  # model.train()
24
- return f"Hello {model.bn1.running_mean.data} !!"
25
 
26
 
27
 
 
9
 
10
  import os
11
 
12
+ def print_bn():
13
+ bn_data = []
14
+ for m in model.modules():
15
+ if(type(m) is nn.BatchNorm2d):
16
+ # print(m.momentum)
17
+ bn_data.extend(m.running_mean.data.numpy().tolist())
18
+ bn_data.extend(m.running_var.data.numpy().tolist())
19
+ bn_data.append(float(m.momentum.data))
20
+ return bn_data
21
+
22
  def greet(image):
23
  # url = f'https://huggingface.co/spaces?p=1&sort=modified&search=GPT'
24
  # html = request_url(url)
25
  # key = os.getenv("OPENAI_API_KEY")
26
  # x = torch.ones([1,3,224,224])
27
+ if(image is None):
28
+ print_bn()
29
+ else:
30
+ print(type(image))
31
+ image = torch.tensor(image).float()
32
+ print(image.min(), image.max())
33
+ image = image/255.0
34
+ image = image.unsqueeze(0)
35
+ image = torch.permute(image, [0,2,3,1])
36
+ out = model(image)
37
+
38
  # model.train()
39
+ return f"Hello YOU !!"
40
 
41
 
42