Skip to content

[Florence-2] SyntaxWarning: invalid escape sequence '\d' in processing_florence2.py #38498

Open
@hookylee

Description

@hookylee

System Info

System Info
OS
nt
Python Version
3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
Embedded Python
false
Pytorch Version
2.7.0+cu128
Arguments
ComfyUI\main.py --windows-standalone-build
RAM Total
31.93 GB
RAM Free
9.09 GB
Devices

Who can help?

hookylee@gmail.com

Hi Transformers team,

While using the Florence-2-base-ft model through HuggingFace Transformers, I encountered the following Python warning:

SyntaxWarning: invalid escape sequence '\d'
C:\Users[USER].cache\huggingface\modules\transformers_modules\Florence-2-base-ft\processing_florence2.py:515

This comes from the following code in processing_florence2.py:
PATTERN: 'r<time_(\d+)><time_(\d+)>([a-zA-Z0-9 ]+)'

The issue is that the regex pattern is written as a regular string instead of a raw string, causing Python to interpret \d as an invalid escape sequence.

Suggested fix:
Change this:
PATTERN: 'r<time_(\d+)><time_(\d+)>([a-zA-Z0-9 ]+)'

To this:
PATTERN: r'<time_(\d+)><time_(\d+)>([a-zA-Z0-9 ]+)'

This will avoid the SyntaxWarning during runtime.

Thank you for maintaining this library and for the Florence-2 integration!

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

...

Expected behavior

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions