Florence-2-base-PromptGen is a model trained for
MiaoshouAI Tagger for ComfyUI.
It is an advanced image captioning tool based on the
Microsoft Florence-2 Model and fine-tuned to perfection.
Most vision models today are trained mainly for general vision recognition purposes, but when doing prompting and image tagging for model training, the format and details of the captions is quite different.
Florence-2-base-PromptGen is trained on such a purpose as aiming to improve the tagging experience and accuracy of the prompt and tagging job. The model is trained based on images and cleaned tags from Civitai so that the end result for tagging the images are the prompts you use to generate these images.
A new instruction prompt <GENERATE_PROMPT> is created for this purpose in addition to <DETAILED_CAPTION> and <MORE_DETAILED_CAPTION>.
It will respond back in danbooru tagging style with much better accuracy and proper level of details.
v0.9 Improved vision ability for uncensored data for <DETAILED_CAPTION> and <MORE_DETAILED_CAPTION>
1
2model = AutoModelForCausalLM.from_pretrained("MiaoshouAI/Florence-2-base-PromptGen", trust_remote_code=True)
3processor = AutoProcessor.from_pretrained("MiaoshouAI/Florence-2-base-PromptGen", trust_remote_code=True)
4
5prompt = "<GENERATE_PROMPT>"
6
7url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
8image = Image.open(requests.get(url, stream=True).raw)
9
10inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
11
12generated_ids = model.generate(
13 input_ids=inputs["input_ids"],
14 pixel_values=inputs["pixel_values"],
15 max_new_tokens=1024,
16 do_sample=False,
17 num_beams=3
18)
19generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
20
21parsed_answer = processor.post_process_generation(generated_text, task=prompt, image_size=(image.width, image.height))
22
23print(parsed_answer)
If you just want to use this model, you can use it under ComfyUI-Miaoshouai-Tagger
A detailed use and install instruction is already there.