-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Florence finetunes in workflows #794
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8f5dd02
Florence fts working
probicheaux c3a3dd8
Inference tweaks
probicheaux ab24790
Add in replacement block
probicheaux fcbf977
Style
probicheaux 5d6ece1
Merge branch 'main' into florence-2-fts-in-workflows
probicheaux 917d784
Address pr comments
probicheaux 93c8c21
Merge branch 'florence-2-fts-in-workflows' of github.com:roboflow/inf…
probicheaux f58f51c
Merge branch 'main' into florence-2-fts-in-workflows
probicheaux d6bfbe0
Bugfix
probicheaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
inference/core/workflows/core_steps/models/foundation/florence2/v2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import List, Literal, Optional, Type, Union | ||
|
||
import supervision as sv | ||
from pydantic import ConfigDict, Field | ||
|
||
from inference.core.workflows.core_steps.models.foundation.florence2.v1 import ( | ||
LONG_DESCRIPTION, | ||
BaseManifest, | ||
Florence2BlockV1, | ||
GroundingSelectionMode, | ||
TaskType, | ||
) | ||
from inference.core.workflows.execution_engine.entities.base import ( | ||
Batch, | ||
WorkflowImageData, | ||
) | ||
from inference.core.workflows.execution_engine.entities.types import ( | ||
ROBOFLOW_MODEL_ID_KIND, | ||
WorkflowParameterSelector, | ||
) | ||
from inference.core.workflows.prototypes.block import BlockResult, WorkflowBlockManifest | ||
|
||
|
||
class V2BlockManifest(BaseManifest): | ||
type: Literal["roboflow_core/florence_2@v2"] | ||
model_id: Union[WorkflowParameterSelector(kind=[ROBOFLOW_MODEL_ID_KIND]), str] = ( | ||
Field( | ||
default="florence-2-base", | ||
description="Model to be used", | ||
examples=["florence-2-base"], | ||
json_schema_extra={"always_visible": True}, | ||
) | ||
) | ||
model_config = ConfigDict( | ||
json_schema_extra={ | ||
"name": "Florence-2 Model", | ||
"version": "v2", | ||
"short_description": "Run Florence-2 on an image", | ||
"long_description": LONG_DESCRIPTION, | ||
"license": "Apache-2.0", | ||
"block_type": "model", | ||
"search_keywords": ["Florence", "Florence-2", "Microsoft"], | ||
"is_vlm_block": True, | ||
"task_type_property": "task_type", | ||
}, | ||
protected_namespaces=(), | ||
) | ||
|
||
|
||
class Florence2BlockV2(Florence2BlockV1): | ||
@classmethod | ||
def get_manifest(cls) -> Type[WorkflowBlockManifest]: | ||
return V2BlockManifest | ||
|
||
def run( | ||
self, | ||
images: Batch[WorkflowImageData], | ||
model_id: str, | ||
task_type: TaskType, | ||
prompt: Optional[str], | ||
classes: Optional[List[str]], | ||
grounding_detection: Optional[ | ||
Union[Batch[sv.Detections], List[int], List[float]] | ||
], | ||
grounding_selection_mode: GroundingSelectionMode, | ||
) -> BlockResult: | ||
return super().run( | ||
probicheaux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
images=images, | ||
model_version=model_id, | ||
task_type=task_type, | ||
prompt=prompt, | ||
classes=classes, | ||
grounding_detection=grounding_detection, | ||
grounding_selection_mode=grounding_selection_mode, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in UI we do not display multiple versions of the same block treating newer versions as the ones shipping super-set of features - in this case (if I understand correctly) - you either choose pre-trained model (
v1
) or fine-tuned one (v2
) - which needs to changeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2 can use the pre-trained ones by passing
florence-2-base
orflorence-2-large
as the model_id (same as before)! This is analogous to yolov8n-640 for object detection. This should show up in the model selector pop up but isn't -- we tried to do this in the frontend similar to yolov8n-640 or whatever, but its not working right now. Will look into it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the field is pre populated with the right pretrained value so ppl should not see a difference unless they try