Downloads · 30 days
24
3% of all-time downloads
IDEA-CCNL/Ziya-Visual-Lyrics-14B
Ziya-Visual-Lyrics-14B is a text generation model from IDEA-CCNL. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as gpl-3.0.
- Main Page:Fengshenbang - Github: Fengshenbang-LM
Downloads · 30 days
24
3% of all-time downloads
All-time downloads
854
Public
Repo size
29.7 GB
Likes
3
Public
Click a slice to open those files.
.bin29.7 GB · 100%
From the Hugging Face model README

Lyrics 是IDEA CCNL研发的大规模视觉语言模型(Large Vision Language Model, LVLM)。Lyrics在预训练(视觉语言的表征对齐)和指令微调(视觉到语言的生成学习)的两阶段训练过程中,构建了视觉细化器来提取局部视觉特征和具化的空间表征,其由图像标记(RAM)、目标检测(Grounding DINO)和语义分割(SAM)模块组成。该方法可以防止细粒度的视觉对象的缺失,造成模型产生不可修复的视觉幻觉和事实错误。
Lyrics 可以以图像、文本、视觉对象作为输入,并以文本和视觉对象的空间表征作为输出。Lyrics模型具有强大的细粒度视觉特征提取和理解能力,能够完成各种以视觉为中心的任务,包括多回合视觉对话、视觉场景理解和推理、基于常识的图像描述、指向性问答。

Lyrics is a Large Vision Language Model (LVLM) developed by IDEA CCNL. In the two-stage training process of pre-training (representation alignment of vision-language) and instruction fine-tuning (generative learning from vision to language), Lyrics construct a visual refiner to extract local visual features and embodied spatial representations. It consists of image tagging (RAM), object detection (Grounding DINO) and semantic segmentation (SAM) modules. This method can prevent the absence of fine-grained visual objects, causing irreparable visual hallucinations and factual errors in the model.
Lyrics can take images, text, and visual objects as input, and text and spatial representations of visual objects as output. The Lyrics model has a powerful ability of fine-grained visual feature extraction and understanding, and is capable of various visual-centric tasks, including multi-turn visual conversation, visual scene understanding and reasoning, commonsense-grounded image description, referential dialogue.
Lyrics 提出了MQ-Former作为视觉信号感知器来弥合多尺度的视觉和文本信息,其通过四种预训练任务来对齐ViT提供的全局视觉特征、视觉细化器提供的局部视觉特征、视觉对象的空间表征和图像摘要,使得模型具备提取语义感知的视觉对象的能力。
Lyrics proposed MQ-Former as a visual signal perceptron to bridge multi-scale visual and text information, which aligns the global visual features provided by ViT, the local visual features provided by the visual refiner, the spatial representation of visual objects and the image caption through four pre-training tasks. The model has the ability to extract semantically perceived visual objects.

import gradio as gr
from PIL import Image
import torch
import random
from fengshen.models.Lyrics.modeling_lyrics import LyricsLMForConditionalGeneration
from torchvision.transforms import Compose, ToTensor, Resize, Normalize
from transformers import InstructBlipProcessor, LlamaTokenizer, BertTokenizer, GenerationConfig
from torchvision.transforms import Normalize, Compose, RandomResizedCrop, InterpolationMode, ToTensor, RandomHorizontalFlip
import fengshen.models.Lyrics.groundingdino.transforms as T
from transformers import InstructBlipForConditionalGeneration
from peft import PeftModel
OPENAI_DATASET_MEAN = (0.48145466, 0.4578275, 0.40821073)
OPENAI_DATASET_STD = (0.26862954, 0.26130258, 0.27577711)
device = "cuda" if torch.cuda.is_available() else "cpu"
_MODEL_PATH = "your_model_path"
processor = InstructBlipProcessor.from_pretrained(os.path.join(_MODEL_PATH, "vicuna-13b_processor"), padding_side = "left")
grounding_transforms = T.Compose(
[
T.RandomResize([800], max_size=1333),
# T.RandomResize([800]),
T.ToTensor(),
T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
]
)
ram_transforms = Compose([
Resize((384, 384)),
ToTensor(),
Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
model = LyricsLMForConditionalGeneration.from_pretrained(_MODEL_PATH).to(device).eval().float()
model = PeftModel.from_pretrained(model, _MODEL_PATH).to(device).eval().float()
model.requires_grad_=False
prompt = [
"Question A",
"Question B",
]
image_url = [
'Img Path A',
'Img Path B',
]
imgs = []
for image, text in zip(image_url, prompt):
image = Image.open(image).convert("RGB")
ram_pixel_values = ram_transforms(image).unsqueeze(0).to(device)
grounding_pixel_values = [grounding_transforms(image, None)[0]]
inputs = processor(images=image, text=text, return_tensors="pt").to(device)
outputs = model.generate(
# **inputs,
pixel_values=inputs.pixel_values,
ram_pixel_values=ram_pixel_values,
grounding_pixel_values=grounding_pixel_values,
input_ids=inputs.input_ids,
attention_mask=inputs.attention_mask,
qformer_input_ids=inputs.qformer_input_ids,
qformer_attention_mask=inputs.qformer_attention_mask,
do_sample=False,
num_beams=5,
max_length=256,
min_length=4,
# repetition_penalty=1.5,
length_penalty=1.0,
# temperature=0.3,
# top_p=0.1,
# pad_token_id=32000,
)
generated_text = processor.batch_decode(outputs, skip_special_tokens=True)[0].strip()
print(generated_text, '\n')





如果您在您的工作中使用了我们的模型,可以引用我们的论文:
If you are using the resource for your work, please cite the our paper:
@misc{lu2023lyrics,
title={Lyrics: Boosting Fine-grained Language-Vision Alignment and Comprehension via Semantic-aware Visual Objects},
author={Junyu Lu and Ruyi Gan and Dixiang Zhang and Xiaojun Wu and Ziwei Wu and Renliang Sun and Jiaxing Zhang and Pingjian Zhang and Yan Song},
year={2023},
eprint={2312.05278},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
You can also cite our website:
欢迎引用我们的网站:
@misc{Fengshenbang-LM,
title={Fengshenbang-LM},
author={IDEA-CCNL},
year={2021},
howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
}