radames commited on
Commit
5c511d7
1 Parent(s): 482feb0

update reqs

Browse files
Files changed (5) hide show
  1. PIFu/apps/eval_spaces.py +1 -3
  2. PIFu/requirements.txt +7 -8
  3. app.py +23 -10
  4. remove_bg.py +1 -1
  5. requirements.txt +9 -9
PIFu/apps/eval_spaces.py CHANGED
@@ -18,8 +18,6 @@ from lib.model import *
18
 
19
  from PIL import Image
20
  import torchvision.transforms as transforms
21
- import glob
22
- import tqdm
23
 
24
  import trimesh
25
  from datetime import datetime
@@ -124,7 +122,7 @@ if __name__ == '__main__':
124
  time = datetime.now()
125
  print("evaluating" , time)
126
  data = evaluator.load_image(test_image_path, test_mask_path)
127
- evaluator.eval(data, True)
128
  print("done evaluating" , datetime.now() - time)
129
  except Exception as e:
130
  print("error:", e.args)
 
18
 
19
  from PIL import Image
20
  import torchvision.transforms as transforms
 
 
21
 
22
  import trimesh
23
  from datetime import datetime
 
122
  time = datetime.now()
123
  print("evaluating" , time)
124
  data = evaluator.load_image(test_image_path, test_mask_path)
125
+ evaluator.eval(data, False)
126
  print("done evaluating" , datetime.now() - time)
127
  except Exception as e:
128
  print("error:", e.args)
PIFu/requirements.txt CHANGED
@@ -1,24 +1,23 @@
1
- cudatoolkit=10.1
2
  cycler==0.10.0
3
  decorator==4.4.1
4
  imageio==2.8.0
5
  kiwisolver==1.1.0
6
  matplotlib==3.1.3
7
  networkx==2.4
8
- numpy==1.18.1
9
- opencv-python==4.2.0.32
10
  pathlib==1.0.1
11
- Pillow==9.0.0
12
- PyOpenGL==3.1.5
13
  pyparsing==2.4.6
14
  python-dateutil==2.8.1
15
  PyWavelets==1.1.1
16
- scikit-image==0.16.2
 
17
  scipy==1.4.1
18
  Shapely==1.7.0
19
  six==1.14.0
20
  torch==1.4.0
21
  torchvision==0.5.0
22
- tqdm==4.43.0
23
  trimesh==3.5.23
24
- xxhash==1.4.3
 
 
1
  cycler==0.10.0
2
  decorator==4.4.1
3
  imageio==2.8.0
4
  kiwisolver==1.1.0
5
  matplotlib==3.1.3
6
  networkx==2.4
7
+ numpy==1.21.6
8
+ opencv-python==4.1.2.30
9
  pathlib==1.0.1
10
+ Pillow==9.1.0
11
+ PyOpenGL==3.1.6
12
  pyparsing==2.4.6
13
  python-dateutil==2.8.1
14
  PyWavelets==1.1.1
15
+ scikit-image==0.18.3
16
+ scikit-learn==1.0.2
17
  scipy==1.4.1
18
  Shapely==1.7.0
19
  six==1.14.0
20
  torch==1.4.0
21
  torchvision==0.5.0
 
22
  trimesh==3.5.23
23
+ tqdm==4.64.0
app.py CHANGED
@@ -1,9 +1,9 @@
1
  import os
2
- try:
3
  os.system("pip install --upgrade torch==1.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html")
4
  except Exception as e:
5
  print(e)
6
-
7
  from pydoc import describe
8
  from huggingface_hub import hf_hub_download
9
  import gradio as gr
@@ -12,11 +12,17 @@ import os
12
  import datetime
13
  from PIL import Image
14
  from remove_bg import RemoveBackground
15
- import torch
 
 
 
 
 
 
16
 
17
  net_C = hf_hub_download("radames/PIFu-upright-standing", filename="net_C")
18
  net_G = hf_hub_download("radames/PIFu-upright-standing", filename="net_G")
19
- torch.hub.load('pytorch/vision:v0.6.0', 'deeplabv3_resnet101', pretrained=True)
20
 
21
  remove_bg = RemoveBackground()
22
 
@@ -32,11 +38,18 @@ def process(img_path):
32
  base = os.path.basename(img_path)
33
  img_name = os.path.splitext(base)[0]
34
  print("image name", img_name)
35
- img = Image.open(img_path)
 
 
 
 
36
  # remove background
37
  print("Removeing background")
38
- foreground = Image.fromarray(remove_bg.inference(img), 'RGBA')
39
- foreground.save("./PIFu/inputs/" + img_name + ".png")
 
 
 
40
  print("Aliging mask with input training image")
41
  subprocess.Popen(["python", "./apps/crop_img.py", "--input_image",
42
  f'./inputs/{img_name}.png', "--out_path", "./inputs"], cwd="PIFu").communicate()
