Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ import gdown
|
|
| 21 |
import matplotlib.pyplot as plt
|
| 22 |
import warnings
|
| 23 |
warnings.filterwarnings("ignore")
|
| 24 |
-
|
| 25 |
os.system("git clone https://github.com/xuebinqin/DIS")
|
| 26 |
os.system("mv DIS/IS-Net/* .")
|
| 27 |
|
|
@@ -53,7 +53,7 @@ class GOSNormalize(object):
|
|
| 53 |
transform = transforms.Compose([GOSNormalize([0.5,0.5,0.5],[1.0,1.0,1.0])])
|
| 54 |
|
| 55 |
def load_image(im_path, hypar):
|
| 56 |
-
im =
|
| 57 |
im, im_shp = im_preprocess(im, hypar["cache_size"])
|
| 58 |
im = torch.divide(im,255.0)
|
| 59 |
shape = torch.from_numpy(np.array(im_shp))
|
|
@@ -132,8 +132,7 @@ net = build_model(hypar, device)
|
|
| 132 |
|
| 133 |
|
| 134 |
def inference(image):
|
| 135 |
-
image_path =
|
| 136 |
-
gdown.download(image, image_path, quiet=False)
|
| 137 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 138 |
mask = predict(net, image_tensor, orig_size, hypar, device)
|
| 139 |
|
|
|
|
| 21 |
import matplotlib.pyplot as plt
|
| 22 |
import warnings
|
| 23 |
warnings.filterwarnings("ignore")
|
| 24 |
+
import requests
|
| 25 |
os.system("git clone https://github.com/xuebinqin/DIS")
|
| 26 |
os.system("mv DIS/IS-Net/* .")
|
| 27 |
|
|
|
|
| 53 |
transform = transforms.Compose([GOSNormalize([0.5,0.5,0.5],[1.0,1.0,1.0])])
|
| 54 |
|
| 55 |
def load_image(im_path, hypar):
|
| 56 |
+
im = Image.open(requests.get(im_path, stream=True).raw)
|
| 57 |
im, im_shp = im_preprocess(im, hypar["cache_size"])
|
| 58 |
im = torch.divide(im,255.0)
|
| 59 |
shape = torch.from_numpy(np.array(im_shp))
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
def inference(image):
|
| 135 |
+
image_path = image
|
|
|
|
| 136 |
image_tensor, orig_size = load_image(image_path, hypar)
|
| 137 |
mask = predict(net, image_tensor, orig_size, hypar, device)
|
| 138 |
|