Kingtous commited on
Commit
b4b6420
·
1 Parent(s): b3929b6

feat: init lama in gpu env

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. model/big-lama.pt +3 -0
app.py CHANGED
@@ -5,15 +5,15 @@ import torch
5
  from PIL import Image
6
  import numpy as np
7
  import cv2
 
8
  from simple_lama_inpainting import SimpleLama
9
 
10
- zero = torch.Tensor([0]).cuda()
11
- print(zero.device) # <-- 'cpu' 🤔
12
- lama: SimpleLama = SimpleLama(device=zero.device)
13
-
14
 
15
  @spaces.GPU
16
  def lama_inpainting(image: np.ndarray, mask: np.ndarray) -> np.ndarray:
 
 
17
  res = lama(
18
  Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)).convert("RGB"),
19
  Image.fromarray(cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)).convert("L"),
 
5
  from PIL import Image
6
  import numpy as np
7
  import cv2
8
+ import os
9
  from simple_lama_inpainting import SimpleLama
10
 
11
+ big_lama_url = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'model/big-lama.pt')
 
 
 
12
 
13
  @spaces.GPU
14
  def lama_inpainting(image: np.ndarray, mask: np.ndarray) -> np.ndarray:
15
+ os.environ['LAMA_MODEL'] = big_lama_url
16
+ lama: SimpleLama = SimpleLama()
17
  res = lama(
18
  Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)).convert("RGB"),
19
  Image.fromarray(cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)).convert("L"),
model/big-lama.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ba7aa7ac37a4d41fdbbeba3a2af7ead18058552997e3a3cd1a3b2210c9e6b4c
3
+ size 205803670