@@ -84,12 +97,12 @@ The pre-trained model has the following warning:
84
  iface = gr.Interface(
85
  fn=process,
86
  description=description,
87
- inputs=gr.Image(type="filepath", label="Input"),
88
- outputs=gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0]),
89
  examples=examples,
90
  allow_flagging="never",
91
  cache_examples=True
92
  )
93
 
94
  if __name__ == "__main__":
95
- iface.launch(debug=True, enable_queue=True)
 
1
  import os
2
+ try:
3
  os.system("pip install --upgrade torch==1.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html")
4
  except Exception as e:
5
  print(e)
6
+
7
  from pydoc import describe
8
  from huggingface_hub import hf_hub_download
9
  import gradio as gr
 
12
  import datetime
13
  from PIL import Image
14
  from remove_bg import RemoveBackground
15
+ import torch, torchvision, skimage
16
+
17
+ print(
18
+ "torch: ", torch.__version__,
19
+ "\ntorchvision: ",torchvision.__version__,
20
+ "\nskimage:", skimage.__version__
21
+ )
22
 
23
  net_C = hf_hub_download("radames/PIFu-upright-standing", filename="net_C")
24
  net_G = hf_hub_download("radames/PIFu-upright-standing", filename="net_G")
25
+ torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
26
 
27
  remove_bg = RemoveBackground()
28
 
 
38
  base = os.path.basename(img_path)
39
  img_name = os.path.splitext(base)[0]
40
  print("image name", img_name)
41
+ img_raw = Image.open(img_path)
42
+ img = img_raw.resize(
43
+ (800, int(800 * img_raw.size[1] / img_raw.size[0])),
44
+ Image.Resampling.LANCZOS)
45
+
46
  # remove background
47
  print("Removeing background")
48
+ try:
49
+ foreground = Image.fromarray(remove_bg.inference(img), 'RGBA')
50
+ foreground.save("./PIFu/inputs/" + img_name + ".png")
51
+ except Exception as e:
52
+ print(e)
53
  print("Aliging mask with input training image")
54
  subprocess.Popen(["python", "./apps/crop_img.py", "--input_image",
55
  f'./inputs/{img_name}.png', "--out_path", "./inputs"], cwd="PIFu").communicate()
 
97
  iface = gr.Interface(
98
  fn=process,
99
  description=description,
100
+ inputs=gr.Image(type="filepath", label="Input Image"),
101
+ outputs=gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"),
102
  examples=examples,
103
  allow_flagging="never",
104
  cache_examples=True
105
  )
106
 
107
  if __name__ == "__main__":
108
+ iface.launch(debug=True, enable_queue=False)
remove_bg.py CHANGED
@@ -6,7 +6,7 @@ from torchvision import transforms
6
 
7
  class RemoveBackground(object):
8
  def __init__(self):
9
- self.model = torch.hub.load('pytorch/vision:v0.6.0', 'deeplabv3_resnet101', pretrained=True)
10
  self.model.eval()
11
 
12
  def make_transparent_foreground(self, pic, mask):
 
6
 
7
  class RemoveBackground(object):
8
  def __init__(self):
9
+ self.model = torch.hub.load('pytorch/vision:v0.10.0', 'deeplabv3_resnet101', pretrained=True)
10
  self.model.eval()
11
 
12
  def make_transparent_foreground(self, pic, mask):
requirements.txt CHANGED
@@ -4,19 +4,19 @@ imageio==2.8.0
4
  kiwisolver==1.1.0
5
  matplotlib==3.1.3
6
  networkx==2.4
7
- numpy==1.18.1
8
- opencv-python==4.2.0.32
9
- Pillow==9.0.0
10
- PyOpenGL==3.1.5
11
  pyparsing==2.4.6
12
  python-dateutil==2.8.1
13
  PyWavelets==1.1.1
14
- scikit-image
 
15
  scipy==1.4.1
16
  Shapely==1.7.0
17
  six==1.14.0
18
- tqdm==4.43.0
 
19
  trimesh==3.5.23
20
- xxhash==1.4.3
21
- torch==1.11
22
- torchvision==0.12.0
 
4
  kiwisolver==1.1.0
5
  matplotlib==3.1.3
6
  networkx==2.4
7
+ numpy==1.21.6
8
+ opencv-python==4.1.2.30
9
+ Pillow==9.1.0
10
+ PyOpenGL==3.1.6
11
  pyparsing==2.4.6
12
  python-dateutil==2.8.1
13
  PyWavelets==1.1.1
14
+ scikit-image==0.18.3
15
+ scikit-learn==1.0.2
16
  scipy==1.4.1
17
  Shapely==1.7.0
18
  six==1.14.0
19
+ torch==1.4.0
20
+ torchvision==0.5.0
21
  trimesh==3.5.23
22
+ tqdm==4.64.0