2022-07-23 13:16:10 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2023-04-06 08:07:14 +02:00
|
|
|
# This installs the TensorFlow libraries on Linux.
|
|
|
|
# bash <(curl -s https://raw.githubusercontent.com/photoprism/photoprism/develop/scripts/dist/install-tensorflow.sh)
|
|
|
|
|
2022-07-23 13:08:24 +02:00
|
|
|
PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts:$PATH"
|
2022-03-23 08:16:01 +01:00
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
set -e
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
TF_VERSION=${TF_VERSION:-1.15.2}
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2023-04-06 08:07:14 +02:00
|
|
|
SYSTEM_ARCH=$(uname -m)
|
2022-02-25 16:33:46 +01:00
|
|
|
DESTARCH=${DESTARCH:-$SYSTEM_ARCH}
|
|
|
|
|
2023-04-06 08:07:14 +02:00
|
|
|
case $DESTARCH in
|
|
|
|
amd64 | AMD64 | x86_64 | x86-64)
|
|
|
|
DESTARCH=amd64
|
|
|
|
;;
|
|
|
|
|
|
|
|
arm64 | ARM64 | aarch64)
|
|
|
|
DESTARCH=arm64
|
|
|
|
;;
|
|
|
|
|
|
|
|
arm | ARM | aarch | armv7l | armhf)
|
|
|
|
DESTARCH=arm
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unsupported Machine Architecture: \"$DESTARCH\"" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ $1 == "auto" ]]; then
|
|
|
|
TF_DRIVER="auto";
|
|
|
|
DESTDIR="/usr";
|
|
|
|
else
|
2022-03-23 08:16:01 +01:00
|
|
|
DESTDIR=$(realpath "${1:-/usr}")
|
2022-02-25 16:33:46 +01:00
|
|
|
fi
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
TMPDIR=${TMPDIR:-/tmp}
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-12-12 20:38:44 +01:00
|
|
|
# Abort if not executed as root.
|
2022-02-19 15:32:52 +01:00
|
|
|
if [[ $(id -u) != "0" ]] && [[ $DESTDIR == "/usr" || $DESTDIR == "/usr/local" ]]; then
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Error: Run ${0##*/} as root to install in a system directory!" 1>&2
|
2022-02-19 15:32:52 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-05-21 02:34:50 +02:00
|
|
|
mkdir -p "$DESTDIR"
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ $TF_DRIVER == "auto" ]]; then
|
|
|
|
echo "Detecting driver..."
|
2023-04-06 08:07:14 +02:00
|
|
|
|
|
|
|
CPU_DETECTED=$(lshw -c processor -json 2>/dev/null)
|
|
|
|
|
|
|
|
if [[ $(echo "${CPU_DETECTED}" | jq -r '.[].capabilities.avx2') == "true" ]]; then
|
|
|
|
TF_DRIVER="avx2"
|
|
|
|
elif [[ $(echo "${CPU_DETECTED}" | jq -r '.[].capabilities.avx') == "true" ]]; then
|
|
|
|
TF_DRIVER="avx"
|
2023-04-29 11:51:06 +02:00
|
|
|
else
|
|
|
|
TF_DRIVER=""
|
2023-04-06 08:07:14 +02:00
|
|
|
fi
|
2022-02-25 16:33:46 +01:00
|
|
|
fi
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ -z $TF_DRIVER ]]; then
|
2022-02-25 17:08:17 +01:00
|
|
|
echo "Installing TensorFlow ${TF_VERSION} for ${DESTARCH^^} in \"$DESTDIR\"..."
|
2022-02-25 16:33:46 +01:00
|
|
|
INSTALL_FILE="${DESTARCH}/libtensorflow-${DESTARCH}-${TF_VERSION}.tar.gz"
|
2022-02-19 15:32:52 +01:00
|
|
|
else
|
2022-02-25 17:08:17 +01:00
|
|
|
echo "Installing TensorFlow ${TF_VERSION} for ${DESTARCH^^}-${TF_DRIVER^^} in \"$DESTDIR\"..."
|
2022-02-25 16:33:46 +01:00
|
|
|
INSTALL_FILE="${DESTARCH}/libtensorflow-${DESTARCH}-${TF_DRIVER}-${TF_VERSION}.tar.gz"
|
2022-02-19 15:32:52 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$TMPDIR/$INSTALL_FILE" ]; then
|
|
|
|
URL="https://dl.photoprism.app/tensorflow/${INSTALL_FILE}"
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Downloading ${DESTARCH} libs from \"$URL\". Please wait."
|
2022-03-23 08:16:01 +01:00
|
|
|
curl --create-dirs -fsSL -o "$TMPDIR/$INSTALL_FILE" "$URL"
|
2022-02-19 15:32:52 +01:00
|
|
|
fi
|
|
|
|
|
2022-03-01 18:16:50 +01:00
|
|
|
echo "Extracting \"$TMPDIR/$INSTALL_FILE\" to \"$DESTDIR\"."
|
2022-02-19 15:32:52 +01:00
|
|
|
|
|
|
|
if [ -f "$TMPDIR/$INSTALL_FILE" ]; then
|
2022-03-23 08:16:01 +01:00
|
|
|
tar --overwrite --mode=755 -C "$DESTDIR" -xzf "$TMPDIR/$INSTALL_FILE"
|
2022-02-19 15:32:52 +01:00
|
|
|
else
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Fatal: \"$TMPDIR/$INSTALL_FILE\" not found"
|
2022-02-19 15:32:52 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $DESTDIR == "/usr" || $DESTDIR == "/usr/local" ]]; then
|
2022-03-01 18:16:50 +01:00
|
|
|
echo "Running \"ldconfig\"."
|
2022-03-23 08:16:01 +01:00
|
|
|
ldconfig
|
2022-02-19 15:32:52 +01:00
|
|
|
else
|
|
|
|
echo "Running \"ldconfig -n $DESTDIR/lib\"."
|
2022-03-23 08:16:01 +01:00
|
|
|
ldconfig -n "$DESTDIR/lib"
|
2022-02-19 15:32:52 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done."
|