sfmig commited on
Commit
17145cb
1 Parent(s): e0235fd
Files changed (2) hide show
  1. app.py +8 -3
  2. 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(image):
 
 
 
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
- # This file may be used to create an environment using:
2
- # $ conda create --name <env> --file <this file>
3
- # platform: osx-64
4
- absl-py=1.1.0=pypi_0
5
- aiohttp=3.8.1=pypi_0
6
- aiosignal=1.2.0=pypi_0
7
- analytics-python=1.4.0=pypi_0
8
- anyio=3.6.1=pypi_0
9
- astunparse=1.6.3=pypi_0
10
- async-timeout=4.0.2=pypi_0
11
- asynctest=0.13.0=pypi_0
12
- attrs=21.4.0=pypi_0
13
- backoff=1.10.0=pypi_0
14
- bcrypt=3.2.2=pypi_0
15
- ca-certificates=2022.4.26=hecd8cb5_0
16
- cachetools=5.2.0=pypi_0
17
- certifi=2022.6.15=py37hecd8cb5_0
18
- cffi=1.15.1=pypi_0
19
- charset-normalizer=2.1.0=pypi_0
20
- click=8.1.3=pypi_0
21
- cryptography=37.0.2=pypi_0
22
- cycler=0.11.0=pypi_0
23
- fastapi=0.78.0=pypi_0
24
- ffmpy=0.3.0=pypi_0
25
- filelock=3.7.1=pypi_0
26
- flatbuffers=1.12=pypi_0
27
- fonttools=4.33.3=pypi_0
28
- freetype=2.11.0=hd8bbffd_0
29
- frozenlist=1.3.0=pypi_0
30
- fsspec=2022.5.0=pypi_0
31
- gast=0.4.0=pypi_0
32
- google-auth=2.9.0=pypi_0
33
- google-auth-oauthlib=0.4.6=pypi_0
34
- google-pasta=0.2.0=pypi_0
35
- gradio=3.0.24=pypi_0
36
- grpcio=1.47.0=pypi_0
37
- h11=0.12.0=pypi_0
38
- h5py=3.7.0=pypi_0
39
- httpcore=0.15.0=pypi_0
40
- httpx=0.23.0=pypi_0
41
- huggingface-hub=0.8.1=pypi_0
42
- idna=3.3=pypi_0
43
- importlib-metadata=4.12.0=pypi_0
44
- jinja2=3.1.2=pypi_0
45
- jpeg=9e=hca72f7f_0
46
- keras=2.9.0=pypi_0
47
- keras-preprocessing=1.1.2=pypi_0
48
- kiwisolver=1.4.3=pypi_0
49
- lcms2=2.12=hf1fd2bf_0
50
- libclang=14.0.1=pypi_0
51
- libcxx=12.0.0=h2f01273_0
52
- libedit=3.1.20210910=hca72f7f_0
53
- libffi=3.2.1=h0a44026_1007
54
- libpng=1.6.37=ha441bb4_0
55
- libtiff=4.2.0=hdb42f99_1
56
- libwebp-base=1.2.2=hca72f7f_0
57
- linkify-it-py=1.0.3=pypi_0
58
- lz4-c=1.9.3=h23ab428_1
59
- markdown=3.3.7=pypi_0
60
- markdown-it-py=2.1.0=pypi_0
61
- markupsafe=2.1.1=pypi_0
62
- matplotlib=3.5.2=pypi_0
63
- mdit-py-plugins=0.3.0=pypi_0
64
- mdurl=0.1.1=pypi_0
65
- monotonic=1.6=pypi_0
66
- multidict=6.0.2=pypi_0
67
- ncurses=6.3=hca72f7f_2
68
- numpy=1.21.6=pypi_0
69
- oauthlib=3.2.0=pypi_0
70
- olefile=0.46=py37_0
71
- openssl=1.1.1p=hca72f7f_0
72
- opt-einsum=3.3.0=pypi_0
73
- orjson=3.7.6=pypi_0
74
- packaging=21.3=pypi_0
75
- pandas=1.3.5=pypi_0
76
- paramiko=2.11.0=pypi_0
77
- pillow=7.2.0=py37hf860fee_2
78
- pip=22.1.2=pypi_0
79
- protobuf=3.19.4=pypi_0
80
- pyasn1=0.4.8=pypi_0
81
- pyasn1-modules=0.2.8=pypi_0
82
- pycparser=2.21=pypi_0
83
- pycryptodome=3.15.0=pypi_0
84
- pydantic=1.9.1=pypi_0
85
- pydub=0.25.1=pypi_0
86
- pynacl=1.5.0=pypi_0
87
- pyparsing=3.0.9=pypi_0
88
- python=3.7.6=h359304d_2
89
- python-dateutil=2.8.2=pypi_0
90
- python-multipart=0.0.5=pypi_0
91
- python_abi=3.7=1_cp37m
92
- pytz=2022.1=pypi_0
93
- pyyaml=6.0=pypi_0
94
- readline=7.0=h1de35cc_5
95
- regex=2022.6.2=pypi_0
96
- requests=2.28.1=pypi_0
97
- requests-oauthlib=1.3.1=pypi_0
98
- rfc3986=1.5.0=pypi_0
99
- rsa=4.8=pypi_0
100
- setuptools=61.2.0=py37hecd8cb5_0
101
- six=1.16.0=pypi_0
102
- sniffio=1.2.0=pypi_0
103
- sqlite=3.33.0=hffcf06c_0
104
- starlette=0.19.1=pypi_0
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