jxl-eval.sh (3060B)
1 #!/bin/bash 2 # Copyright (c) the JPEG XL Project Authors. All rights reserved. 3 # 4 # Use of this source code is governed by a BSD-style 5 # license that can be found in the LICENSE file. 6 7 set -eu 8 9 GSROOT="${GSROOT:-gs://jxl-quality}" 10 URLROOT="${URLROOT:-https://storage.googleapis.com/jxl-quality}" 11 BUILD_DIR="${BUILD_DIR:-./build}" 12 BUILD_MODE="${BUILD_MODE:-opt}" 13 DESC="${DESC:-exp}" 14 15 build_libjxl() { 16 export BUILD_DIR="${BUILD_DIR}" 17 export SKIP_TEST=1 18 ./ci.sh "${BUILD_MODE}" 19 } 20 21 build_mozjpeg() { 22 if [[ ! -d "${HOME}/mozjpeg" ]]; then 23 (cd "${HOME}" 24 git clone https://github.com/mozilla/mozjpeg.git 25 ) 26 fi 27 (cd "${HOME}/mozjpeg" 28 mkdir -p build 29 cmake -GNinja -B build 30 ninja -C build 31 ) 32 } 33 34 download_corpus() { 35 local corpus="$1" 36 local localdir="${HOME}/corpora/${corpus}" 37 local remotedir="${GSROOT}/corpora/${corpus}" 38 if [[ ! -d "${localdir}" ]]; then 39 mkdir -p "${localdir}" 40 fi 41 gsutil -m rsync "${remotedir}" "${localdir}" 42 } 43 44 create_report() { 45 local corpus="$1" 46 local codec="$2" 47 shift 2 48 local rev="$(git rev-parse --short HEAD)" 49 local originals="${URLROOT}/corpora/${corpus}" 50 if git diff HEAD --quiet; then 51 local expid="${corpus}/${rev}/base" 52 else 53 local expid="${corpus}/${rev}/${DESC}" 54 fi 55 local output_dir="benchmark_results/${expid}" 56 local bucket="eval/${USER}/${expid}" 57 local indexhtml="index.$(echo ${codec} | tr ':' '_').html" 58 local url="${URLROOT}/${bucket}/${indexhtml}" 59 local use_decompressed="--save_decompressed --html_report_use_decompressed" 60 if [[ "${codec:0:4}" == "jpeg" ]]; then 61 use_decompressed="--nohtml_report_use_decompressed" 62 fi 63 ( 64 cd "${BUILD_DIR}" 65 tools/benchmark_xl \ 66 --output_dir "${output_dir}" \ 67 --input "${HOME}/corpora/${corpus}/*.??g" \ 68 --codec="${codec}" \ 69 --save_compressed \ 70 --write_html_report \ 71 ${use_decompressed} \ 72 --originals_url="${originals}" \ 73 $@ 74 gsutil -m rsync "${output_dir}" "${GSROOT}/${bucket}" 75 echo "You can view evaluation results at:" 76 echo "${url}" 77 ) 78 } 79 80 cmd_upload_corpus() { 81 local corpus="$1" 82 gsutil -m rsync "${HOME}/corpora/${corpus}" "${GSROOT}/corpora/${corpus}" 83 } 84 85 cmd_report() { 86 local corpus="$1" 87 local codec="$2" 88 if [[ "${codec}" == *","* ]]; then 89 echo "Multiple codecs are not allowed in html report" 90 exit 1 91 fi 92 download_corpus "${corpus}" 93 if [[ "${codec:0:4}" == "jpeg" ]]; then 94 build_mozjpeg 95 export LD_LIBRARY_PATH="${HOME}/mozjpeg/build:${LD_LIBRARY_PATH:-}" 96 fi 97 build_libjxl 98 create_report "$@" 99 } 100 101 main() { 102 local cmd="${1:-}" 103 if [[ -z "${cmd}" ]]; then 104 cat >&2 <<EOF 105 Use: $0 CMD 106 107 Where CMD is one of: 108 upload_corpus CORPUS 109 Upload the image corpus in $HOME/corpora/CORPUS to the cloud 110 report CORPUS CODEC 111 Build and run benchmark of codec CODEC on image corpus CORPUS and upload 112 the results to the cloud. If the codec is jpeg, the mozjpeg library will be 113 built and used through LD_LIBRARY_PATH 114 EOF 115 echo "Usage $0 CMD" 116 exit 1 117 fi 118 cmd="cmd_${cmd}" 119 shift 120 set -x 121 "${cmd}" "$@" 122 } 123 124 main "$@"