XuyaoWang's picture
Update README.md
a49a84a verified
metadata
license: apache-2.0
language:
  - en
base_model:
  - meta-llama/Meta-Llama-3.1-8B

🦙 Llama3.1-8b-vision-audio Model Card

Model Details

This repository contains a version of the LLaVA model that supports image and audio input from the Llama 3.1-8B foundation model using the PKU-Alignment/align-anything library.

  • Developed by: the PKU-Alignment Team.
  • Model Type: An auto-regressive language model based on the transformer architecture.
  • License: Non-commercial license.
  • Fine-tuned from model: meta-llama/Llama 3.1-8B.

Model Sources

How to use model (reprod.)

  • Using align-anything
from align_anything.models.llama_vision_audio_model import (
    LlamaVisionAudioForConditionalGeneration,
    LlamaVisionAudioProcessor,
)
import torch
import torchaudio
from PIL import Image

path = <path_to_model_dir>
processor = LlamaVisionAudioProcessor.from_pretrained(path)
model = LlamaVisionAudioForConditionalGeneration.from_pretrained(path)

prompt = "<|start_header_id|>user<|end_header_id|>: Where is the capital of China?\n<|start_header_id|>assistant<|end_header_id|>: "

inputs = processor(text=prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=True))

prompt = "<|start_header_id|>user<|end_header_id|>: Summarize the audio's contents.<audio>\n<|start_header_id|>assistant<|end_header_id|>: "

audio_path = "align-anything/assets/test_audio.wav"
audio, _ = torchaudio.load(audio_path)
if audio.shape[0] == 2:
    audio = audio.mean(dim=0, keepdim=True)
audio = audio.squeeze().tolist()

inputs = processor(text=prompt, raw_speech=audio, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=False))

prompt = "<|start_header_id|>user<|end_header_id|>: <image> Give an overview of what's in the image.\n<|start_header_id|>assistant<|end_header_id|>: "
image_path = "align-anything/assets/test_image.webp"
image = Image.open(image_path)

inputs = processor(text=prompt, images=image, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=1024)
print(processor.decode(outputs[0], skip_special_tokens=True))