LLMs can see and hear without any training
LLMs无需任何训练即可看到和听到:代码发布
这是论文 LLMs can see and hear without any training 的官方实现代码。
安装
使用以下命令安装 conda 环境:
conda env create -f environment.yml
conda activate MILS
数据集和检查点
下载以下数据集、标注和检查点:
MS-COCO:从官方网站这里下载 MS-COCO 验证数据集。 另外,下载 Karpathy 等人在 CVPR 2015 的论文 Deep visual-semantic alignments for generating image descriptions 中使用的 5000 个样本测试集。
wget http://images.cocodataset.org/zips/val2014.zip
wget http://images.cocodataset.org/annotations/annotations_trainval2014.zip
unzip val2014.zip
unzip annotations_trainval2014.zip
Clotho:从官方网站这里下载 clotho 数据集。 我们使用此数据集的测试集进行基准测试。
wget https://zenodo.org/records/3490684/files/clotho_audio_evaluation.7z
pip3 install dtrx
wget https://www.7-zip.org/a/7z2107-linux-x64.tar.xz
tar xf 7z2107-linux-x64.tar.xz
./7zz e clotho_audio_evaluation.7z
wget https://zenodo.org/records/3490684/files/clotho_captions_evaluation.csv
MSR-VTT:从这里下载数据集。 我们使用此数据集的测试集。
wget https://www.robots.ox.ac.uk/~maxbain/frozen-in-time/data/MSRVTT.zip
unzip MSRVTT.zip
ViClip-InternVid-10M-FLT.pth:从这里下载,并在 task_utils/video/viclip.py
中设置正确的路径。
更新路径
更新 paths.py 中的变量,以设置数据集目录和输出文件夹。
运行代码
MILS 是一种仅用于推理的方法,可以在单个 A100 GPU 上运行。 我们在八个 A100 GPU 上运行实验,下面的代码可以针对任意数量的 GPU 进行调整。
图像描述生成 (Image captioning)
使用以下命令生成图像描述:
CUDA_VISIBLE_DEVICES=0 python main_image_captioning.py --process 0 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=1 python main_image_captioning.py --process 1 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=2 python main_image_captioning.py --process 2 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=3 python main_image_captioning.py --process 3 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=4 python main_image_captioning.py --process 4 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=5 python main_image_captioning.py --process 5 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=6 python main_image_captioning.py --process 6 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=7 python main_image_captioning.py --process 7 --num_processes 8 --batch_size 32 &
图像描述保存在 OUTPUT_DIR
中。 在 eval/image_captioning.py
的 ours_result_path
变量中指定此路径,然后获取图像描述的评估指标:
python eval/image_captioning.py
音频描述生成 (Audio captioning)
使用以下命令生成音频描述:
CUDA_VISIBLE_DEVICES=0 python main_audio_captioning.py --process 0 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=1 python main_audio_captioning.py --process 1 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=2 python main_audio_captioning.py --process 2 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=3 python main_audio_captioning.py --process 3 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=4 python main_audio_captioning.py --process 4 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=5 python main_audio_captioning.py --process 5 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=6 python main_audio_captioning.py --process 6 --num_processes 8 --batch_size 32 &
CUDA_VISIBLE_DEVICES=7 python main_audio_captioning.py --process 7 --num_processes 8 --batch_size 32 &
音频描述保存在 OUTPUT_DIR
中。 在 eval/audio_captioning.py
的 address
变量中指定此路径,然后获取音频描述的评估指标:
python eval/audio_captioning.py
视频描述生成 (Video captioning)
使用以下命令生成视频描述:
CUDA_VISIBLE_DEVICES=0 python main_video_captioning.py --process 0 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=1 python main_video_captioning.py --process 1 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=2 python main_video_captioning.py --process 2 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=3 python main_video_captioning.py --process 3 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=4 python main_video_captioning.py --process 4 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=5 python main_video_captioning.py --process 5 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=6 python main_video_captioning.py --process 6 --num_processes 8 --batch_size 8 &
CUDA_VISIBLE_DEVICES=7 python main_video_captioning.py --process 7 --num_processes 8 --batch_size 8 &
视频描述保存在 OUTPUT_DIR
中。 在 eval/video_captioning.py
的 ours_result_path
变量中指定此路径,然后获取视频描述的评估指标:
python eval/video_captioning.py
高质量图像生成 (High-quality image generation)
使用以下命令生成高质量图像:
CUDA_VISIBLE_DEVICES=0 python main_image_generation_enhancement.py --process 0 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=1 python main_image_generation_enhancement.py --process 1 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=2 python main_image_generation_enhancement.py --process 2 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=3 python main_image_generation_enhancement.py --process 3 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=4 python main_image_generation_enhancement.py --process 4 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=5 python main_image_generation_enhancement.py --process 5 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=6 python main_image_generation_enhancement.py --process 6 --num_processes 8 --batch_size 4 &
CUDA_VISIBLE_DEVICES=7 python main_image_generation_enhancement.py --process 7 --num_processes 8 --batch_size 4 &
生成的图像保存在 OUTPUT_DIR
中。
风格迁移 (Style transfer)
将风格图片和内容图片放入 images/
文件夹中,然后运行:
python main_style_transfer.py --style_image <style_image> --content_image <content_image>
输出结果保存在 OUTPUT_DIR
中。
跨模态算术 (Cross-modal arithmetic)
我们首先使用图像描述生成将图像转换为文本。 此外,我们使用音频描述生成将音频转换为文本。 接下来,我们将描述组合成 LLM 的图像生成提示,请参阅论文以获取准确的提示细节。 然后将提示作为初始提示输入到使用 CustomArithmetic.csv
的高质量图像生成中。
问题
请在此仓库中开启一个 issue(建议这样做,以便更好地被看到)或联系 kumar.ashutosh@utexas.edu。
贡献
请参阅 CONTRIBUTING 文件,了解如何提供帮助。
许可证
MILS
在 CC-by-NC 4.0 license 下提供,但是从其他位置提取的第三方内容受其各自的许可证的约束,并且您可能需要承担其他法律义务或对其内容的使用施加限制。
引用
如果您使用了这项工作,请引用:
@article{ashutosh2025llms,
title={LLMs can see and hear without any training},
author={Ashutosh, Kumar and Gandelsman, Yossi and Chen, Xinlei and Misra, Ishan and Girdhar, Rohit},
journal={arXiv preprint arXiv:2501.18096},
year={2025}
}