myrad01 RysonFeng commited on
Commit
b09c1e6
0 Parent(s):

Duplicate from InpaintAI/Inpaint-Anything

Browse files

Co-authored-by: RunsenFeng <RysonFeng@users.noreply.huggingface.co>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +39 -0
  2. .gitignore +12 -0
  3. LICENSE +201 -0
  4. README.md +14 -0
  5. __init__.py +0 -0
  6. app.py +231 -0
  7. fill_anything.py +128 -0
  8. lama_inpaint.py +205 -0
  9. pretrained_models/.gitkeep +1 -0
  10. pretrained_models/big-lama/config.yaml +3 -0
  11. pretrained_models/big-lama/models/best.ckpt +3 -0
  12. pretrained_models/sam_vit_h_4b8939.pth +3 -0
  13. remove_anything.py +122 -0
  14. replace_anything.py +126 -0
  15. requirements.txt +23 -0
  16. sam_segment.py +127 -0
  17. stable_diffusion_inpaint.py +117 -0
  18. third_party/.gitkeep +1 -0
  19. third_party/lama/.gitignore +3 -0
  20. third_party/lama/LICENSE +3 -0
  21. third_party/lama/README.md +3 -0
  22. third_party/lama/bin/analyze_errors.py +3 -0
  23. third_party/lama/bin/blur_predicts.py +3 -0
  24. third_party/lama/bin/calc_dataset_stats.py +3 -0
  25. third_party/lama/bin/debug/analyze_overlapping_masks.sh +3 -0
  26. third_party/lama/bin/evaluate_predicts.py +3 -0
  27. third_party/lama/bin/evaluator_example.py +3 -0
  28. third_party/lama/bin/extract_masks.py +3 -0
  29. third_party/lama/bin/filter_sharded_dataset.py +3 -0
  30. third_party/lama/bin/gen_debug_mask_dataset.py +3 -0
  31. third_party/lama/bin/gen_mask_dataset.py +3 -0
  32. third_party/lama/bin/gen_mask_dataset_hydra.py +3 -0
  33. third_party/lama/bin/gen_outpainting_dataset.py +3 -0
  34. third_party/lama/bin/make_checkpoint.py +3 -0
  35. third_party/lama/bin/mask_example.py +3 -0
  36. third_party/lama/bin/paper_runfiles/blur_tests.sh +3 -0
  37. third_party/lama/bin/paper_runfiles/env.sh +3 -0
  38. third_party/lama/bin/paper_runfiles/find_best_checkpoint.py +3 -0
  39. third_party/lama/bin/paper_runfiles/generate_test_celeba-hq.sh +3 -0
  40. third_party/lama/bin/paper_runfiles/generate_test_ffhq.sh +3 -0
  41. third_party/lama/bin/paper_runfiles/generate_test_paris.sh +3 -0
  42. third_party/lama/bin/paper_runfiles/generate_test_paris_256.sh +3 -0
  43. third_party/lama/bin/paper_runfiles/generate_val_test.sh +3 -0
  44. third_party/lama/bin/paper_runfiles/predict_inner_features.sh +3 -0
  45. third_party/lama/bin/paper_runfiles/update_test_data_stats.sh +3 -0
  46. third_party/lama/bin/predict.py +3 -0
  47. third_party/lama/bin/predict_inner_features.py +3 -0
  48. third_party/lama/bin/report_from_tb.py +3 -0
  49. third_party/lama/bin/sample_from_dataset.py +3 -0
  50. third_party/lama/bin/side_by_side.py +3 -0
