|
| 1 | +Steps to run the COCO dataset for Image Captioning |
| 2 | +================================================== |
| 3 | +##### (1) Env setup |
| 4 | + export CAFFE_ON_SPARK=/Users/mridul/bigml/CaffeOnSpark |
| 5 | + export DYLD_LIBRARY_PATH=${CAFFE_ON_SPARK}/caffe-public/distribute/lib:${CAFFE_ON_SPARK}/caffe-distri/distribute/lib |
| 6 | + export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/cuda/lib:/usr/local/mkl/lib/intel64/ |
| 7 | + export LD_LIBRARY_PATH=${DYLD_LIBRARY_PATH} |
| 8 | + export SPARK_HOME=/Users/mridul/bigml/spark-1.6.0-bin-hadoop2.6 |
| 9 | + export PATH=${SPARK_HOME}/bin:${PATH} |
| 10 | + export PYSPARK_PYTHON=Python2.7.10/bin/python |
| 11 | + export PYTHONPATH=$PYTHONPATH:caffeonsparkpythonapi.zip:caffe_on_grid_archive/lib64:/usr/local/cuda-7.5/lib64 |
| 12 | + export LD_LIBRARY_PATH=Python2.7.10/lib:/usr/local/cuda/lib:caffe_on_grid_archive/lib64/mkl/intel64/:${LD_LIBRARY_PATH} |
| 13 | + export DYLD_LIBRARY_PATH=Python2.7.10/lib:/usr/local/cuda/lib:caffe_on_grid_archive/lib64/mkl/intel64/:${LD_LIBRARY_PATH} |
| 14 | + export IPYTHON_ROOT=~/Python2.7.10 |
| 15 | + unset SPARK_CONF_DIR |
| 16 | + |
| 17 | +##### (2) Download the coco dataset if required |
| 18 | + |
| 19 | + mkdir -p /tmp/coco |
| 20 | + pushd /tmp/coco |
| 21 | + wget http://msvocds.blob.core.windows.net/coco2014/train2014.zip |
| 22 | + wget http://msvocds.blob.core.windows.net/coco2014/val2014.zip |
| 23 | + wget http://msvocds.blob.core.windows.net/coco2014/test2014.zip |
| 24 | + wget http://msvocds.blob.core.windows.net/annotations-1-0-3/captions_train-val2014.zip |
| 25 | + unzip *.zip |
| 26 | + popd |
| 27 | + |
| 28 | +##### (3) Create the input dataframe from cocodataset |
| 29 | + #-output the root directory for producing all the outputs |
| 30 | + #-imageRoot the root input directory for all the images (required) |
| 31 | + #-captionFile the input json which contains the image details and captions in coco format (check on mscoco.org) |
| 32 | + #-outputFormat the format of the output file to produce the dataframe |
| 33 | + #-imageCaptionDFDir the dataframe output dir name for images and their captions under -output, in json |
| 34 | + #-vocabDir the vocabulary for the dataframe under -output in desired outputFormat |
| 35 | + #-embeddingDFDir the dataframe output dir name for embedded images and their captions under -output in desired outputFormat |
| 36 | + |
| 37 | + pushd ${CAFFE_ON_SPARK}/data/ |
| 38 | + spark-submit --master ${MASTER_URL} --deploy-mode client \ |
| 39 | + --conf spark.executor.extraClassPath=${CAFFE_ON_SPARK}/caffe-grid/target/caffe-grid-0.1-SNAPSHOT-jar-with-dependencies.jar \ |
| 40 | + --conf --driver-class-path=${CAFFE_ON_SPARK}/caffe-grid/target/caffe-grid-0.1-SNAPSHOT-jar-with-dependencies.jar \ |
| 41 | + --class com.yahoo.ml.caffe.tools.CocoDataSetConverter \ |
| 42 | + ${CAFFE_ON_SPARK}/caffe-grid/target/caffe-grid-0.1-SNAPSHOT-jar-with-dependencies.jar \ |
| 43 | + -output /tmp/coco/parquet/ \ |
| 44 | + -imageRoot /tmp/coco/images/train2014/ \ |
| 45 | + -captionFile /tmp/coco/annotations/captions_train2014.json \ |
| 46 | + -outputFormat parquet \ |
| 47 | + -imageCaptionDFDir df_image_caption_train2014 \ |
| 48 | + -vocabDir vocab \ |
| 49 | + -vocabSize 8800 \ |
| 50 | + -embeddingDFDir df_embedded_train2014 |
| 51 | + popd |
| 52 | + |
| 53 | +##### (4) Train the image model |
| 54 | + pushd ${CAFFE_ON_SPARK}/data/ |
| 55 | + spark-submit --master ${MASTER_URL} \ |
| 56 | + --files train_val.prototxt,solver.prototxt \ |
| 57 | + --conf spark.cores.max=${TOTAL_CORES} \ |
| 58 | + --conf spark.task.cpus=${CORES_PER_WORKER} \ |
| 59 | + --conf spark.driver.extraLibraryPath="${DYLD_LIBRARY_PATH}" \ |
| 60 | + --conf spark.executorEnv.DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}" \ |
| 61 | + --class com.yahoo.ml.caffe.CaffeOnSpark \ |
| 62 | + ${CAFFE_ON_SPARK}/caffe-grid/target/caffe-grid-0.1-SNAPSHOT-jar-with-dependencies.jar \ |
| 63 | + -train \ |
| 64 | + -conf solver.prototxt \ |
| 65 | + -model /tmp/coco/bvlc_reference_caffenet.caffemodel \ |
| 66 | + -devices 1 |
| 67 | + hadoop fs -ls /tmp/coco/bvlc_reference_caffenet.caffemodel |
| 68 | + popd |
| 69 | +##### (5) Train the lstm |
| 70 | + pushd ${CAFFE_ON_SPARK}/data/ |
| 71 | + spark-submit --master ${MASTER_URL} \ |
| 72 | + --files lrcn_cos.prototxt,lrcn_solver.prototxt \ |
| 73 | + --conf spark.cores.max=${TOTAL_CORES} \ |
| 74 | + --conf spark.task.cpus=${CORES_PER_WORKER} \ |
| 75 | + --conf spark.driver.extraLibraryPath="${DYLD_LIBRARY_PATH}" \ |
| 76 | + --conf spark.executorEnv.DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}" \ |
| 77 | + --class com.yahoo.ml.caffe.CaffeOnSpark \ |
| 78 | + ${CAFFE_ON_SPARK}/caffe-grid/target/caffe-grid-0.1-SNAPSHOT-jar-with-dependencies.jar \ |
| 79 | + -train \ |
| 80 | + -conf lrcn_solver.prototxt \ |
| 81 | + -devices 1 \ |
| 82 | + -resize \ |
| 83 | + -weights /tmp/coco/bvlc_reference_caffenet.caffemodel \ |
| 84 | + -model /tmp/coco/parquet/lrcn_coco.model |
| 85 | + popd |
| 86 | + |
| 87 | +##### (6) Submit the data for inference |
| 88 | + Note that the below files also need to be shipped as shown |
| 89 | + #-model the image-lstm pretrained model to ship |
| 90 | + #-imagenet the image network definition |
| 91 | + #-lstmnet the lstm network definition |
| 92 | + #-vocab the vocabulary file (produced from above) for the given train set |
| 93 | + #-input the input embedding produced above |
| 94 | + #-output the path where to write the desired output |
| 95 | + |
| 96 | + pushd ${CAFFE_ON_SPARK}/data/ |
| 97 | + ln -s ~/Python2.7.10 Python2.7.10 |
| 98 | + unzip ${CAFFE_ON_SPARK}/caffe-grid/target/caffeonsparkpythonapi.zip |
| 99 | + cat /tmp/coco/parquet/vocab/part* > vocab.txt |
| 100 | + rm -rf /tmp/coco/parquet/df_caption_results_train2014 |
| 101 | + spark-submit --master ${MASTER_URL} \ |
| 102 | + --conf spark.cores.max=${TOTAL_CORES} \ |
| 103 | + --conf spark.task.cpus=${CORES_PER_WORKER} \ |
| 104 | + --conf spark.driver.extraLibraryPath="${DYLD_LIBRARY_PATH}:Python2.7.10/lib" \ |
| 105 | + --conf spark.executorEnv.LD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:Python2.7.10/lib" \ |
| 106 | + --conf spark.pythonargs="-model /tmp/coco/parquet/lrcn_coco.model -imagenet deploy.prototxt -lstmnet lrcn_word_to_preds.deploy.prototxt -vocab vocab.txt -input /tmp/coco/parquet/df_embedded_train2014 -output /tmp/coco/parquet/df_caption_results_train2014" examples/ImageCaption.py |
| 107 | + popd |
| 108 | +##### (7) Launch IPython Notebook |
| 109 | + export IPYTHON_OPTS="notebook --no-browser --ip=127.0.0.1" |
| 110 | + pushd ${CAFFE_ON_SPARK}/data/ |
| 111 | + ln -s ~/Python2.7.10 Python2.7.10 |
| 112 | + unzip ${CAFFE_ON_SPARK}/caffe-grid/target/caffeonsparkpythonapi.zip |
| 113 | + cat /tmp/coco/parquet/vocab/part* > vocab.txt |
| 114 | + pyspark --master ${MASTER_URL} --deploy-mode client \ |
| 115 | + --conf spark.driver.extraLibraryPath="${DYLD_LIBRARY_PATH}:Python2.7.10/lib" \ |
| 116 | + --conf spark.executorEnv.LD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:Python2.7.10/lib" \ |
| 117 | + --files "${CAFFE_ON_SPARK}/data/deploy.prototxt,${CAFFE_ON_SPARK}/data/vocab.txt,${CAFFE_ON_SPARK}/data/lrcn_word_to_preds.deploy.prototxt,${CAFFE_ON_SPARK}/data/caffe/_caffe.so" \ |
| 118 | + --py-files "${CAFFE_ON_SPARK}/caffe-grid/target/caffeonsparkpythonapi.zip" |
| 119 | + |
0 commit comments