Spaces:
Runtime error
Runtime error
sfmig
commited on
Commit
•
17145cb
1
Parent(s):
e0235fd
fixes
Browse files- app.py +8 -3
- requirements.txt +104 -131
app.py
CHANGED
@@ -176,12 +176,15 @@ model = DetrForSegmentation.from_pretrained('facebook/detr-resnet-50-panoptic')
|
|
176 |
input = gr.inputs.Image()
|
177 |
output = gr.outputs.Image()
|
178 |
|
179 |
-
def predict_animal_mask(
|
|
|
|
|
|
|
180 |
inputs = feature_extractor(images=image, return_tensors="pt") #pt=Pytorch, tf=TensorFlow
|
181 |
outputs = model(**inputs)
|
182 |
-
logits = outputs.logits
|
183 |
bboxes = outputs.pred_boxes
|
184 |
-
masks = outputs.pred_masks
|
185 |
|
186 |
# postprocess the image
|
187 |
label_per_pixel = torch.argmax(masks.squeeze(),dim=0).detach().numpy()
|
@@ -193,6 +196,8 @@ def predict_animal_mask(image):
|
|
193 |
pred_img = np.array(image.convert('RGB'))*0.5 + color_mask*0.5
|
194 |
pred_img = pred_img.astype(np.uint8)
|
195 |
|
|
|
|
|
196 |
|
197 |
####################################################
|
198 |
# Create user interface and launch
|
|
|
176 |
input = gr.inputs.Image()
|
177 |
output = gr.outputs.Image()
|
178 |
|
179 |
+
def predict_animal_mask(im):
|
180 |
+
image = Image.fromarray(im) # im: numpy array 3d: 480, 640, 3: to PIL Image
|
181 |
+
image = image.resize((200,200)) # PIL image # could I upsample output instead? better?
|
182 |
+
|
183 |
inputs = feature_extractor(images=image, return_tensors="pt") #pt=Pytorch, tf=TensorFlow
|
184 |
outputs = model(**inputs)
|
185 |
+
logits = outputs.logits # torch.Size([1, 100, 251])
|
186 |
bboxes = outputs.pred_boxes
|
187 |
+
masks = outputs.pred_masks # torch.Size([1, 100, 200, 200])
|
188 |
|
189 |
# postprocess the image
|
190 |
label_per_pixel = torch.argmax(masks.squeeze(),dim=0).detach().numpy()
|
|
|
196 |
pred_img = np.array(image.convert('RGB'))*0.5 + color_mask*0.5
|
197 |
pred_img = pred_img.astype(np.uint8)
|
198 |
|
199 |
+
return pred_img
|
200 |
+
|
201 |
|
202 |
####################################################
|
203 |
# Create user interface and launch
|
requirements.txt
CHANGED
@@ -1,131 +1,104 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
tensorboard=2.9.1=pypi_0
|
106 |
-
tensorboard-data-server=0.6.1=pypi_0
|
107 |
-
tensorboard-plugin-wit=1.8.1=pypi_0
|
108 |
-
tensorflow=2.9.1=pypi_0
|
109 |
-
tensorflow-estimator=2.9.0=pypi_0
|
110 |
-
tensorflow-io-gcs-filesystem=0.26.0=pypi_0
|
111 |
-
termcolor=1.1.0=pypi_0
|
112 |
-
timm=0.5.4=pypi_0
|
113 |
-
tk=8.6.12=h5d9f67b_0
|
114 |
-
tokenizers=0.12.1=pypi_0
|
115 |
-
torch=1.12.0=pypi_0
|
116 |
-
torchaudio=0.12.0=pypi_0
|
117 |
-
torchvision=0.13.0=pypi_0
|
118 |
-
tqdm=4.64.0=pypi_0
|
119 |
-
transformers=4.20.1=pypi_0
|
120 |
-
typing-extensions=4.3.0=pypi_0
|
121 |
-
uc-micro-py=1.0.1=pypi_0
|
122 |
-
urllib3=1.26.9=pypi_0
|
123 |
-
uvicorn=0.18.2=pypi_0
|
124 |
-
werkzeug=2.1.2=pypi_0
|
125 |
-
wheel=0.37.1=pyhd3eb1b0_0
|
126 |
-
wrapt=1.14.1=pypi_0
|
127 |
-
xz=5.2.5=hca72f7f_1
|
128 |
-
yarl=1.7.2=pypi_0
|
129 |
-
zipp=3.8.0=pypi_0
|
130 |
-
zlib=1.2.12=h4dc903c_2
|
131 |
-
zstd=1.5.2=hcb37349_0
|
|
|
1 |
+
absl-py==1.1.0
|
2 |
+
aiohttp==3.8.1
|
3 |
+
aiosignal==1.2.0
|
4 |
+
analytics-python==1.4.0
|
5 |
+
anyio==3.6.1
|
6 |
+
astunparse==1.6.3
|
7 |
+
async-timeout==4.0.2
|
8 |
+
asynctest==0.13.0
|
9 |
+
attrs==21.4.0
|
10 |
+
backoff==1.10.0
|
11 |
+
bcrypt==3.2.2
|
12 |
+
cachetools==5.2.0
|
13 |
+
certifi @ file:///private/var/folders/sy/f16zz6x50xz3113nwtb9bvq00000gp/T/abs_83242e7e-f82d-4a71-8ef2-9d71d212d249gu_wxmeq/croots/recipe/certifi_1655968827803/work/certifi
|
14 |
+
cffi==1.15.1
|
15 |
+
charset-normalizer==2.1.0
|
16 |
+
click==8.1.3
|
17 |
+
cryptography==37.0.2
|
18 |
+
cycler==0.11.0
|
19 |
+
fastapi==0.78.0
|
20 |
+
ffmpy==0.3.0
|
21 |
+
filelock==3.7.1
|
22 |
+
flatbuffers==1.12
|
23 |
+
fonttools==4.33.3
|
24 |
+
frozenlist==1.3.0
|
25 |
+
fsspec==2022.5.0
|
26 |
+
gast==0.4.0
|
27 |
+
google-auth==2.9.0
|
28 |
+
google-auth-oauthlib==0.4.6
|
29 |
+
google-pasta==0.2.0
|
30 |
+
gradio==3.0.24
|
31 |
+
grpcio==1.47.0
|
32 |
+
h11==0.12.0
|
33 |
+
h5py==3.7.0
|
34 |
+
httpcore==0.15.0
|
35 |
+
httpx==0.23.0
|
36 |
+
huggingface-hub==0.8.1
|
37 |
+
idna==3.3
|
38 |
+
importlib-metadata==4.12.0
|
39 |
+
Jinja2==3.1.2
|
40 |
+
keras==2.9.0
|
41 |
+
Keras-Preprocessing==1.1.2
|
42 |
+
kiwisolver==1.4.3
|
43 |
+
libclang==14.0.1
|
44 |
+
linkify-it-py==1.0.3
|
45 |
+
Markdown==3.3.7
|
46 |
+
markdown-it-py==2.1.0
|
47 |
+
MarkupSafe==2.1.1
|
48 |
+
matplotlib==3.5.2
|
49 |
+
mdit-py-plugins==0.3.0
|
50 |
+
mdurl==0.1.1
|
51 |
+
monotonic==1.6
|
52 |
+
multidict==6.0.2
|
53 |
+
numpy==1.21.6
|
54 |
+
oauthlib==3.2.0
|
55 |
+
olefile==0.46
|
56 |
+
opt-einsum==3.3.0
|
57 |
+
orjson==3.7.6
|
58 |
+
packaging==21.3
|
59 |
+
pandas==1.3.5
|
60 |
+
paramiko==2.11.0
|
61 |
+
Pillow @ file:///Users/runner/miniforge3/conda-bld/pillow_1602493105252/work
|
62 |
+
protobuf==3.19.4
|
63 |
+
pyasn1==0.4.8
|
64 |
+
pyasn1-modules==0.2.8
|
65 |
+
pycparser==2.21
|
66 |
+
pycryptodome==3.15.0
|
67 |
+
pydantic==1.9.1
|
68 |
+
pydub==0.25.1
|
69 |
+
PyNaCl==1.5.0
|
70 |
+
pyparsing==3.0.9
|
71 |
+
python-dateutil==2.8.2
|
72 |
+
python-multipart==0.0.5
|
73 |
+
pytz==2022.1
|
74 |
+
PyYAML==6.0
|
75 |
+
regex==2022.6.2
|
76 |
+
requests==2.28.1
|
77 |
+
requests-oauthlib==1.3.1
|
78 |
+
rfc3986==1.5.0
|
79 |
+
rsa==4.8
|
80 |
+
six==1.16.0
|
81 |
+
sniffio==1.2.0
|
82 |
+
starlette==0.19.1
|
83 |
+
tensorboard==2.9.1
|
84 |
+
tensorboard-data-server==0.6.1
|
85 |
+
tensorboard-plugin-wit==1.8.1
|
86 |
+
tensorflow==2.9.1
|
87 |
+
tensorflow-estimator==2.9.0
|
88 |
+
tensorflow-io-gcs-filesystem==0.26.0
|
89 |
+
termcolor==1.1.0
|
90 |
+
timm==0.5.4
|
91 |
+
tokenizers==0.12.1
|
92 |
+
torch==1.12.0
|
93 |
+
torchaudio==0.12.0
|
94 |
+
torchvision==0.13.0
|
95 |
+
tqdm==4.64.0
|
96 |
+
transformers==4.20.1
|
97 |
+
typing_extensions==4.3.0
|
98 |
+
uc-micro-py==1.0.1
|
99 |
+
urllib3==1.26.9
|
100 |
+
uvicorn==0.18.2
|
101 |
+
Werkzeug==2.1.2
|
102 |
+
wrapt==1.14.1
|
103 |
+
yarl==1.7.2
|
104 |
+
zipp==3.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|