2019-05-04 00:53:02 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-03-16 19:09:53 +01:00
|
|
|
TODAY=$(/bin/date -u +%Y%m%d)
|
2019-05-04 00:53:02 +02:00
|
|
|
|
|
|
|
MODEL_NAME="NASNet Mobile"
|
2021-12-12 20:15:52 +01:00
|
|
|
MODEL_URL="https://dl.photoprism.app/tensorflow/nasnet.zip?$TODAY"
|
2020-05-31 02:09:52 +02:00
|
|
|
MODEL_PATH="assets/nasnet"
|
2019-05-04 00:53:02 +02:00
|
|
|
MODEL_ZIP="/tmp/photoprism/nasnet.zip"
|
2019-06-06 14:44:29 +02:00
|
|
|
MODEL_HASH="f18b801354e95cade497b4f12e8d2537d04c04f6 $MODEL_ZIP"
|
2019-05-04 00:53:02 +02:00
|
|
|
MODEL_VERSION="$MODEL_PATH/version.txt"
|
2020-12-04 11:02:19 +01:00
|
|
|
MODEL_BACKUP="storage/backup/nasnet-$TODAY"
|
2019-05-04 00:53:02 +02:00
|
|
|
|
2019-12-14 15:41:37 +01:00
|
|
|
echo "Installing $MODEL_NAME model for TensorFlow..."
|
2019-05-04 00:53:02 +02:00
|
|
|
|
|
|
|
# Create directories
|
2022-03-16 19:09:53 +01:00
|
|
|
/bin/mkdir -p /tmp/photoprism
|
|
|
|
/bin/mkdir -p storage/backup
|
2019-05-04 00:53:02 +02:00
|
|
|
|
2019-05-04 01:17:39 +02:00
|
|
|
# Check for update
|
2022-03-16 19:09:53 +01:00
|
|
|
if [[ -f ${MODEL_ZIP} ]] && [[ $(/usr/bin/sha1sum ${MODEL_ZIP}) == "${MODEL_HASH}" ]]; then
|
2019-05-04 01:17:39 +02:00
|
|
|
if [[ -f ${MODEL_VERSION} ]]; then
|
|
|
|
echo "Already up to date."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Download model
|
|
|
|
echo "Downloading latest model from $MODEL_URL..."
|
2022-03-16 19:09:53 +01:00
|
|
|
/usr/bin/wget "${MODEL_URL}" -O ${MODEL_ZIP}
|
2019-05-04 01:17:39 +02:00
|
|
|
|
2022-03-16 19:09:53 +01:00
|
|
|
TMP_HASH=$(/usr/bin/sha1sum ${MODEL_ZIP})
|
2019-05-04 01:17:39 +02:00
|
|
|
|
2022-03-16 19:09:53 +01:00
|
|
|
echo "${TMP_HASH}"
|
2019-05-04 01:17:39 +02:00
|
|
|
fi
|
2019-05-04 00:53:02 +02:00
|
|
|
|
|
|
|
# Create backup
|
|
|
|
if [[ -e ${MODEL_PATH} ]]; then
|
|
|
|
echo "Creating backup of existing directory: $MODEL_BACKUP"
|
2022-03-16 19:09:53 +01:00
|
|
|
/bin/rm -rf "${MODEL_BACKUP}"
|
|
|
|
/bin/mv ${MODEL_PATH} "${MODEL_BACKUP}"
|
2019-05-04 00:53:02 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Unzip model
|
2022-03-16 19:09:53 +01:00
|
|
|
/usr/bin/unzip ${MODEL_ZIP} -d assets
|
2019-05-04 00:53:02 +02:00
|
|
|
echo "$MODEL_NAME $TODAY $MODEL_HASH" > ${MODEL_VERSION}
|
|
|
|
|
|
|
|
echo "Latest $MODEL_NAME installed."
|