liuyizhang
commited on
Commit
•
7a52d01
1
Parent(s):
abb3b3e
update app.py
Browse files- app.py +24 -10
- requirements.txt +1 -1
app.py
CHANGED
@@ -37,8 +37,14 @@ from GroundingDINO.groundingdino.util.utils import clean_state_dict, get_phrases
|
|
37 |
import cv2
|
38 |
import numpy as np
|
39 |
import matplotlib.pyplot as plt
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# segment anything
|
44 |
from segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator
|
@@ -56,11 +62,13 @@ from utils import computer_info
|
|
56 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, ram_show_mask
|
57 |
from ram_train_eval import RamModel,RamPredictor
|
58 |
from mmengine.config import Config as mmengine_Config
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
|
65 |
# from transformers import AutoProcessor, AutoModelForVision2Seq
|
66 |
import ast
|
@@ -787,7 +795,9 @@ def get_model_device(module):
|
|
787 |
ram_enable = True
|
788 |
kosmos_enable = True
|
789 |
|
790 |
-
task_types = ["detection", "segment", "inpainting"
|
|
|
|
|
791 |
if ram_enable:
|
792 |
task_types.append("relate anything")
|
793 |
if kosmos_enable:
|
@@ -811,7 +821,10 @@ if __name__ == "__main__":
|
|
811 |
load_sam_model()
|
812 |
|
813 |
load_sd_model()
|
814 |
-
|
|
|
|
|
|
|
815 |
if ram_enable:
|
816 |
load_ram_model()
|
817 |
|
@@ -907,7 +920,8 @@ if __name__ == "__main__":
|
|
907 |
DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
908 |
if ram_enable:
|
909 |
DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
910 |
-
|
|
|
911 |
if kosmos_enable:
|
912 |
DESCRIPTION += f'Kosmos-2 from [Kosmos-2](https://github.com/microsoft/unilm/tree/master/kosmos-2). <br>'
|
913 |
DESCRIPTION += f'Thanks for their excellent work.'
|
|
|
37 |
import cv2
|
38 |
import numpy as np
|
39 |
import matplotlib.pyplot as plt
|
40 |
+
|
41 |
+
lama_cleaner_enable = False
|
42 |
+
try:
|
43 |
+
from lama_cleaner.model_manager import ModelManager
|
44 |
+
from lama_cleaner.schema import Config as lama_Config
|
45 |
+
lama_cleaner_enable = True
|
46 |
+
except Exception as e:
|
47 |
+
pass
|
48 |
|
49 |
# segment anything
|
50 |
from segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator
|
|
|
62 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, ram_show_mask
|
63 |
from ram_train_eval import RamModel,RamPredictor
|
64 |
from mmengine.config import Config as mmengine_Config
|
65 |
+
|
66 |
+
if lama_cleaner_enable:
|
67 |
+
from lama_cleaner.helper import (
|
68 |
+
load_img,
|
69 |
+
numpy_to_bytes,
|
70 |
+
resize_max_size,
|
71 |
+
)
|
72 |
|
73 |
# from transformers import AutoProcessor, AutoModelForVision2Seq
|
74 |
import ast
|
|
|
795 |
ram_enable = True
|
796 |
kosmos_enable = True
|
797 |
|
798 |
+
task_types = ["detection", "segment", "inpainting"]
|
799 |
+
if lama_cleaner_enable:
|
800 |
+
task_types.append("remove")
|
801 |
if ram_enable:
|
802 |
task_types.append("relate anything")
|
803 |
if kosmos_enable:
|
|
|
821 |
load_sam_model()
|
822 |
|
823 |
load_sd_model()
|
824 |
+
|
825 |
+
if lama_cleaner_enable:
|
826 |
+
load_lama_cleaner_model()
|
827 |
+
|
828 |
if ram_enable:
|
829 |
load_ram_model()
|
830 |
|
|
|
920 |
DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
921 |
if ram_enable:
|
922 |
DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
923 |
+
if lama_cleaner_enable:
|
924 |
+
DESCRIPTION += f'Remove(cleaner) from [lama-cleaner](https://github.com/Sanster/lama-cleaner). <br>'
|
925 |
if kosmos_enable:
|
926 |
DESCRIPTION += f'Kosmos-2 from [Kosmos-2](https://github.com/microsoft/unilm/tree/master/kosmos-2). <br>'
|
927 |
DESCRIPTION += f'Thanks for their excellent work.'
|
requirements.txt
CHANGED
@@ -26,6 +26,6 @@ safetensors
|
|
26 |
pynvml
|
27 |
sentencepiece
|
28 |
|
29 |
-
lama-cleaner==1.2.3
|
30 |
openmim==0.1.5
|
31 |
mmcv==2.0.0
|
|
|
26 |
pynvml
|
27 |
sentencepiece
|
28 |
|
29 |
+
# lama-cleaner==1.2.3
|
30 |
openmim==0.1.5
|
31 |
mmcv==2.0.0
|