安装InternVL

        InternVL        官网

        interVL        安装

完全删除环境和环境中的所有软件包

conda remove -n env_name --all 

安装

  • 克隆此存储库:

git clone https://github.com/OpenGVLab/InternVL.git
  • 创建conda虚拟环境并激活:

conda create -n inter python=3.9 -y
conda activate inter
  • 安装PyTorch>=2.0torchvision>=0.15.2使用CUDA>=11.6

    例如,要torch==2.0.1安装CUDA==11.8

conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.8 -c pytorch -c nvidia
# or
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118
  • 安装flash-attn==2.3.6

pip install flash-attn==2.3.6 --no-build-isolation
  • 安装timm==0.9.12mmcv-full==1.6.2

pip install timm==0.9.12
pip install -U openmim
mim install mmcv-full==1.6.2  # (optional, for mmsegmentation)
  • 安装transformers==4.37.2

pip install transformers==4.37.2
  • 安装其他要求:

pip install opencv-python termcolor yacs pyyaml scipy
pip install deepspeed==0.13.5
pip install pycocoevalcap tqdm

### InternVL 项目详细介绍 #### 1. 项目概述 InternVL 是一个多模态预训练模型,旨在处理图像和文本之间的跨模态任务。该项目提供了强大的视觉-语言理解能力,并支持多种应用场景,例如图文检索、视觉问答 (VQA) 和图像描述生成等[^3]。 #### 2. 安装与配置指南 为了成功运行 InternVL,需按照以下说明完成环境搭建: ##### 环境依赖 确保已安装 Python(建议版本 >=3.8),并创建虚拟环境以隔离依赖项。以下是必要的库及其最低版本要求: ```bash pip install torch>=1.9.0 torchvision transformers numpy scikit-image ``` ##### 下载模型权重 访问官方仓库链接 [https://gitcode.com/gh_mirrors/in/InternVL](https://gitcode.com/gh_mirrors/in/InternVL),下载预训练模型文件以及相关脚本。具体路径如下: ```plaintext /path/to/model_weights/ ├── config.json # 配置文件 ├── pytorch_model.bin # 模型权重 └── tokenizer_config.json # Tokenizer 设置 ``` ##### 数据准备 如果计划执行微调操作,则需要准备好标注好的数据集。推荐的数据格式为 JSON 文件,结构示例如下: ```json [ {"image_path": "path_to_image_1.jpg", "text": "A man riding a bicycle."}, {"image_path": "path_to_image_2.jpg", "text": "Two dogs playing in the park."} ] ``` --- ### 使用方法详解 #### 图文匹配任务 通过加载预训练模型实例化对象后,可输入图片路径及对应文字描述来获取相似度分数。 ```python from internvl import InternVLModel, InternVLProcessor # 初始化处理器和模型 processor = InternVLProcessor.from_pretrained("/path/to/pretrained/") model = InternVLModel.from_pretrained("/path/to/pretrained/") # 加载样例数据 image_path = "/path/to/example_image.jpg" text_input = "An image of a cat." inputs = processor(image=image_path, text=text_input, return_tensors="pt") outputs = model(**inputs) logits_per_image = outputs.logits_per_image.cpu().detach().numpy() # shape: (batch_size, num_texts) print(f"Similarity Score: {logits_per_image}") ``` #### 可视化问答 (Visual Question Answering, VQA) 针对给定的一张图片提问自然语言问题,返回最可能的答案选项。 ```python question = "What is the color of this car?" vqa_inputs = processor(image="/path/to/car_image.png", question=question, return_tensors="pt") vqa_outputs = model.vqa_forward(vqa_inputs.input_ids, vqa_inputs.attention_mask, **vqa_inputs.image_features) predicted_answer_index = int(torch.argmax(vqa_outputs)) answer_list = ["red", "blue", "green"] # 假设这是候选答案列表 print(f"The predicted answer is '{answer_list[predicted_answer_index]}'.") ``` --- ### Mini-InternVL 的特点与发展 作为 InternVL 的轻量化变体,Mini-InternVL 展现了卓越的小规模参数表现力。其核心改进包括但不限于以下几个方面[^4]: - 开发了一款名为 InternViT-300M 的高效视觉编码器,具备较强的泛化能力和鲁棒性; - 统一了模型架构、数据格式及时序安排标准,从而简化了向下游任务迁移的过程; - 实验验证显示,在仅占用少量资源的前提下即可达到接近主流大模型的效果水平; 此外还进行了深入分析探讨不同数量级样本对于领域适配效果的影响规律,为进一步优化 MLLMs 应用于专业化场景奠定了理论基础。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山山而川_R

谢谢鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值