huanx commited on
Commit
1273cb1
·
verified ·
1 Parent(s): 8a245da

Fix zero-variance input handling and keep bundled vendor runtime

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app/runtime.py +1 -1
  3. app/vendor/upcunet_v3.py +10 -8
.gitignore CHANGED
@@ -1,6 +1,7 @@
1
  __pycache__/
2
  *.pyc
3
  .venv/
 
4
  app/__pycache__/
5
  app/vendor/__pycache__/
6
  data/*.db
 
1
  __pycache__/
2
  *.pyc
3
  .venv/
4
+ .hf-deploy-secrets.txt
5
  app/__pycache__/
6
  app/vendor/__pycache__/
7
  data/*.db
app/runtime.py CHANGED
@@ -274,7 +274,7 @@ class RealCuganRuntime:
274
 
275
  def _ensure_vendor_file(self) -> Path:
276
  vendor_path = self.env.vendor_dir / "upcunet_v3.py"
277
- if vendor_path.exists() and self._sha256(vendor_path) == self.env.real_cugan_sha256:
278
  return vendor_path
279
  try:
280
  response = requests.get(self.env.real_cugan_upstream_url, timeout=45)
 
274
 
275
  def _ensure_vendor_file(self) -> Path:
276
  vendor_path = self.env.vendor_dir / "upcunet_v3.py"
277
+ if vendor_path.exists():
278
  return vendor_path
279
  try:
280
  response = requests.get(self.env.real_cugan_upstream_url, timeout=45)
app/vendor/upcunet_v3.py CHANGED
@@ -11,14 +11,16 @@ import os,sys
11
  import numpy as np
12
  root_path=os.path.abspath('.')
13
  sys.path.append(root_path)
14
- def q(inp,cache_mode):
15
- maxx = inp.max()
16
- minn = inp.min()
17
- delta = maxx - minn
18
- if(cache_mode==2):
19
- return ((inp-minn)/delta*255).round().byte().cpu(),delta,minn,inp.device#大概3倍延时#太慢了,屏蔽该模式
20
- elif(cache_mode==1):
21
- return ((inp-minn)/delta*255).round().byte(),delta,minn,inp.device#不用CPU转移
 
 
22
  def dq(inp,if_half,cache_mode,delta,minn,device):
23
  if(cache_mode==2):
24
  if(if_half==True):return inp.to(device).half()/255*delta+minn
 
11
  import numpy as np
12
  root_path=os.path.abspath('.')
13
  sys.path.append(root_path)
14
+ def q(inp,cache_mode):
15
+ maxx = inp.max()
16
+ minn = inp.min()
17
+ delta = maxx - minn
18
+ if(delta==0):
19
+ return torch.zeros_like(inp, dtype=torch.uint8),delta,minn,inp.device
20
+ if(cache_mode==2):
21
+ return ((inp-minn)/delta*255).round().byte().cpu(),delta,minn,inp.device#大概3倍延时#太慢了,屏蔽该模式
22
+ elif(cache_mode==1):
23
+ return ((inp-minn)/delta*255).round().byte(),delta,minn,inp.device#不用CPU转移
24
  def dq(inp,if_half,cache_mode,delta,minn,device):
25
  if(cache_mode==2):
26
  if(if_half==True):return inp.to(device).half()/255*delta+minn