人工智能之基于阿里云快速搭建Llama-3.2-11B-Vision-Instruct

人工智能之基于阿里云快速搭建Llama-3.2-11B-Vision-Instruct

需求描述

  1. 基于阿里云搭建图片生成文字模型,模型名称:LLM-Research/Llama-3.2-11B-Vision-Instruct
  2. 使用上述模型输入图片生成文字,模型路径

业务实现

阿里云配置

阿里云配置如下:

代码验证

python 复制代码
import requests
import torch
from PIL import Image
from transformers import MllamaForConditionalGeneration, AutoProcessor
from modelscope import snapshot_download
model_id = "LLM-Research/Llama-3.2-11B-Vision-Instruct"
model_dir = snapshot_download(model_id, ignore_file_pattern=['*.pth'])

model = MllamaForConditionalGeneration.from_pretrained(
    model_dir,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
processor = AutoProcessor.from_pretrained(model_dir)

url = "https://vcg01.cfp.cn/creative/vcg/800/new/VCG41519623066.jpg"
image = Image.open(requests.get(url, stream=True).raw)

messages = [
    {"role": "user", "content": [
        {"type": "image"},
        {"type": "text", "text": "如果你需要对图片描述,你会怎么描述?"}
    ]}
]
input_text \
       = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(image, input_text, return_tensors="pt").to(model.device)

output = model.generate(**inputs, max_new_tokens=30)
print(processor.decode(output[0]))

结果展示如下,生成的文本信息如下:

The image shows a baby in a white outfit being held by an adult, with the baby looking at the camera and smiling.

从多次搭建的经验来看,建议在搭建模型相关的内容的时候,优先选择阿里云的相关服务,很多东西阿里云的容器云已经提供底层技术,可以很快的使用modelscope提供的操作内容进行快速的模型搭建。

相关推荐
nvvas15 分钟前
AI互联网辅助工具
人工智能·chatgpt
蹦蹦跳跳真可爱58915 分钟前
Python----目标检测(《SSD: Single Shot MultiBox Detector》论文和SSD的原理与网络结构)
人工智能·python·深度学习·神经网络·目标检测·计算机视觉
love530love21 分钟前
Windows 下部署 SUNA 项目:虚拟环境尝试与最终方案
前端·人工智能·windows·后端·docker·rust·开源
hahaha601624 分钟前
农业机器人的开发
人工智能·计算机视觉
xiaoli232728 分钟前
机器学习——SVM
人工智能·机器学习·支持向量机
智驱力人工智能33 分钟前
高密爆炸警钟长鸣:AI为化工安全戴上“智能护盾”
人工智能·算法·安全·重构·边缘计算·高密爆炸·高密化工厂
元闰子44 分钟前
AI Agent需要什么样的数据库?
数据库·人工智能·后端
蚂蚁数据AntData1 小时前
⼤模型驱动的DeepInsight Copilot在蚂蚁的技术实践
大数据·人工智能·数据分析·copilot·数据库架构
LeonDL1681 小时前
HALCON 深度学习训练 3D 图像的几种方式优缺点
人工智能·python·深度学习·3d·halcon·halcon训练3d图像·深度学习训练3d图像
jmsail1 小时前
Dynamics 365 Business Central AI Sales Order Agent Copilot
人工智能·microsoft·copilot·dynamics 365·d365 bc erp