Downloads · 30 days
12
1% of all-time downloads
Falconsai/florence-2-invoice
florence-2-invoice is a image-text-to-text model from Falconsai. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for transformers.
- Developed by: Michael Stattelman for Falcons.ai - Funded by [optional]: Falcons.ai
Downloads · 30 days
12
1% of all-time downloads
All-time downloads
1.9K
Public
Parameters
1.9M
7.7 MB on disk
Likes
7
Public
Click a slice to open those files.
.safetensors15.5 MB · 78%
From the Hugging Face model README
Falconsai/florence-2-invoice is a fine-tuned version of the microsoft/Florence-2-base-ft model. This model has been specifically trained to identify and extract key fields from invoice images. The fine-tuning process utilized a curated dataset of invoices annotated to recognize the following fields:
The base model used for fine-tuning is microsoft/Florence-2-base-ft, a state-of-the-art vision model developed by Microsoft.
The fine-tuning process was carried out using a Low-Rank Adaptation (LoRa) configuration with the following parameters:
LoraConfig(
r=8,
lora_alpha=8,
target_modules=["q_proj", "o_proj", "k_proj", "v_proj", "linear", "Conv2d", "lm_head", "fc2"],
task_type="CAUSAL_LM",
lora_dropout=0.05,
bias="none",
inference_mode=False,
use_rslora=True,
init_lora_weights="gaussian",
revision=REVISION
)
The fine-tuning process was conducted on an Alienware system, ensuring robust performance and efficient training.
The model was trained on a curated dataset of invoice images. Each invoice was annotated to identify the specific fields listed above. This dataset ensured that the model learned to accurately detect and extract key information from various invoice formats.
To use this model for inference, you can load it via the Hugging Face Transformers library:
import torch
from PIL import Image
from transformers import (
AdamW,
AutoModelForCausalLM,
AutoProcessor,
get_scheduler
)
def run_florence_invoice(img, task_prompt, text_input=None):
image = Image.open(img)
# Ensure the image is in RGB format
if image.mode != "RGB":
image = image.convert("RGB")
model_id2 = "Falconsai/florence-2-invoice"
model = AutoModelForCausalLM.from_pretrained(model_id2, trust_remote_code=True).eval().cuda()
processor = AutoProcessor.from_pretrained(model_id2, trust_remote_code=True)
with torch.no_grad():
if text_input is None:
prompt = task_prompt
else:
prompt = task_prompt + text_input
inputs = processor(text=prompt, images=image, return_tensors="pt")
generated_ids = model.generate(
input_ids=inputs["input_ids"].cuda(),
pixel_values=inputs["pixel_values"].cuda(),
max_new_tokens=1024,
num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
del model
del processor
return parsed_answer
## Call the function as follows:
### Return all fields identified:
img = './invoice.png'
run_florence_invoice(img, '<OD>')
### Return Specific field
img = './invoice.png'
results = run_florence_invoice(img, "<CAPTION_TO_PHRASE_GROUNDING>", text_input="invoice date")
This model is ideal for automating the extraction of key information from invoices in various business and financial applications. It can significantly reduce the manual effort required for data entry and validation in accounting and bookkeeping processes.
The model has been evaluated on a held-out set of annotated invoice images. The evaluation metrics used included precision, recall, and F1-score for each of the identified fields. Detailed evaluation results and visualizations are available in the results directory of the repository.
For more information or questions about this model, please contact the developers at [[email protected]].
This model is licensed under the MIT License. See the LICENSE file for more details.
We would like to thank Microsoft for the development of the Florence2 vision model and the broader machine learning community for their contributions and support.