Spaces:
Runtime error
Runtime error
liuyizhang
commited on
Commit
•
4962329
1
Parent(s):
79eb367
update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ import cv2
|
|
41 |
import numpy as np
|
42 |
import matplotlib.pyplot as plt
|
43 |
from lama_cleaner.model_manager import ModelManager
|
44 |
-
from lama_cleaner.schema import Config
|
45 |
|
46 |
# segment anything
|
47 |
from segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator
|
@@ -280,7 +280,7 @@ def lama_cleaner_process(image, mask):
|
|
280 |
else:
|
281 |
size_limit = int(size_limit)
|
282 |
|
283 |
-
config =
|
284 |
ldm_steps=25,
|
285 |
ldm_sampler='plms',
|
286 |
zits_wireframe=True,
|
@@ -324,14 +324,14 @@ def lama_cleaner_process(image, mask):
|
|
324 |
# relate anything
|
325 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, show_mask
|
326 |
from ram_train_eval import RamModel,RamPredictor
|
327 |
-
from mmengine.config import Config
|
328 |
input_size = 512
|
329 |
hidden_size = 256
|
330 |
num_classes = 56
|
331 |
|
332 |
# load ram model
|
333 |
model_path = "./checkpoints/ram_epoch12.pth"
|
334 |
-
|
335 |
model=dict(
|
336 |
pretrained_model_name_or_path='bert-base-uncased',
|
337 |
load_pretrained_weights=False,
|
@@ -345,7 +345,7 @@ config = dict(
|
|
345 |
),
|
346 |
load_from=model_path,
|
347 |
)
|
348 |
-
|
349 |
|
350 |
class Ram_Predictor(RamPredictor):
|
351 |
def __init__(self, config, device='cpu'):
|
@@ -358,7 +358,8 @@ class Ram_Predictor(RamPredictor):
|
|
358 |
if self.config.load_from is not None:
|
359 |
self.model.load_state_dict(torch.load(self.config.load_from, map_location=self.device))
|
360 |
self.model.train()
|
361 |
-
|
|
|
362 |
|
363 |
# visualization
|
364 |
def draw_selected_mask(mask, draw):
|
@@ -736,8 +737,8 @@ if __name__ == "__main__":
|
|
736 |
mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
|
737 |
|
738 |
DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
739 |
-
DESCRIPTION += '
|
740 |
-
DESCRIPTION += '
|
741 |
DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
742 |
gr.Markdown(DESCRIPTION)
|
743 |
|
|
|
41 |
import numpy as np
|
42 |
import matplotlib.pyplot as plt
|
43 |
from lama_cleaner.model_manager import ModelManager
|
44 |
+
from lama_cleaner.schema import Config as lama_Config
|
45 |
|
46 |
# segment anything
|
47 |
from segment_anything import build_sam, SamPredictor, SamAutomaticMaskGenerator
|
|
|
280 |
else:
|
281 |
size_limit = int(size_limit)
|
282 |
|
283 |
+
config = lama_Config(
|
284 |
ldm_steps=25,
|
285 |
ldm_sampler='plms',
|
286 |
zits_wireframe=True,
|
|
|
324 |
# relate anything
|
325 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, show_mask
|
326 |
from ram_train_eval import RamModel,RamPredictor
|
327 |
+
from mmengine.config import Config as mmengine_Config
|
328 |
input_size = 512
|
329 |
hidden_size = 256
|
330 |
num_classes = 56
|
331 |
|
332 |
# load ram model
|
333 |
model_path = "./checkpoints/ram_epoch12.pth"
|
334 |
+
ram_config = dict(
|
335 |
model=dict(
|
336 |
pretrained_model_name_or_path='bert-base-uncased',
|
337 |
load_pretrained_weights=False,
|
|
|
345 |
),
|
346 |
load_from=model_path,
|
347 |
)
|
348 |
+
ram_config = mmengine_Config(ram_config)
|
349 |
|
350 |
class Ram_Predictor(RamPredictor):
|
351 |
def __init__(self, config, device='cpu'):
|
|
|
358 |
if self.config.load_from is not None:
|
359 |
self.model.load_state_dict(torch.load(self.config.load_from, map_location=self.device))
|
360 |
self.model.train()
|
361 |
+
|
362 |
+
ram_model = Ram_Predictor(ram_config, device)
|
363 |
|
364 |
# visualization
|
365 |
def draw_selected_mask(mask, draw):
|
|
|
737 |
mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio], outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
|
738 |
|
739 |
DESCRIPTION = '### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
740 |
+
DESCRIPTION += 'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
741 |
+
DESCRIPTION += 'Thanks for their excellent work.'
|
742 |
DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
743 |
gr.Markdown(DESCRIPTION)
|
744 |
|