Spaces:
Sleeping
Sleeping
Yuxiang Wang
commited on
Commit
·
97f07be
1
Parent(s):
6e2a000
feat:add env.py,try downgrade pytorch version
Browse files- app.py +3 -51
- env.py +65 -0
- inference_sam.py +1 -0
- model/.gitattributes +0 -35
- model/README.md +0 -37
- model/sam_02-06_dice_mse_0.pth +0 -1
app.py
CHANGED
@@ -1,64 +1,16 @@
|
|
1 |
|
2 |
-
import subprocess
|
3 |
import os
|
4 |
import sys
|
5 |
-
import
|
6 |
|
7 |
-
def is_pkg_installed(pkg_name):
|
8 |
-
try:
|
9 |
-
importlib.metadata.distribution(pkg_name)
|
10 |
-
return True
|
11 |
-
except importlib.metadata.PackageNotFoundError:
|
12 |
-
return False
|
13 |
|
14 |
-
|
15 |
-
('gradio',None),
|
16 |
-
('numpy',None),
|
17 |
-
('tensorflow', '2.9'),
|
18 |
-
('keras', '2.9'),
|
19 |
-
('opencv-python-headless', '4.5.5.64'),
|
20 |
-
('python-dotenv', None),
|
21 |
-
('torch', None),
|
22 |
-
('torchvision', None),
|
23 |
-
('xplique', None),
|
24 |
-
('git+https://github.com/facebookresearch/segment-anything.git', None),
|
25 |
-
('git+https://github.com/cocodataset/panopticapi.git', None),
|
26 |
-
]
|
27 |
|
28 |
-
env_name = os.path.basename(sys.prefix)
|
29 |
-
if env_name == 'fossil': # in case pkgs installed to unexpected env during local dev
|
30 |
-
for package, version in packages_to_install:
|
31 |
-
package_spec = f"{package}=={version}" if version else package
|
32 |
-
if not is_pkg_installed(package):
|
33 |
-
#TODO
|
34 |
-
if package=='torch' or 'torchvision' or 'tensorflow':
|
35 |
-
subprocess.call(f"TMPDIR='../../../tmp/' pip install {package_spec}",shell=True)
|
36 |
-
else:
|
37 |
-
subprocess.call(f"pip install {package_spec}".split())
|
38 |
-
else:
|
39 |
-
print(f"{package_spec} is already installed.")
|
40 |
-
else:
|
41 |
-
print("Please use venv named 'fossil' in case pkgs installed to other unexpected envs or locations.")
|
42 |
-
|
43 |
-
|
44 |
-
#print(os.getenv('SYSTEM'))
|
45 |
-
|
46 |
-
'''
|
47 |
-
if os.getenv('SYSTEM') == 'spaces':
|
48 |
-
subprocess.call('pip install tensorflow==2.9'.split())
|
49 |
-
subprocess.call('pip install keras==2.9'.split())
|
50 |
-
subprocess.call('pip install git+https://github.com/facebookresearch/segment-anything.git'.split())
|
51 |
-
subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
|
52 |
-
subprocess.call('pip install git+https://github.com/cocodataset/panopticapi.git'.split())
|
53 |
-
subprocess.call('pip install python-dotenv'.split())
|
54 |
-
subprocess.call('pip install torch torchvision '.split())
|
55 |
-
subprocess.call('pip install xplique'.split())
|
56 |
-
'''
|
57 |
|
58 |
import gradio as gr
|
59 |
from huggingface_hub import snapshot_download
|
60 |
import cv2
|
61 |
-
import dotenv
|
62 |
dotenv.load_dotenv()
|
63 |
import numpy as np
|
64 |
import gradio as gr
|
|
|
1 |
|
|
|
2 |
import os
|
3 |
import sys
|
4 |
+
from env import config_env
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
config_env()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
import gradio as gr
|
11 |
from huggingface_hub import snapshot_download
|
12 |
import cv2
|
13 |
+
import dotenv
|
14 |
dotenv.load_dotenv()
|
15 |
import numpy as np
|
16 |
import gradio as gr
|
env.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import importlib.metadata
|
4 |
+
|
5 |
+
|
6 |
+
def config_env():
|
7 |
+
packages_to_install = [
|
8 |
+
('gradio',None),
|
9 |
+
('numpy',None),
|
10 |
+
('tensorflow', '2.9'),
|
11 |
+
('keras', '2.9'),
|
12 |
+
('opencv-python-headless', '4.5.5.64'),
|
13 |
+
('python-dotenv', None),
|
14 |
+
('torch', None),
|
15 |
+
('torchvision', None),
|
16 |
+
('xplique', None),
|
17 |
+
('segment_anything', None),
|
18 |
+
('panopticapi', None),
|
19 |
+
]
|
20 |
+
|
21 |
+
name_to_command = {'segment_anything':'git+https://github.com/facebookresearch/segment-anything.git',
|
22 |
+
'panopticapi':'git+https://github.com/cocodataset/panopticapi.git',
|
23 |
+
'torch':'torch --index-url https://download.pytorch.org/whl/cu118',
|
24 |
+
'torchvision':'torchvision --index-url https://download.pytorch.org/whl/cu118',
|
25 |
+
}
|
26 |
+
|
27 |
+
env_name = os.path.basename(sys.prefix)
|
28 |
+
if env_name == 'fossil': # in case pkgs installed to unexpected env during local dev
|
29 |
+
for package, version in packages_to_install:
|
30 |
+
package_spec = f"{package}=={version}" if version else package
|
31 |
+
package_spec = name_to_command[package_spec] if package_spec in name_to_command
|
32 |
+
if not is_pkg_installed(package):
|
33 |
+
#TODO
|
34 |
+
if package=='torch' or 'torchvision' or 'tensorflow':
|
35 |
+
# TMPDIR = 'home/username/tmp' for temporary compilation to prevent disk partition storage limit on zmachine
|
36 |
+
subprocess.call(f"TMPDIR='../../../tmp/' pip install {package_spec}",shell=True)
|
37 |
+
else:
|
38 |
+
subprocess.call(f"pip install {package_spec}".split())
|
39 |
+
else:
|
40 |
+
print(f"{package_spec} is already installed.")
|
41 |
+
else:
|
42 |
+
print("Please use venv named 'fossil' in case pkgs installed to other unexpected envs or locations.")
|
43 |
+
|
44 |
+
|
45 |
+
#print(os.getenv('SYSTEM'))
|
46 |
+
|
47 |
+
'''
|
48 |
+
if os.getenv('SYSTEM') == 'spaces':
|
49 |
+
subprocess.call('pip install tensorflow==2.9'.split())
|
50 |
+
subprocess.call('pip install keras==2.9'.split())
|
51 |
+
subprocess.call('pip install git+https://github.com/facebookresearch/segment-anything.git'.split())
|
52 |
+
subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
|
53 |
+
subprocess.call('pip install git+https://github.com/cocodataset/panopticapi.git'.split())
|
54 |
+
subprocess.call('pip install python-dotenv'.split())
|
55 |
+
subprocess.call('pip install torch torchvision '.split())
|
56 |
+
subprocess.call('pip install xplique'.split())
|
57 |
+
'''
|
58 |
+
|
59 |
+
|
60 |
+
def is_pkg_installed(pkg_name):
|
61 |
+
try:
|
62 |
+
importlib.metadata.distribution(pkg_name)
|
63 |
+
return True
|
64 |
+
except importlib.metadata.PackageNotFoundError:
|
65 |
+
return False
|
inference_sam.py
CHANGED
@@ -26,6 +26,7 @@ from huggingface_hub import snapshot_download
|
|
26 |
if not os.path.exists('model'):
|
27 |
REPO_ID='Serrelab/SAM_Leaves'
|
28 |
token = os.environ.get('READ_TOKEN')
|
|
|
29 |
if token is None:
|
30 |
print("warning! A read token in env variables is needed for authentication.")
|
31 |
snapshot_download(repo_id=REPO_ID, token=token,repo_type='model',local_dir='model')
|
|
|
26 |
if not os.path.exists('model'):
|
27 |
REPO_ID='Serrelab/SAM_Leaves'
|
28 |
token = os.environ.get('READ_TOKEN')
|
29 |
+
print(f"Read token:{token}")
|
30 |
if token is None:
|
31 |
print("warning! A read token in env variables is needed for authentication.")
|
32 |
snapshot_download(repo_id=REPO_ID, token=token,repo_type='model',local_dir='model')
|
model/.gitattributes
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model/README.md
DELETED
@@ -1,37 +0,0 @@
|
|
1 |
-
---
|
2 |
-
license: bigscience-openrail-m
|
3 |
-
language:
|
4 |
-
- en
|
5 |
-
pipeline_tag: image-segmentation
|
6 |
-
---
|
7 |
-
# Model Card for Model ID
|
8 |
-
|
9 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
10 |
-
|
11 |
-
This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
|
12 |
-
|
13 |
-
## Model Details
|
14 |
-
|
15 |
-
SAM trained with MSE and finetuned for leaves segmentation
|
16 |
-
|
17 |
-
### Model Description
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
- **Developed by:** Thomas Fel and I . Rodriguez
|
23 |
-
|
24 |
-
- **Model type:** Semantic Segmentation
|
25 |
-
- **Language(s) (NLP):** [More Information Needed]
|
26 |
-
|
27 |
-
|
28 |
-
### Model Sources [optional]
|
29 |
-
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model/sam_02-06_dice_mse_0.pth
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
../../../../.cache/huggingface/hub/models--Serrelab--SAM_Leaves/blobs/920cc0f6b6d80b8dcd771cb39bdec6c6be9c44cc6fc95314ef20025b71e55a73
|
|
|
|