Modular Florence2 block that can also be used with Mellon.
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<CAPTION>" # can also be <DETAILED_CAPTION> or <MORE_DETAILED_CAPTION>
16annotation_prompt = ""
17
18output = pipe(image=image, annotation_task=annotation_task, annotation_prompt=annotation_prompt).annotations[0]
19print(output)
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<OD>"
16annotation_prompt = ""
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<DENSE_REGION_CAPTION>"
16annotation_prompt = ""
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<REGION_PROPOSAL>"
16annotation_prompt = ""
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<CAPTION_TO_PHRASE_GROUNDING>"
16annotation_prompt = "man"
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box", # can also use `mask_image` and `mask_overlay`
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<REFERRING_EXPRESSION_SEGMENTATION>"
16annotation_prompt = "man"
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="mask_image", # can also use `mask_overlay`
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<OPEN_VOCABULARY_DETECTION>"
16annotation_prompt = "man with a beard"
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).images[0]
24output.save("output.png")
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<OCR>"
16annotation_prompt = ""
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).annotations[0]
24print(output)
1import torch
2
3from diffusers.modular_pipelines import ModularPipeline
4from diffusers.utils import load_image
5
6
7pipe = ModularPipeline.from_pretrained("OzzyGT/florence-2-block", trust_remote_code=True)
8pipe.load_components(torch_dtype=torch.float16)
9pipe.to("cuda")
10
11image = load_image(
12 "https://huggingface.co/datasets/OzzyGT/diffusers-examples/resolve/main/florence-2/white_board_people.png"
13)
14
15annotation_task = "<OCR_WITH_REGION>"
16annotation_prompt = ""
17
18output = pipe(
19 image=image,
20 annotation_task=annotation_task,
21 annotation_prompt=annotation_prompt,
22 annotation_output_type="bounding_box",
23).images[0]
24output.save("output.png")