基于 bge-vl-large 和 bge-vl-base 模型在线对图片进行检索,提供可视化页面进行操作
使用 python的 streamlit 来写页面,左侧sidebar有查询和图片浏览即可
pip install -r requirements.txt
有两种方式运行应用:
streamlit run app.py
streamlit run simple_app.py
应用将在本地启动,通常在 http://localhost:8501 访问。
app.py: 主应用程序(完整版)simple_app.py: 简化版应用程序(不依赖BGE-VL模型)model_utils.py: 模型操作工具类config.py: 配置文件test_model.py: 模型测试脚本data/: 数据目录
uploads/: 上传的图片embeddings/: 存储的嵌入向量和索引models/: 缓存的模型文件如果遇到模型加载错误,可能是由于以下原因:
解决方案:
simple_app.py 进行图片上传和浏览test_model.py 脚本测试模型加载import torch
from transformers import AutoModel
MODEL_NAME = "BAAI/BGE-VL-base" # or "BAAI/BGE-VL-large"
model = AutoModel.from_pretrained(MODEL_NAME, trust_remote_code=True) # You must set trust_remote_code=True
model.set_processor(MODEL_NAME)
model.eval()
with torch.no_grad():
query = model.encode(
images = "./assets/cir_query.png",
text = "Make the background dark, as if the camera has taken the photo at night"
)
candidates = model.encode(
images = ["./assets/cir_candi_1.png", "./assets/cir_candi_2.png"]
)
scores = query @ candidates.T
print(scores)
基于 bge-vl-large 和 bge-vl-base 模型在线对图片进行检索,提供可视化页面进行操作
使用 python的 streamlit 来写页面,左侧sidebar有查询和图片浏览即可
pip install -r requirements.txt
有两种方式运行应用:
streamlit run app.py
streamlit run simple_app.py
应用将在本地启动,通常在 http://localhost:8501 访问。
app.py: 主应用程序(完整版)simple_app.py: 简化版应用程序(不依赖BGE-VL模型)model_utils.py: 模型操作工具类config.py: 配置文件test_model.py: 模型测试脚本data/: 数据目录
uploads/: 上传的图片embeddings/: 存储的嵌入向量和索引models/: 缓存的模型文件如果遇到模型加载错误,可能是由于以下原因:
解决方案:
simple_app.py 进行图片上传和浏览test_model.py 脚本测试模型加载import torch
from transformers import AutoModel
MODEL_NAME = "BAAI/BGE-VL-base" # or "BAAI/BGE-VL-large"
model = AutoModel.from_pretrained(MODEL_NAME, trust_remote_code=True) # You must set trust_remote_code=True
model.set_processor(MODEL_NAME)
model.eval()
with torch.no_grad():
query = model.encode(
images = "./assets/cir_query.png",
text = "Make the background dark, as if the camera has taken the photo at night"
)
candidates = model.encode(
images = ["./assets/cir_candi_1.png", "./assets/cir_candi_2.png"]
)
scores = query @ candidates.T
print(scores)