.gitattributes ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ **.png filter=lfs diff=lfs merge=lfs -text
36
+ **.gif filter=lfs diff=lfs merge=lfs -text
37
+ **.jpg filter=lfs diff=lfs merge=lfs -text
38
+ third_party/** filter=lfs diff=lfs merge=lfs -text
39
+ pretrained_models/** filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python byte code, etc.
2
+ __pycache__/
3
+
4
+ # C/C++ object files/libraries
5
+ *.o
6
+ *.so
7
+
8
+ # macOS
9
+ **/.DS_Store
10
+
11
+ # tmp
12
+ ~*
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Inpaint Anything
3
+ emoji: ⚡
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: InpaintAI/Inpaint-Anything
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ # sys.path.append(os.path.abspath(os.path.dirname(os.getcwd())))
4
+ # os.chdir("../")
5
+ import gradio as gr
6
+ import numpy as np
7
+ from pathlib import Path
8
+ from matplotlib import pyplot as plt
9
+ import torch
10
+ import tempfile
11
+ from lama_inpaint import inpaint_img_with_lama, build_lama_model, inpaint_img_with_builded_lama
12
+ from utils import load_img_to_array, save_array_to_img, dilate_mask, \
13
+ show_mask, show_points
14
+ from PIL import Image
15
+ sys.path.insert(0, str(Path(__file__).resolve().parent / "third_party" / "segment-anything"))
16
+ from segment_anything import SamPredictor, sam_model_registry
17
+ import argparse
18
+
19
+ def setup_args(parser):
20
+ parser.add_argument(
21
+ "--lama_config", type=str,
22
+ default="./third_party/lama/configs/prediction/default.yaml",
23
+ help="The path to the config file of lama model. "
24
+ "Default: the config of big-lama",
25
+ )
26
+ parser.add_argument(
27
+ "--lama_ckpt", type=str,
28
+ default="pretrained_models/big-lama",
29
+ help="The path to the lama checkpoint.",
30
+ )
31
+ parser.add_argument(
32
+ "--sam_ckpt", type=str,
33
+ default="./pretrained_models/sam_vit_h_4b8939.pth",
34
+ help="The path to the SAM checkpoint to use for mask generation.",
35
+ )
36
+ def mkstemp(suffix, dir=None):
37
+ fd, path = tempfile.mkstemp(suffix=f"{suffix}", dir=dir)
38
+ os.close(fd)
39
+ return Path(path)
40
+
41
+
42
+ def get_sam_feat(img):
43
+ model['sam'].set_image(img)
44
+ features = model['sam'].features
45
+ orig_h = model['sam'].orig_h
46
+ orig_w = model['sam'].orig_w
47
+ input_h = model['sam'].input_h
48
+ input_w = model['sam'].input_w
49
+ model['sam'].reset_image()
50
+ return features, orig_h, orig_w, input_h, input_w
51
+
52
+
53
+ def get_masked_img(img, w, h, features, orig_h, orig_w, input_h, input_w, dilate_kernel_size):
54
+ point_coords = [w, h]
55
+ point_labels = [1]
56
+
57
+ model['sam'].is_image_set = True
58
+ model['sam'].features = features
59
+ model['sam'].orig_h = orig_h
60
+ model['sam'].orig_w = orig_w
61
+ model['sam'].input_h = input_h
62
+ model['sam'].input_w = input_w
63
+
64
+ # model['sam'].set_image(img) # todo : update here for accelerating
65
+ masks, _, _ = model['sam'].predict(
66
+ point_coords=np.array([point_coords]),
67
+ point_labels=np.array(point_labels),
68
+ multimask_output=True,
69
+ )
70
+
71
+ masks = masks.astype(np.uint8) * 255
72
+
73
+ # dilate mask to avoid unmasked edge effect
74
+ if dilate_kernel_size is not None:
75
+ masks = [dilate_mask(mask, dilate_kernel_size) for mask in masks]
76
+ else:
77
+ masks = [mask for mask in masks]
78
+
79
+ figs = []
80
+ for idx, mask in enumerate(masks):
81
+ # save the pointed and masked image
82
+ tmp_p = mkstemp(".png")
83
+ dpi = plt.rcParams['figure.dpi']
84
+ height, width = img.shape[:2]
85
+ fig = plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
86
+ plt.imshow(img)
87
+ plt.axis('off')
88
+ show_points(plt.gca(), [point_coords], point_labels,
89
+ size=(width*0.04)**2)
90
+ show_mask(plt.gca(), mask, random_color=False)
91
+ plt.tight_layout()
92
+ plt.savefig(tmp_p, bbox_inches='tight', pad_inches=0)
93
+ figs.append(fig)
94
+ plt.close()
95
+ return *figs, *masks
96
+
97
+
98
+ def get_inpainted_img(img, mask0, mask1, mask2):
99
+ lama_config = args.lama_config
100
+ device = "cuda" if torch.cuda.is_available() else "cpu"
101
+ out = []
102
+ for mask in [mask0, mask1, mask2]:
103
+ if len(mask.shape)==3:
104
+ mask = mask[:,:,0]
105
+ img_inpainted = inpaint_img_with_builded_lama(
106
+ model['lama'], img, mask, lama_config, device=device)
107
+ out.append(img_inpainted)
108
+ return out
109
+
110
+
111
+ # get args
112
+ parser = argparse.ArgumentParser()
113
+ setup_args(parser)
114
+ args = parser.parse_args(sys.argv[1:])
115
+ # build models
116
+ model = {}
117
+ # build the sam model
118
+ model_type="vit_h"
119
+ ckpt_p=args.sam_ckpt
120
+ model_sam = sam_model_registry[model_type](checkpoint=ckpt_p)
121
+ device = "cuda" if torch.cuda.is_available() else "cpu"
122
+ model_sam.to(device=device)
123
+ model['sam'] = SamPredictor(model_sam)
124
+
125
+ # build the lama model
126
+ lama_config = args.lama_config
127
+ lama_ckpt = args.lama_ckpt
128
+ device = "cuda" if torch.cuda.is_available() else "cpu"
129
+ model['lama'] = build_lama_model(lama_config, lama_ckpt, device=device)
130
+
131
+ button_size = (100,50)
132
+ with gr.Blocks() as demo:
133
+ features = gr.State(None)
134
+ orig_h = gr.State(None)
135
+ orig_w = gr.State(None)
136
+ input_h = gr.State(None)
137
+ input_w = gr.State(None)
138
+
139
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
140
+ with gr.Column(variant="panel"):
141
+ with gr.Row():
142
+ gr.Markdown("## Input Image")
143
+ with gr.Row():
144
+ img = gr.Image(label="Input Image").style(height="200px")
145
+ with gr.Column(variant="panel"):
146
+ with gr.Row():
147
+ gr.Markdown("## Pointed Image")
148
+ with gr.Row():
149
+ img_pointed = gr.Plot(label='Pointed Image')
150
+ with gr.Column(variant="panel"):
151
+ with gr.Row():
152
+ gr.Markdown("## Control Panel")
153
+ with gr.Row():
154
+ w = gr.Number(label="Point Coordinate W")
155
+ h = gr.Number(label="Point Coordinate H")
156
+ dilate_kernel_size = gr.Slider(label="Dilate Kernel Size", minimum=0, maximum=100, step=1, value=15)
157
+ sam_mask = gr.Button("Predict Mask", variant="primary").style(full_width=True, size="sm")
158
+ lama = gr.Button("Inpaint Image", variant="primary").style(full_width=True, size="sm")
159
+ clear_button_image = gr.Button(value="Reset", label="Reset", variant="secondary").style(full_width=True, size="sm")
160
+
161
+ # todo: maybe we can delete this row, for it's unnecessary to show the original mask for customers
162
+ with gr.Row(variant="panel"):
163
+ with gr.Column():
164
+ with gr.Row():
165
+ gr.Markdown("## Segmentation Mask")
166
+ with gr.Row():
167
+ mask_0 = gr.outputs.Image(type="numpy", label="Segmentation Mask 0").style(height="200px")
168
+ mask_1 = gr.outputs.Image(type="numpy", label="Segmentation Mask 1").style(height="200px")
169
+ mask_2 = gr.outputs.Image(type="numpy", label="Segmentation Mask 2").style(height="200px")
170
+
171
+ with gr.Row(variant="panel"):
172
+ with gr.Column():
173
+ with gr.Row():
174
+ gr.Markdown("## Image with Mask")
175
+ with gr.Row():
176
+ img_with_mask_0 = gr.Plot(label="Image with Segmentation Mask 0")
177
+ img_with_mask_1 = gr.Plot(label="Image with Segmentation Mask 1")
178
+ img_with_mask_2 = gr.Plot(label="Image with Segmentation Mask 2")
179
+
180
+ with gr.Row(variant="panel"):
181
+ with gr.Column():
182
+ with gr.Row():
183
+ gr.Markdown("## Image Removed with Mask")
184
+ with gr.Row():
185
+ img_rm_with_mask_0 = gr.outputs.Image(
186
+ type="numpy", label="Image Removed with Segmentation Mask 0").style(height="200px")
187
+ img_rm_with_mask_1 = gr.outputs.Image(
188
+ type="numpy", label="Image Removed with Segmentation Mask 1").style(height="200px")
189
+ img_rm_with_mask_2 = gr.outputs.Image(
190
+ type="numpy", label="Image Removed with Segmentation Mask 2").style(height="200px")
191
+
192
+
193
+ def get_select_coords(img, evt: gr.SelectData):
194
+ dpi = plt.rcParams['figure.dpi']
195
+ height, width = img.shape[:2]
196
+ fig = plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
197
+ plt.imshow(img)
198
+ plt.axis('off')
199
+ plt.tight_layout()
200
+ show_points(plt.gca(), [[evt.index[0], evt.index[1]]], [1],
201
+ size=(width*0.04)**2)
202
+ return evt.index[0], evt.index[1], fig
203
+
204
+ img.select(get_select_coords, [img], [w, h, img_pointed])
205
+ img.upload(get_sam_feat, [img], [features, orig_h, orig_w, input_h, input_w])
206
+
207
+ sam_mask.click(
208
+ get_masked_img,
209
+ [img, w, h, features, orig_h, orig_w, input_h, input_w, dilate_kernel_size],
210
+ [img_with_mask_0, img_with_mask_1, img_with_mask_2, mask_0, mask_1, mask_2]
211
+ )
212
+
213
+ lama.click(
214
+ get_inpainted_img,
215
+ [img, mask_0, mask_1, mask_2],
216
+ [img_rm_with_mask_0, img_rm_with_mask_1, img_rm_with_mask_2]
217
+ )
218
+
219
+
220
+ def reset(*args):
221
+ return [None for _ in args]
222
+
223
+ clear_button_image.click(
224
+ reset,
225
+ [img, features, img_pointed, w, h, mask_0, mask_1, mask_2, img_with_mask_0, img_with_mask_1, img_with_mask_2, img_rm_with_mask_0, img_rm_with_mask_1, img_rm_with_mask_2],
226
+ [img, features, img_pointed, w, h, mask_0, mask_1, mask_2, img_with_mask_0, img_with_mask_1, img_with_mask_2, img_rm_with_mask_0, img_rm_with_mask_1, img_rm_with_mask_2]
227
+ )
228
+
229
+ if __name__ == "__main__":
230
+ demo.launch()
231
+
fill_anything.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import sys
3
+ import argparse
4
+ import numpy as np
5
+ import torch
6
+ from pathlib import Path
7
+ from matplotlib import pyplot as plt
8
+ from typing import Any, Dict, List
9
+
10
+ from sam_segment import predict_masks_with_sam
11
+ from stable_diffusion_inpaint import fill_img_with_sd
12
+ from utils import load_img_to_array, save_array_to_img, dilate_mask, \
13
+ show_mask, show_points
14
+
15
+
16
+ def setup_args(parser):
17
+ parser.add_argument(
18
+ "--input_img", type=str, required=True,
19
+ help="Path to a single input img",
20
+ )
21
+ parser.add_argument(
22
+ "--point_coords", type=float, nargs='+', required=True,
23
+ help="The coordinate of the point prompt, [coord_W coord_H].",
24
+ )
25
+ parser.add_argument(
26
+ "--point_labels", type=int, nargs='+', required=True,
27
+ help="The labels of the point prompt, 1 or 0.",
28
+ )
29
+ parser.add_argument(
30
+ "--text_prompt", type=str, required=True,
31
+ help="Text prompt",
32
+ )
33
+ parser.add_argument(
34
+ "--dilate_kernel_size", type=int, default=None,
35
+ help="Dilate kernel size. Default: None",
36
+ )
37
+ parser.add_argument(
38
+ "--output_dir", type=str, required=True,
39
+ help="Output path to the directory with results.",
40
+ )
41
+ parser.add_argument(
42
+ "--sam_model_type", type=str,
43
+ default="vit_h", choices=['vit_h', 'vit_l', 'vit_b'],
44
+ help="The type of sam model to load. Default: 'vit_h"
45
+ )
46
+ parser.add_argument(
47
+ "--sam_ckpt", type=str, required=True,
48
+ help="The path to the SAM checkpoint to use for mask generation.",
49
+ )
50
+ parser.add_argument(
51
+ "--seed", type=int,
52
+ help="Specify seed for reproducibility.",
53
+ )
54
+ parser.add_argument(
55
+ "--deterministic", action="store_true",
56
+ help="Use deterministic algorithms for reproducibility.",
57
+ )
58
+
59
+
60
+
61
+ if __name__ == "__main__":
62
+ """Example usage:
63
+ python fill_anything.py \
64
+ --input_img FA_demo/FA1_dog.png \
65
+ --point_coords 750 500 \
66
+ --point_labels 1 \
67
+ --text_prompt "a teddy bear on a bench" \
68
+ --dilate_kernel_size 15 \
69
+ --output_dir ./results \
70
+ --sam_model_type "vit_h" \
71
+ --sam_ckpt sam_vit_h_4b8939.pth
72
+ """
73
+ parser = argparse.ArgumentParser()
74
+ setup_args(parser)
75
+ args = parser.parse_args(sys.argv[1:])
76
+ device = "cuda" if torch.cuda.is_available() else "cpu"
77
+
78
+ img = load_img_to_array(args.input_img)
79
+
80
+ masks, _, _ = predict_masks_with_sam(
81
+ img,
82
+ [args.point_coords],
83
+ args.point_labels,
84
+ model_type=args.sam_model_type,
85
+ ckpt_p=args.sam_ckpt,
86
+ device=device,
87
+ )
88
+ masks = masks.astype(np.uint8) * 255
89
+
90
+ # dilate mask to avoid unmasked edge effect
91
+ if args.dilate_kernel_size is not None:
92
+ masks = [dilate_mask(mask, args.dilate_kernel_size) for mask in masks]
93
+
94
+ # visualize the segmentation results
95
+ img_stem = Path(args.input_img).stem
96
+ out_dir = Path(args.output_dir) / img_stem
97
+ out_dir.mkdir(parents=True, exist_ok=True)
98
+ for idx, mask in enumerate(masks):
99
+ # path to the results
100
+ mask_p = out_dir / f"mask_{idx}.png"
101
+ img_points_p = out_dir / f"with_points.png"
102
+ img_mask_p = out_dir / f"with_{Path(mask_p).name}"
103
+
104
+ # save the mask
105
+ save_array_to_img(mask, mask_p)
106
+
107
+ # save the pointed and masked image
108
+ dpi = plt.rcParams['figure.dpi']
109
+ height, width = img.shape[:2]
110
+ plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
111
+ plt.imshow(img)
112
+ plt.axis('off')
113
+ show_points(plt.gca(), [args.point_coords], args.point_labels,
114
+ size=(width*0.04)**2)
115
+ plt.savefig(img_points_p, bbox_inches='tight', pad_inches=0)
116
+ show_mask(plt.gca(), mask, random_color=False)
117
+ plt.savefig(img_mask_p, bbox_inches='tight', pad_inches=0)
118
+ plt.close()
119
+
120
+ # fill the masked image
121
+ for idx, mask in enumerate(masks):
122
+ if args.seed is not None:
123
+ torch.manual_seed(args.seed)
124
+ mask_p = out_dir / f"mask_{idx}.png"
125
+ img_filled_p = out_dir / f"filled_with_{Path(mask_p).name}"
126
+ img_filled = fill_img_with_sd(
127
+ img, mask, args.text_prompt, device=device)
128
+ save_array_to_img(img_filled, img_filled_p)
lama_inpaint.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import numpy as np
4
+ import torch
5
+ import yaml
6
+ import glob
7
+ import argparse
8
+ from PIL import Image
9
+ from omegaconf import OmegaConf
10
+ from pathlib import Path
11
+
12
+ os.environ['OMP_NUM_THREADS'] = '1'
13
+ os.environ['OPENBLAS_NUM_THREADS'] = '1'
14
+ os.environ['MKL_NUM_THREADS'] = '1'
15
+ os.environ['VECLIB_MAXIMUM_THREADS'] = '1'
16
+ os.environ['NUMEXPR_NUM_THREADS'] = '1'
17
+
18
+ sys.path.insert(0, str(Path(__file__).resolve().parent / "third_party" / "lama"))
19
+
20
+ from saicinpainting.evaluation.utils import move_to_device
21
+ from saicinpainting.training.trainers import load_checkpoint
22
+ from saicinpainting.evaluation.data import pad_tensor_to_modulo
23
+
24
+ from utils import load_img_to_array, save_array_to_img
25
+
26
+
27
+ @torch.no_grad()
28
+ def inpaint_img_with_lama(
29
+ img: np.ndarray,
30
+ mask: np.ndarray,
31
+ config_p: str,
32
+ ckpt_p: str,
33
+ mod=8,
34
+ device="cuda"
35
+ ):
36
+ assert len(mask.shape) == 2
37
+ if np.max(mask) == 1:
38
+ mask = mask * 255
39
+ img = torch.from_numpy(img).float().div(255.)
40
+ mask = torch.from_numpy(mask).float()
41
+ predict_config = OmegaConf.load(config_p)
42
+ predict_config.model.path = ckpt_p
43
+ # device = torch.device(predict_config.device)
44
+ device = torch.device(device)
45
+
46
+ train_config_path = os.path.join(
47
+ predict_config.model.path, 'config.yaml')
48
+
49
+ with open(train_config_path, 'r') as f:
50
+ train_config = OmegaConf.create(yaml.safe_load(f))
51
+
52
+ train_config.training_model.predict_only = True
53
+ train_config.visualizer.kind = 'noop'
54
+
55
+ checkpoint_path = os.path.join(
56
+ predict_config.model.path, 'models',
57
+ predict_config.model.checkpoint
58
+ )
59
+ model = load_checkpoint(
60
+ train_config, checkpoint_path, strict=False, map_location=device)
61
+ model.freeze()
62
+ if not predict_config.get('refine', False):
63
+ model.to(device)
64
+
65
+ batch = {}
66
+ batch['image'] = img.permute(2, 0, 1).unsqueeze(0)
67
+ batch['mask'] = mask[None, None]
68
+ unpad_to_size = [batch['image'].shape[2], batch['image'].shape[3]]
69
+ batch['image'] = pad_tensor_to_modulo(batch['image'], mod)
70
+ batch['mask'] = pad_tensor_to_modulo(batch['mask'], mod)
71
+ batch = move_to_device(batch, device)
72
+ batch['mask'] = (batch['mask'] > 0) * 1
73
+
74
+ batch = model(batch)
75
+ cur_res = batch[predict_config.out_key][0].permute(1, 2, 0)
76
+ cur_res = cur_res.detach().cpu().numpy()
77
+
78
+ if unpad_to_size is not None:
79
+ orig_height, orig_width = unpad_to_size
80
+ cur_res = cur_res[:orig_height, :orig_width]
81
+
82
+ cur_res = np.clip(cur_res * 255, 0, 255).astype('uint8')
83
+ return cur_res
84
+
85
+
86
+ def build_lama_model(
87
+ config_p: str,
88
+ ckpt_p: str,
89
+ device="cuda"
90
+ ):
91
+ predict_config = OmegaConf.load(config_p)
92
+ predict_config.model.path = ckpt_p
93
+ # device = torch.device(predict_config.device)
94
+ device = torch.device(device)
95
+
96
+ train_config_path = os.path.join(
97
+ predict_config.model.path, 'config.yaml')
98
+
99
+ with open(train_config_path, 'r') as f:
100
+ train_config = OmegaConf.create(yaml.safe_load(f))
101
+
102
+ train_config.training_model.predict_only = True
103
+ train_config.visualizer.kind = 'noop'
104
+
105
+ checkpoint_path = os.path.join(
106
+ predict_config.model.path, 'models',
107
+ predict_config.model.checkpoint
108
+ )
109
+ model = load_checkpoint(
110
+ train_config, checkpoint_path, strict=False, map_location=device)
111
+ model.freeze()
112
+ if not predict_config.get('refine', False):
113
+ model.to(device)
114
+
115
+ return model
116
+
117
+
118
+ @torch.no_grad()
119
+ def inpaint_img_with_builded_lama(
120
+ model,
121
+ img: np.ndarray,
122
+ mask: np.ndarray,
123
+ config_p: str,
124
+ mod=8,
125
+ device="cuda"
126
+ ):
127
+ assert len(mask.shape) == 2
128
+ if np.max(mask) == 1:
129
+ mask = mask * 255
130
+ img = torch.from_numpy(img).float().div(255.)
131
+ mask = torch.from_numpy(mask).float()
132
+ predict_config = OmegaConf.load(config_p)
133
+
134
+ batch = {}
135
+ batch['image'] = img.permute(2, 0, 1).unsqueeze(0)
136
+ batch['mask'] = mask[None, None]
137
+ unpad_to_size = [batch['image'].shape[2], batch['image'].shape[3]]
138
+ batch['image'] = pad_tensor_to_modulo(batch['image'], mod)
139
+ batch['mask'] = pad_tensor_to_modulo(batch['mask'], mod)
140
+ batch = move_to_device(batch, device)
141
+ batch['mask'] = (batch['mask'] > 0) * 1
142
+
143
+ batch = model(batch)
144
+ cur_res = batch[predict_config.out_key][0].permute(1, 2, 0)
145
+ cur_res = cur_res.detach().cpu().numpy()
146
+
147
+ if unpad_to_size is not None:
148
+ orig_height, orig_width = unpad_to_size
149
+ cur_res = cur_res[:orig_height, :orig_width]
150
+
151
+ cur_res = np.clip(cur_res * 255, 0, 255).astype('uint8')
152
+ return cur_res
153
+
154
+
155
+ def setup_args(parser):
156
+ parser.add_argument(
157
+ "--input_img", type=str, required=True,
158
+ help="Path to a single input img",
159
+ )
160
+ parser.add_argument(
161
+ "--input_mask_glob", type=str, required=True,
162
+ help="Glob to input masks",
163
+ )
164
+ parser.add_argument(
165
+ "--output_dir", type=str, required=True,
166
+ help="Output path to the directory with results.",
167
+ )
168
+ parser.add_argument(
169
+ "--lama_config", type=str,
170
+ default="./third_party/lama/configs/prediction/default.yaml",
171
+ help="The path to the config file of lama model. "
172
+ "Default: the config of big-lama",
173
+ )
174
+ parser.add_argument(
175
+ "--lama_ckpt", type=str, required=True,
176
+ help="The path to the lama checkpoint.",
177
+ )
178
+
179
+
180
+ if __name__ == "__main__":
181
+ """Example usage:
182
+ python lama_inpaint.py \
183
+ --input_img FA_demo/FA1_dog.png \
184
+ --input_mask_glob "results/FA1_dog/mask*.png" \
185
+ --output_dir results \
186
+ --lama_config lama/configs/prediction/default.yaml \
187
+ --lama_ckpt big-lama
188
+ """
189
+ parser = argparse.ArgumentParser()
190
+ setup_args(parser)
191
+ args = parser.parse_args(sys.argv[1:])
192
+ device = "cuda" if torch.cuda.is_available() else "cpu"
193
+
194
+ img_stem = Path(args.input_img).stem
195
+ mask_ps = sorted(glob.glob(args.input_mask_glob))
196
+ out_dir = Path(args.output_dir) / img_stem
197
+ out_dir.mkdir(parents=True, exist_ok=True)
198
+
199
+ img = load_img_to_array(args.input_img)
200
+ for mask_p in mask_ps:
201
+ mask = load_img_to_array(mask_p)
202
+ img_inpainted_p = out_dir / f"inpainted_with_{Path(mask_p).name}"
203
+ img_inpainted = inpaint_img_with_lama(
204
+ img, mask, args.lama_config, args.lama_ckpt, device=device)
205
+ save_array_to_img(img_inpainted, img_inpainted_p)
pretrained_models/.gitkeep ADDED
@@ -0,0 +1 @@
 
 
1
+ # Put pretrained models into this directory
pretrained_models/big-lama/config.yaml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fdeed49926e13b101c4dd9e193acec9e58677dfdb4ba49dd6a3a8927964e2a7
3
+ size 3947
pretrained_models/big-lama/models/best.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fccb7adffd53ec0974ee5503c3731c2c2f1e7e07856fd9228cdcc0b46fd5d423
3
+ size 410046389
pretrained_models/sam_vit_h_4b8939.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7bf3b02f3ebf1267aba913ff637d9a2d5c33d3173bb679e46d9f338c26f262e
3
+ size 2564550879
remove_anything.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import sys
3
+ import argparse
4
+ import numpy as np
5
+ from pathlib import Path
6
+ from matplotlib import pyplot as plt
7
+
8
+ from sam_segment import predict_masks_with_sam
9
+ from lama_inpaint import inpaint_img_with_lama
10
+ from utils import load_img_to_array, save_array_to_img, dilate_mask, \
11
+ show_mask, show_points
12
+
13
+
14
+ def setup_args(parser):
15
+ parser.add_argument(
16
+ "--input_img", type=str, required=True,
17
+ help="Path to a single input img",
18
+ )
19
+ parser.add_argument(
20
+ "--point_coords", type=float, nargs='+', required=True,
21
+ help="The coordinate of the point prompt, [coord_W coord_H].",
22
+ )
23
+ parser.add_argument(
24
+ "--point_labels", type=int, nargs='+', required=True,
25
+ help="The labels of the point prompt, 1 or 0.",
26
+ )
27
+ parser.add_argument(
28
+ "--dilate_kernel_size", type=int, default=None,
29
+ help="Dilate kernel size. Default: None",
30
+ )
31
+ parser.add_argument(
32
+ "--output_dir", type=str, required=True,
33
+ help="Output path to the directory with results.",
34
+ )
35
+ parser.add_argument(
36
+ "--sam_model_type", type=str,
37
+ default="vit_h", choices=['vit_h', 'vit_l', 'vit_b'],
38
+ help="The type of sam model to load. Default: 'vit_h"
39
+ )
40
+ parser.add_argument(
41
+ "--sam_ckpt", type=str, required=True,
42
+ help="The path to the SAM checkpoint to use for mask generation.",
43
+ )
44
+ parser.add_argument(
45
+ "--lama_config", type=str,
46
+ default="./lama/configs/prediction/default.yaml",
47
+ help="The path to the config file of lama model. "
48
+ "Default: the config of big-lama",
49
+ )
50
+ parser.add_argument(
51
+ "--lama_ckpt", type=str, required=True,
52
+ help="The path to the lama checkpoint.",
53
+ )
54
+
55
+
56
+ if __name__ == "__main__":
57
+ """Example usage:
58
+ python remove_anything.py \
59
+ --input_img FA_demo/FA1_dog.png \
60
+ --point_coords 750 500 \
61
+ --point_labels 1 \
62
+ --dilate_kernel_size 15 \
63
+ --output_dir ./results \
64
+ --sam_model_type "vit_h" \
65
+ --sam_ckpt sam_vit_h_4b8939.pth \
66
+ --lama_config lama/configs/prediction/default.yaml \
67
+ --lama_ckpt big-lama
68
+ """
69
+ parser = argparse.ArgumentParser()
70
+ setup_args(parser)
71
+ args = parser.parse_args(sys.argv[1:])
72
+ device = "cuda" if torch.cuda.is_available() else "cpu"
73
+
74
+ img = load_img_to_array(args.input_img)
75
+
76
+ masks, _, _ = predict_masks_with_sam(
77
+ img,
78
+ [args.point_coords],
79
+ args.point_labels,
80
+ model_type=args.sam_model_type,
81
+ ckpt_p=args.sam_ckpt,
82
+ device=device,
83
+ )
84
+ masks = masks.astype(np.uint8) * 255
85
+
86
+ # dilate mask to avoid unmasked edge effect
87
+ if args.dilate_kernel_size is not None:
88
+ masks = [dilate_mask(mask, args.dilate_kernel_size) for mask in masks]
89
+
90
+ # visualize the segmentation results
91
+ img_stem = Path(args.input_img).stem
92
+ out_dir = Path(args.output_dir) / img_stem
93
+ out_dir.mkdir(parents=True, exist_ok=True)
94
+ for idx, mask in enumerate(masks):
95
+ # path to the results
96
+ mask_p = out_dir / f"mask_{idx}.png"
97
+ img_points_p = out_dir / f"with_points.png"
98
+ img_mask_p = out_dir / f"with_{Path(mask_p).name}"
99
+
100
+ # save the mask
101
+ save_array_to_img(mask, mask_p)
102
+
103
+ # save the pointed and masked image
104
+ dpi = plt.rcParams['figure.dpi']
105
+ height, width = img.shape[:2]
106
+ plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
107
+ plt.imshow(img)
108
+ plt.axis('off')
109
+ show_points(plt.gca(), [args.point_coords], args.point_labels,
110
+ size=(width*0.04)**2)
111
+ plt.savefig(img_points_p, bbox_inches='tight', pad_inches=0)
112
+ show_mask(plt.gca(), mask, random_color=False)
113
+ plt.savefig(img_mask_p, bbox_inches='tight', pad_inches=0)
114
+ plt.close()
115
+
116
+ # inpaint the masked image
117
+ for idx, mask in enumerate(masks):
118
+ mask_p = out_dir / f"mask_{idx}.png"
119
+ img_inpainted_p = out_dir / f"inpainted_with_{Path(mask_p).name}"
120
+ img_inpainted = inpaint_img_with_lama(
121
+ img, mask, args.lama_config, args.lama_ckpt, device=device)
122
+ save_array_to_img(img_inpainted, img_inpainted_p)
replace_anything.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import sys
3
+ import argparse
4
+ import numpy as np
5
+ import torch
6
+ from pathlib import Path
7
+ from matplotlib import pyplot as plt
8
+ from typing import Any, Dict, List
9
+ from sam_segment import predict_masks_with_sam
10
+ from stable_diffusion_inpaint import replace_img_with_sd
11
+ from utils import load_img_to_array, save_array_to_img, dilate_mask, \
12
+ show_mask, show_points
13
+
14
+
15
+ def setup_args(parser):
16
+ parser.add_argument(
17
+ "--input_img", type=str, required=True,
18
+ help="Path to a single input img",
19
+ )
20
+ parser.add_argument(
21
+ "--point_coords", type=float, nargs='+', required=True,
22
+ help="The coordinate of the point prompt, [coord_W coord_H].",
23
+ )
24
+ parser.add_argument(
25
+ "--point_labels", type=int, nargs='+', required=True,
26
+ help="The labels of the point prompt, 1 or 0.",
27
+ )
28
+ parser.add_argument(
29
+ "--text_prompt", type=str, required=True,
30
+ help="Text prompt",
31
+ )
32
+ parser.add_argument(
33
+ "--dilate_kernel_size", type=int, default=None,
34
+ help="Dilate kernel size. Default: None",
35
+ )
36
+ parser.add_argument(
37
+ "--output_dir", type=str, required=True,
38
+ help="Output path to the directory with results.",
39
+ )
40
+ parser.add_argument(
41
+ "--sam_model_type", type=str,
42
+ default="vit_h", choices=['vit_h', 'vit_l', 'vit_b'],
43
+ help="The type of sam model to load. Default: 'vit_h"
44
+ )
45
+ parser.add_argument(
46
+ "--sam_ckpt", type=str, required=True,
47
+ help="The path to the SAM checkpoint to use for mask generation.",
48
+ )
49
+ parser.add_argument(
50
+ "--seed", type=int,
51
+ help="Specify seed for reproducibility.",
52
+ )
53
+ parser.add_argument(
54
+ "--deterministic", action="store_true",
55
+ help="Use deterministic algorithms for reproducibility.",
56
+ )
57
+
58
+
59
+
60
+ if __name__ == "__main__":
61
+ """Example usage:
62
+ python replace_anything.py \
63
+ --input_img FA_demo/FA1_dog.png \
64
+ --point_coords 750 500 \
65
+ --point_labels 1 \
66
+ --text_prompt "sit on the swing" \
67
+ --output_dir ./results \
68
+ --sam_model_type "vit_h" \
69
+ --sam_ckpt sam_vit_h_4b8939.pth
70
+ """
71
+ parser = argparse.ArgumentParser()
72
+ setup_args(parser)
73
+ args = parser.parse_args(sys.argv[1:])
74
+ device = "cuda" if torch.cuda.is_available() else "cpu"
75
+
76
+ img = load_img_to_array(args.input_img)
77
+
78
+ masks, _, _ = predict_masks_with_sam(
79
+ img,
80
+ [args.point_coords],
81
+ args.point_labels,
82
+ model_type=args.sam_model_type,
83
+ ckpt_p=args.sam_ckpt,
84
+ device=device,
85
+ )
86
+ masks = masks.astype(np.uint8) * 255
87
+
88
+ # dilate mask to avoid unmasked edge effect
89
+ if args.dilate_kernel_size is not None:
90
+ masks = [dilate_mask(mask, args.dilate_kernel_size) for mask in masks]
91
+
92
+ # visualize the segmentation results
93
+ img_stem = Path(args.input_img).stem
94
+ out_dir = Path(args.output_dir) / img_stem
95
+ out_dir.mkdir(parents=True, exist_ok=True)
96
+ for idx, mask in enumerate(masks):
97
+ # path to the results
98
+ mask_p = out_dir / f"mask_{idx}.png"
99
+ img_points_p = out_dir / f"with_points.png"
100
+ img_mask_p = out_dir / f"with_{Path(mask_p).name}"
101
+
102
+ # save the mask
103
+ save_array_to_img(mask, mask_p)
104
+
105
+ # save the pointed and masked image
106
+ dpi = plt.rcParams['figure.dpi']
107
+ height, width = img.shape[:2]
108
+ plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
109
+ plt.imshow(img)
110
+ plt.axis('off')
111
+ show_points(plt.gca(), [args.point_coords], args.point_labels,
112
+ size=(width*0.04)**2)
113
+ plt.savefig(img_points_p, bbox_inches='tight', pad_inches=0)
114
+ show_mask(plt.gca(), mask, random_color=False)
115
+ plt.savefig(img_mask_p, bbox_inches='tight', pad_inches=0)
116
+ plt.close()
117
+
118
+ # fill the masked image
119
+ for idx, mask in enumerate(masks):
120
+ if args.seed is not None:
121
+ torch.manual_seed(args.seed)
122
+ mask_p = out_dir / f"mask_{idx}.png"
123
+ img_replaced_p = out_dir / f"replaced_with_{Path(mask_p).name}"
124
+ img_replaced = replace_img_with_sd(
125
+ img, mask, args.text_prompt, device=device)
126
+ save_array_to_img(img_replaced, img_replaced_p)
requirements.txt ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ opencv-python
4
+ matplotlib
5
+ tensorflow
6
+ pyyaml
7
+ tqdm
8
+ numpy
9
+ easydict
10
+ scikit-image
11
+ scikit-learn
12
+ opencv-python
13
+ joblib
14
+ matplotlib
15
+ pandas
16
+ albumentations==0.5.2
17
+ hydra-core
18
+ pytorch-lightning
19
+ tabulate
20
+ kornia==0.5.0
21
+ webdataset
22
+ packaging
23
+ wldhx.yadisk-direct
sam_segment.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import argparse
3
+ import numpy as np
4
+ from pathlib import Path
5
+ from matplotlib import pyplot as plt
6
+ from typing import Any, Dict, List
7
+ import torch
8
+
9
+ sys.path.insert(0, str(Path(__file__).resolve().parent / "third_party" / "segment-anything"))
10
+
11
+ from segment_anything import SamPredictor, sam_model_registry
12
+ from utils import load_img_to_array, save_array_to_img, dilate_mask, \
13
+ show_mask, show_points
14
+
15
+
16
+ def predict_masks_with_sam(
17
+ img: np.ndarray,
18
+ point_coords: List[List[float]],
19
+ point_labels: List[int],
20
+ model_type: str,
21
+ ckpt_p: str,
22
+ device="cuda"
23
+ ):
24
+ point_coords = np.array(point_coords)
25
+ point_labels = np.array(point_labels)
26
+ sam = sam_model_registry[model_type](checkpoint=ckpt_p)
27
+ sam.to(device=device)
28
+ predictor = SamPredictor(sam)
29
+
30
+ predictor.set_image(img)
31
+ masks, scores, logits = predictor.predict(
32
+ point_coords=point_coords,
33
+ point_labels=point_labels,
34
+ multimask_output=True,
35
+ )
36
+ return masks, scores, logits
37
+
38
+
39
+ def setup_args(parser):
40
+ parser.add_argument(
41
+ "--input_img", type=str, required=True,
42
+ help="Path to a single input img",
43
+ )
44
+ parser.add_argument(
45
+ "--point_coords", type=float, nargs='+', required=True,
46
+ help="The coordinate of the point prompt, [coord_W coord_H].",
47
+ )
48
+ parser.add_argument(
49
+ "--point_labels", type=int, nargs='+', required=True,
50
+ help="The labels of the point prompt, 1 or 0.",
51
+ )
52
+ parser.add_argument(
53
+ "--dilate_kernel_size", type=int, default=None,
54
+ help="Dilate kernel size. Default: None",
55
+ )
56
+ parser.add_argument(
57
+ "--output_dir", type=str, required=True,
58
+ help="Output path to the directory with results.",
59
+ )
60
+ parser.add_argument(
61
+ "--sam_model_type", type=str,
62
+ default="vit_h", choices=['vit_h', 'vit_l', 'vit_b'],
63
+ help="The type of sam model to load. Default: 'vit_h"
64
+ )
65
+ parser.add_argument(
66
+ "--sam_ckpt", type=str, required=True,
67
+ help="The path to the SAM checkpoint to use for mask generation.",
68
+ )
69
+
70
+
71
+ if __name__ == "__main__":
72
+ """Example usage:
73
+ python sam_segment.py \
74
+ --input_img FA_demo/FA1_dog.png \
75
+ --point_coords 750 500 \
76
+ --point_labels 1 \
77
+ --dilate_kernel_size 15 \
78
+ --output_dir ./results \
79
+ --sam_model_type "vit_h" \
80
+ --sam_ckpt sam_vit_h_4b8939.pth
81
+ """
82
+ parser = argparse.ArgumentParser()
83
+ setup_args(parser)
84
+ args = parser.parse_args(sys.argv[1:])
85
+ device = "cuda" if torch.cuda.is_available() else "cpu"
86
+
87
+ img = load_img_to_array(args.input_img)
88
+
89
+ masks, _, _ = predict_masks_with_sam(
90
+ img,
91
+ [args.point_coords],
92
+ args.point_labels,
93
+ model_type=args.sam_model_type,
94
+ ckpt_p=args.sam_ckpt,
95
+ device=device,
96
+ )
97
+ masks = masks.astype(np.uint8) * 255
98
+
99
+ # dilate mask to avoid unmasked edge effect
100
+ if args.dilate_kernel_size is not None:
101
+ masks = [dilate_mask(mask, args.dilate_kernel_size) for mask in masks]
102
+
103
+ # visualize the segmentation results
104
+ img_stem = Path(args.input_img).stem
105
+ out_dir = Path(args.output_dir) / img_stem
106
+ out_dir.mkdir(parents=True, exist_ok=True)
107
+ for idx, mask in enumerate(masks):
108
+ # path to the results
109
+ mask_p = out_dir / f"mask_{idx}.png"
110
+ img_points_p = out_dir / f"with_points.png"
111
+ img_mask_p = out_dir / f"with_{Path(mask_p).name}"
112
+
113
+ # save the mask
114
+ save_array_to_img(mask, mask_p)
115
+
116
+ # save the pointed and masked image
117
+ dpi = plt.rcParams['figure.dpi']
118
+ height, width = img.shape[:2]
119
+ plt.figure(figsize=(width/dpi/0.77, height/dpi/0.77))
120
+ plt.imshow(img)
121
+ plt.axis('off')
122
+ show_points(plt.gca(), [args.point_coords], args.point_labels,
123
+ size=(width*0.04)**2)
124
+ plt.savefig(img_points_p, bbox_inches='tight', pad_inches=0)
125
+ show_mask(plt.gca(), mask, random_color=False)
126
+ plt.savefig(img_mask_p, bbox_inches='tight', pad_inches=0)
127
+ plt.close()
stable_diffusion_inpaint.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import glob
4
+ import argparse
5
+ import torch
6
+ import numpy as np
7
+ import PIL.Image as Image
8
+ from pathlib import Path
9
+ from diffusers import StableDiffusionInpaintPipeline
10
+ from utils.mask_processing import crop_for_filling_pre, crop_for_filling_post
11
+ from utils.crop_for_replacing import recover_size, resize_and_pad
12
+ from utils import load_img_to_array, save_array_to_img
13
+
14
+
15
+ def fill_img_with_sd(
16
+ img: np.ndarray,
17
+ mask: np.ndarray,
18
+ text_prompt: str,
19
+ device="cuda"
20
+ ):
21
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
22
+ "stabilityai/stable-diffusion-2-inpainting",
23
+ torch_dtype=torch.float32,
24
+ ).to(device)
25
+ img_crop, mask_crop = crop_for_filling_pre(img, mask)
26
+ img_crop_filled = pipe(
27
+ prompt=text_prompt,
28
+ image=Image.fromarray(img_crop),
29
+ mask_image=Image.fromarray(mask_crop)
30
+ ).images[0]
31
+ img_filled = crop_for_filling_post(img, mask, np.array(img_crop_filled))
32
+ return img_filled
33
+
34
+
35
+ def replace_img_with_sd(
36
+ img: np.ndarray,
37
+ mask: np.ndarray,
38
+ text_prompt: str,
39
+ step: int = 50,
40
+ device="cuda"
41
+ ):
42
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
43
+ "stabilityai/stable-diffusion-2-inpainting",
44
+ torch_dtype=torch.float32,
45
+ ).to(device)
46
+ img_padded, mask_padded, padding_factors = resize_and_pad(img, mask)
47
+ img_padded = pipe(
48
+ prompt=text_prompt,
49
+ image=Image.fromarray(img_padded),
50
+ mask_image=Image.fromarray(255 - mask_padded),
51
+ num_inference_steps=step,
52
+ ).images[0]
53
+ height, width, _ = img.shape
54
+ img_resized, mask_resized = recover_size(
55
+ np.array(img_padded), mask_padded, (height, width), padding_factors)
56
+ mask_resized = np.expand_dims(mask_resized, -1) / 255
57
+ img_resized = img_resized * (1-mask_resized) + img * mask_resized
58
+ return img_resized
59
+
60
+
61
+ def setup_args(parser):
62
+ parser.add_argument(
63
+ "--input_img", type=str, required=True,
64
+ help="Path to a single input img",
65
+ )
66
+ parser.add_argument(
67
+ "--text_prompt", type=str, required=True,
68
+ help="Text prompt",
69
+ )
70
+ parser.add_argument(
71
+ "--input_mask_glob", type=str, required=True,
72
+ help="Glob to input masks",
73
+ )
74
+ parser.add_argument(
75
+ "--output_dir", type=str, required=True,
76
+ help="Output path to the directory with results.",
77
+ )
78
+ parser.add_argument(
79
+ "--seed", type=int,
80
+ help="Specify seed for reproducibility.",
81
+ )
82
+ parser.add_argument(
83
+ "--deterministic", action="store_true",
84
+ help="Use deterministic algorithms for reproducibility.",
85
+ )
86
+
87
+ if __name__ == "__main__":
88
+ """Example usage:
89
+ python lama_inpaint.py \
90
+ --input_img FA_demo/FA1_dog.png \
91
+ --input_mask_glob "results/FA1_dog/mask*.png" \
92
+ --text_prompt "a teddy bear on a bench" \
93
+ --output_dir results
94
+ """
95
+ parser = argparse.ArgumentParser()
96
+ setup_args(parser)
97
+ args = parser.parse_args(sys.argv[1:])
98
+ device = "cuda" if torch.cuda.is_available() else "cpu"
99
+
100
+ if args.deterministic:
101
+ os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
102
+ torch.use_deterministic_algorithms(True)
103
+
104
+ img_stem = Path(args.input_img).stem
105
+ mask_ps = sorted(glob.glob(args.input_mask_glob))
106
+ out_dir = Path(args.output_dir) / img_stem
107
+ out_dir.mkdir(parents=True, exist_ok=True)
108
+
109
+ img = load_img_to_array(args.input_img)
110
+ for mask_p in mask_ps:
111
+ if args.seed is not None:
112
+ torch.manual_seed(args.seed)
113
+ mask = load_img_to_array(mask_p)
114
+ img_filled_p = out_dir / f"filled_with_{Path(mask_p).name}"
115
+ img_filled = fill_img_with_sd(
116
+ img, mask, args.text_prompt, device=device)
117
+ save_array_to_img(img_filled, img_filled_p)
third_party/.gitkeep ADDED
@@ -0,0 +1 @@
 
 
1
+ # Put third party packages into this directory
third_party/lama/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbe005fc6c62133aee2511011dad6e169d913bba51490d29d36659566c7d84e9
3
+ size 1865
third_party/lama/LICENSE ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ceeeac5a802e86c413c22b16cce8e9a22027b0250c97e6f8ac97c14cf0542c0
3
+ size 11348
third_party/lama/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54b097c25246f2193703790ca10f3da7a134ca9cd6fee6f7f14d1e03c016df3a
3
+ size 16575
third_party/lama/bin/analyze_errors.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9019332b8309090906f49ac63fe6a6e5f1a5a03e2eedf3e56c8be6cfd6fb2dcc
3
+ size 17698
third_party/lama/bin/blur_predicts.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed0863c166ba510175e89a373f7b950550e8008ed4b328e6b7d2c53e7237889a
3
+ size 2191
third_party/lama/bin/calc_dataset_stats.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:53e279cba5626e01ffaa7984b775603f64cdf149a72fa16a0f58000a3bcbc4ec
3
+ size 3627
third_party/lama/bin/debug/analyze_overlapping_masks.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c368f947b87d27ecda000ba96d2dd81437aa24215064f1cae1df92c86f0f1c52
3
+ size 1132
third_party/lama/bin/evaluate_predicts.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67458a187713e1455dd1ff013bd678d608979ae49f637a22f24ee92d40de0e8b
3
+ size 3530
third_party/lama/bin/evaluator_example.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c88b5a0d15bfa6e81b60c963aa8f32ff752b853ae3cf38966d24cccdfc8b931
3
+ size 2359
third_party/lama/bin/extract_masks.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e90a3197316ee22fd33b01ce1df8b8e21be39288e1669ec1c9f4d7e6e0fcd19
3
+ size 1627
third_party/lama/bin/filter_sharded_dataset.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:48c820e8ec725ffbc1b625d6924dab43c5134f955e0a32bc3ee756f437e6c2f1
3
+ size 2346
third_party/lama/bin/gen_debug_mask_dataset.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea1b7f9144b3716ebe676bb89efd9ae052e4831670ba65c3b1f05ef770da5e76
3
+ size 1909
third_party/lama/bin/gen_mask_dataset.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f0ab3421b1b5f69b00e2e8faec6ac6ef7f980dc8ce8aed340bd99e3e5bd5a1b
3
+ size 5609
third_party/lama/bin/gen_mask_dataset_hydra.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d732574c27a74fa64c66a1afea6497e4fd87103d7da3d58e3dc83f7bb59ad46e
3
+ size 5340
third_party/lama/bin/gen_outpainting_dataset.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7457d08e1f495c3bee3de2413fdb735f252d3fe342b5e54e5372af73b1598211
3
+ size 3226
third_party/lama/bin/make_checkpoint.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d86903c380809c4c266a0ea39cae4d2fb4aa4fcae9ca51491053ac28a72c2edf
3
+ size 3097
third_party/lama/bin/mask_example.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3d14ee869193ebb1b5ac68ea92c9506e7f9bba280ca9c4581fb170cd6ccd789
3
+ size 466
third_party/lama/bin/paper_runfiles/blur_tests.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c8ec2117f3e600321150ed0f24d385c71edb14f2c221a2c32afe6d61a833cfc
3
+ size 1491
third_party/lama/bin/paper_runfiles/env.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:669a5d8d21c3c4400225ef11a4d424d79de578cd5fa923ef55fb930e743a7094
3
+ size 170
third_party/lama/bin/paper_runfiles/find_best_checkpoint.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42d198b58e58ec822e1aac66d66251b87c519f8b9ec178a1c0f810f0891841ae
3
+ size 2075
third_party/lama/bin/paper_runfiles/generate_test_celeba-hq.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecde53349bd3df42ce1e2659578ab493f78a521760168c1458c746b06c304fe9
3
+ size 603
third_party/lama/bin/paper_runfiles/generate_test_ffhq.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27abaa6c56ac539bea34bac171d31558826399e1ea2e69742ac0bb9f93364413
3
+ size 580
third_party/lama/bin/paper_runfiles/generate_test_paris.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b48c06f2d0197d5b52fd6dbaa3c3b24ec41d19e8ae485e920eab1f85b9e2d0c
3
+ size 593
third_party/lama/bin/paper_runfiles/generate_test_paris_256.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:174c38fc6663c4bb6eb7b259a81ec6e4b1d16df0ae40cd4329b2fb4656306a74
3
+ size 598
third_party/lama/bin/paper_runfiles/generate_val_test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13ea073dbdec3dcab2af58f39099f1e23f7a93e7f445ba00d3091070ab1cd329
3
+ size 1045
third_party/lama/bin/paper_runfiles/predict_inner_features.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eebdbcad0999666cc465eea6cf5154bd90a933a044da95888de6e6f1fdf5b15a
3
+ size 841
third_party/lama/bin/paper_runfiles/update_test_data_stats.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:686112f14750df31bb8dec7d603088b40a2b6b2083df6688817640c7d26d788c
3
+ size 927
third_party/lama/bin/predict.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d7cff7b5f498e895830f97fc076f33ad61bf62c5a117f2028932b267e9d13f7
3
+ size 4092
third_party/lama/bin/predict_inner_features.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2754aedde8a69795dca8cb2ee2919ba6237397b1d0501061f684e347d35128ac
3
+ size 4938
third_party/lama/bin/report_from_tb.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c110718a1f0c37ed143eeac317a4bd3522350060e178ea655fd5d0bd32804dfc
3
+ size 2588
third_party/lama/bin/sample_from_dataset.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb5507435eb50c10e50f96707e77f5109b8c8f73f14c520a24b321b24b6fc642
3
+ size 3044
third_party/lama/bin/side_by_side.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9eaec563dbc98868725083fd560f729e3e50dc263b71a6ff1bbfd9f627df0b5d
3
+ size 2826