FiLM框架运行CLEVR数据集

1.搭建虚拟环境

virtualenv -p python3 .env       # Create virtual environment
source .env/bin/activate         # Activate virtual environment
pip install -r requirements.txt  # Install dependencies
echo $PWD > .env/lib/python3.5/site-packages/iep.pth # Add this package to virtual environment
# Work for a while ...
deactivate # Exit virtual environment

2.数据集的预处理

CLEVR数据集

(1)下载解压
(2)提取图像特征
提取ResNet-101特征 【train\val\test类似】

python scripts/extract_features.py \
  --input_image_dir data/CLEVR_v1.0/images/train \
  --output_h5_file data/train_features.h5

h5是什么格式的文件?
(3)预处理question【train\val\test类似】

python scripts/preprocess_questions.py \
  --input_questions_json data/CLEVR_v1.0/questions/CLEVR_train_questions.json \
  --output_h5_file data/train_questions.h5 \
  --output_vocab_json data/vocab.json

vocab.json这个词汇表stores the mapping between tokens and indices for questions and programs。训练的时候生成vocab.json,可以重复利用在val\test那里用作输入

python scripts/preprocess_questions.py \
  --input_questions_json data/CLEVR_v1.0/questions/CLEVR_val_questions.json \
  --output_h5_file data/val_questions.h5 \
  --input_vocab_json data/vocab.json

3.训练
训练细节和“ Program Generator + Execution Engine model”高度一致,虽然我们是单步训练,他们是三步训练。
三步训练:包括PG、EE、PG+EE
(1)训练Program Generator

python scripts/train_model.py \
  --model_type PG \
  --num_train_samples 18000 \   # a small number of ground-truth programs
  --num_iterations 20000 \
  --checkpoint_every 1000 \
  --checkpoint_path data/program_generator.pt

(2)训练 Execution Engine

python scripts/train_model.py \
  --model_type EE \
  --program_generator_start_from data/program_generator.py \   #用的是PG预测生成的输出
  --num_iterations 100000 \
  --checkpoint_path data/execution_engine.pt

(3)联合训练PG+EE【无gt联合微调】

python scripts/train_model.py \
  --model_type PG+EE \
  --program_generator_start_from data/program_generator.pt \
  --execution_engine_start_from data/execution_engine.pt \
  --checkpoint_path data/joint_pg_ee.pt

FiLM的单步训练,直接运行下面的语句就开始训练了。

sh scripts/train/film.sh

生成film.pt文件(模型),film.log文件,film.pt.json文件


4.测试

python scripts/run_model.py \
  --program_generator data/program_generator.pt \
  --execution_engine data/execution_engine.pt \
  --input_question_h5 data/val_questions.h5 \
  --input_features_h5 data/val_features.h5

联合微调版

python scripts/run_model.py \
  --program_generator data/joint_pg_ee.pt \
  --execution_engine data/joint_pg_ee.pt \
  --input_question_h5 data/val_questions.h5 \
  --input_features_h5 data/val_features.h5
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,309评论 19 139
  • 这个教程默认代码、预训练模型、测试部分的代码已经下载好,环境也已经编译好 【训练】 modelsmodels文件夹...
    wendy_要努力努力再努力阅读 1,484评论 0 3
  • 把当前目录作为Root Document只需要这条命令即可:php -S localhost:3300 也可以指定...
    绚烂的时光阅读 804评论 0 1
  • 雨后清晨气象新, 金风细细入帘门。 时光易老情难却, 莫教年华负此身。
    沂河生阅读 1,818评论 0 3
  • 百度释义:客情关系是指产品、服务提供者,与其客户之间的情感联系!从某种意义上来说,客情关系是公共关系营销的一个分支...
    8b15323bc64a阅读 2,234评论 0 0

友情链接更多精彩内容