NickKolok commited on
Commit
4cce72f
·
verified ·
1 Parent(s): ea89a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -22,10 +22,11 @@ if not os.path.exists(MODEL_PATH):
22
  # Define the Real-ESRGAN class
23
  class RealESRGAN:
24
  def __init__(self, model_path, device):
25
- # Load the model using torch.hub
26
- self.model = torch.hub.load('xinntao/Real-ESRGAN', 'real_esrgan', model=model_path, force_reload=True)
27
- self.model.eval().to(device) # Put model in evaluation mode and move to device
28
-
 
29
  def upscale(self, image_tensor):
30
  with torch.no_grad():
31
  sr_image_tensor = self.model(image_tensor).clamp(0, 1)
@@ -39,7 +40,7 @@ def upscale_image(image):
39
  # Pre-process the input image
40
  image = image.convert("RGB")
41
  transform = transforms.ToTensor()
42
- image_tensor = transform(image).unsqueeze(0) # Add batch dimension
43
 
44
  # Perform upscaling
45
  sr_image_tensor = model.upscale(image_tensor)
 
22
  # Define the Real-ESRGAN class
23
  class RealESRGAN:
24
  def __init__(self, model_path, device):
25
+ # Correctly load the model
26
+ self.model = torch.hub.load('xinntao/Real-ESRGAN', 'real_esrgan', model_path, device=device)
27
+ self.model.eval() # Set the model to eval mode
28
+ self.device = device # Store the device
29
+
30
  def upscale(self, image_tensor):
31
  with torch.no_grad():
32
  sr_image_tensor = self.model(image_tensor).clamp(0, 1)
 
40
  # Pre-process the input image
41
  image = image.convert("RGB")
42
  transform = transforms.ToTensor()
43
+ image_tensor = transform(image).unsqueeze(0).to(device) # Add batch dimension and move to device
44
 
45
  # Perform upscaling
46
  sr_image_tensor = model.upscale(image_tensor)