Skip to content

Commit

Permalink
add florence model; update demo.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
yadong-lu committed Oct 25, 2024
1 parent b510e61 commit cafc5ef
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 242 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
weights/
weights/icon_caption_blip2
weights/icon_caption_florence
Binary file modified __pycache__/utils.cpython-312.pyc
Binary file not shown.
393 changes: 164 additions & 229 deletions demo.ipynb

Large diffs are not rendered by default.

Binary file added imgs/google_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed imgs/mobile_4.png
Binary file not shown.
Binary file removed imgs/pc_1.png
Binary file not shown.
Binary file removed imgs/saved_image_demo.png
Binary file not shown.
Binary file removed imgs/settings.png
Binary file not shown.
Binary file added imgs/windows_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/windows_multitab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ opencv-python-headless
gradio
dill
accelerate

timm
Binary file modified util/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified util/__pycache__/box_annotator.cpython-312.pyc
Binary file not shown.
30 changes: 19 additions & 11 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,27 @@
import torchvision.transforms as T


def get_caption_model_processor(model_name_or_path="Salesforce/blip2-opt-2.7b", device=None):
def get_caption_model_processor(model_name, model_name_or_path="Salesforce/blip2-opt-2.7b", device=None):
if not device:
device = "cuda" if torch.cuda.is_available() else "cpu"
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
if device == 'cpu':
model = Blip2ForConditionalGeneration.from_pretrained(
model_name_or_path, device_map=None, torch_dtype=torch.float32
)
else:
model = Blip2ForConditionalGeneration.from_pretrained(
model_name_or_path, device_map=None, torch_dtype=torch.float16
)
if model_name == "blip2":
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
if device == 'cpu':
model = Blip2ForConditionalGeneration.from_pretrained(
model_name_or_path, device_map=None, torch_dtype=torch.float32
)
else:
model = Blip2ForConditionalGeneration.from_pretrained(
model_name_or_path, device_map=None, torch_dtype=torch.float16
).to(device)
elif model_name == "florence2":
from transformers import AutoProcessor, AutoModelForCausalLM
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-base", trust_remote_code=True)
if device == 'cpu':
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.float32, trust_remote_code=True)
else:
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.float16, trust_remote_code=True).to(device)
return {'model': model.to(device), 'processor': processor}


Expand Down
Binary file added weights/icon_detect/best.pt
Binary file not shown.

0 comments on commit cafc5ef

Please sign in to comment.