Last active
August 26, 2026 02:35
-
-
Save llj098/0c27580364e27d53b1f386a248e36499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import absolute_import | |
| from __future__ import division | |
| from __future__ import print_function | |
| import tensorflow as tf | |
| from tensorflow.contrib.framework import add_arg_scope | |
| from tensorflow.contrib.layers.python.layers import utils | |
| slim = tf.contrib.slim | |
| def squeeze(inputs, num_outputs, fire_id): | |
| return slim.conv2d(inputs, num_outputs, 1, stride=1, scope="fire/squeeze/"+str(fire_id)) | |
| def expand(inputs, num_outputs, fire_id): | |
| with tf.variable_scope('expand'): | |
| e1x1 = slim.conv2d(inputs, num_outputs, 1, stride=1, scope='fire/ex1x1/'+str(fire_id)) | |
| e3x3 = slim.conv2d(inputs, num_outputs, 3, scope='fire/ex3x3/'+str(fire_id)) | |
| return tf.concat(3, [e1x1, e3x3]) | |
| def fire_module(x, s=16, e=64, fire_id=0): | |
| return expand(squeeze(x, s, fire_id), e, fire_id) | |
| def inference(images, _a, phase_train=True, weight_decay=0.8, reuse=None): | |
| with tf.variable_scope('SqueezeNet', 'SqueezeNet', [images], reuse=reuse): | |
| x_image = tf.reshape(images, [-1, 160, 160, 3]) | |
| net = slim.conv2d(x_image, 96, 7, scope="conv_1", stride=2) #[?,14,14,64] | |
| net = slim.max_pool2d(net, 3, stride=2, scope="maxpool1") #[?,6,6,64] | |
| net = fire_module(net, fire_id=2) | |
| net = fire_module(net, fire_id=3) | |
| net = fire_module(net, 32, 128, fire_id=4) | |
| net = slim.max_pool2d(net, 3, scope="maxpool3") | |
| net = fire_module(net, 32, 128, fire_id=5) | |
| net = fire_module(net, 48, 192, fire_id=6) | |
| net = fire_module(net, 48, 192, fire_id=7) | |
| net = fire_module(net, 64, 256, fire_id=8) | |
| net = slim.max_pool2d(net, 2, stride=2, scope="maxpool8") | |
| net = fire_module(net, 64, 256, fire_id=9) | |
| net = slim.dropout(net, 0.5) | |
| net = slim.conv2d(net, 1792, 1, scope="conv10", padding="VALID") | |
| net = slim.avg_pool2d(net, 9) | |
| net = slim.flatten(net) | |
| return net,{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| readonly SERVER_HOST="cn.fatlj.cn" | |
| readonly SERVER_SSH="root@cn.fatlj.cn" | |
| readonly SERVER_ID="X27W4GU-OTKEAAF-M24BSX6-ZOHTTOL-UP57YBW-GWMGRVK-SUF7ZR6-WKFEOQW" | |
| readonly SERVER_ADDRESS="tcp://cn.fatlj.cn:22000" | |
| readonly SERVER_HOSTKEY_SHA256="SHA256:SQ4IkEHxsbqQ0PifKrXPP1VGS3x3x8UFDpTcBYbNzms" | |
| fail() { | |
| printf '错误:%s\n' "$*" >&2 | |
| exit 1 | |
| } | |
| [[ $# -le 1 ]] || fail "用法:$0 [LOGICAL_DEVICE_NAME]" | |
| DEVICE_NAME=${1:-$(hostname -s)} | |
| [[ $DEVICE_NAME =~ ^[A-Za-z0-9._-]{1,64}$ ]] || fail "设备名只允许字母、数字、点、下划线和连字符" | |
| readonly DEVICE_NAME | |
| [[ $EUID -ne 0 ]] || fail "请以普通用户运行;脚本会在安装软件时自行调用 sudo" | |
| [[ -t 0 ]] || fail "需要交互输入密码。请用 bash <(curl -fsSL GIST_RAW_URL) 设备名 运行,不要使用 curl | bash" | |
| command -v systemctl >/dev/null || fail "当前系统不是 systemd 环境" | |
| install_packages() { | |
| command -v pacman >/dev/null || fail "此脚本仅支持 Arch Linux 及其衍生发行版" | |
| if ! command -v syncthing >/dev/null || ! command -v ssh >/dev/null; then | |
| sudo pacman -S --needed syncthing openssh | |
| fi | |
| command -v syncthing >/dev/null || fail "Syncthing 安装失败" | |
| command -v ssh >/dev/null || fail "OpenSSH 客户端安装失败" | |
| # 客户端只需要 ssh 命令连接服务器,不需要启动 sshd.service。 | |
| } | |
| pin_server_host_key() { | |
| local scan fingerprint | |
| install -d -m 700 "$HOME/.ssh" | |
| touch "$HOME/.ssh/known_hosts" | |
| chmod 600 "$HOME/.ssh/known_hosts" | |
| scan=$(ssh-keyscan -T 10 -t ed25519 "$SERVER_HOST" 2>/dev/null) || fail "无法取得服务器 SSH 主机密钥" | |
| fingerprint=$(printf '%s\n' "$scan" | ssh-keygen -lf - | awk 'NR==1 {print $2}') | |
| [[ $fingerprint == "$SERVER_HOSTKEY_SHA256" ]] || fail "服务器 SSH 指纹不匹配;拒绝连接" | |
| if ! ssh-keygen -F "$SERVER_HOST" -f "$HOME/.ssh/known_hosts" >/dev/null; then | |
| printf '%s\n' "$scan" >> "$HOME/.ssh/known_hosts" | |
| fi | |
| } | |
| has_line() { | |
| local needle=$1 | |
| grep -Fqx -- "$needle" | |
| } | |
| wait_for_syncthing() { | |
| for _ in $(seq 1 60); do | |
| if syncthing cli show system >/dev/null 2>&1; then | |
| return | |
| fi | |
| sleep 1 | |
| done | |
| fail "本机 Syncthing API 未在 60 秒内就绪" | |
| } | |
| get_device_id() { | |
| if syncthing device-id >/dev/null 2>&1; then | |
| syncthing device-id | |
| else | |
| syncthing --device-id | |
| fi | |
| } | |
| ensure_server_device() { | |
| if syncthing cli config devices list | has_line "$SERVER_ID"; then | |
| syncthing cli config devices "$SERVER_ID" name set server | |
| syncthing cli config devices "$SERVER_ID" untrusted set true | |
| if ! syncthing cli config devices "$SERVER_ID" dump-json | grep -Fq -- "$SERVER_ADDRESS"; then | |
| syncthing cli config devices "$SERVER_ID" addresses add "$SERVER_ADDRESS" | |
| fi | |
| else | |
| syncthing cli config devices add \ | |
| --device-id "$SERVER_ID" \ | |
| --name server \ | |
| --addresses "$SERVER_ADDRESS" \ | |
| --untrusted | |
| fi | |
| } | |
| ensure_folder() { | |
| local folder_id=$1 label=$2 path=$3 password=$4 | |
| install -d -m 700 "$path" | |
| if syncthing cli config folders list | has_line "$folder_id"; then | |
| syncthing cli config folders "$folder_id" label set "$label" | |
| syncthing cli config folders "$folder_id" path set "$path" | |
| syncthing cli config folders "$folder_id" type set sendreceive | |
| else | |
| syncthing cli config folders add \ | |
| --id "$folder_id" \ | |
| --label "$label" \ | |
| --path "$path" \ | |
| --type sendreceive | |
| fi | |
| if syncthing cli config folders "$folder_id" devices list | has_line "$SERVER_ID"; then | |
| syncthing cli config folders "$folder_id" devices "$SERVER_ID" encryption-password set "$password" | |
| else | |
| syncthing cli config folders "$folder_id" devices add \ | |
| --device-id "$SERVER_ID" \ | |
| --encryption-password "$password" | |
| fi | |
| } | |
| install_packages | |
| pin_server_host_key | |
| systemctl --user enable --now syncthing.service | |
| wait_for_syncthing | |
| MY_ID=$(get_device_id) | |
| printf '逻辑设备名:%s\n' "$DEVICE_NAME" | |
| printf '本机 Syncthing Device ID:%s\n' "$MY_ID" | |
| printf '\n服务器目前保存的是端到端加密副本,需要原来的文件夹加密密码。\n' | |
| read -r -s -p '请输入 obsidian 的加密密码:' OBSIDIAN_PASSWORD | |
| printf '\n' | |
| [[ -n $OBSIDIAN_PASSWORD ]] || fail "obsidian 加密密码不能为空" | |
| read -r -s -p '请输入 deft 的加密密码(直接回车表示与 obsidian 相同):' DEFT_PASSWORD | |
| printf '\n' | |
| if [[ -z $DEFT_PASSWORD ]]; then | |
| DEFT_PASSWORD=$OBSIDIAN_PASSWORD | |
| fi | |
| printf '\n正在通过 SSH 将本机登记到服务器;没有 SSH 密钥时会询问 root 密码。\n' | |
| ssh "$SERVER_SSH" /usr/local/sbin/syncthing-enroll-device "$MY_ID" "$DEVICE_NAME" | |
| ensure_server_device | |
| ensure_folder obsidian Obsidian "$HOME/syncthing/obsidian" "$OBSIDIAN_PASSWORD" | |
| ensure_folder wvlq9-mp3uf Deft "$HOME/syncthing/deft" "$DEFT_PASSWORD" | |
| unset OBSIDIAN_PASSWORD DEFT_PASSWORD | |
| printf '\n配置完成。Syncthing 将从公网服务器下载并解密数据:\n' | |
| printf ' obsidian → %s\n' "$HOME/syncthing/obsidian" | |
| printf ' deft → %s\n' "$HOME/syncthing/deft" | |
| printf '服务状态:systemctl --user status syncthing.service\n' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| readonly SERVER_HOST="cn.fatlj.cn" | |
| readonly SERVER_SSH="root@cn.fatlj.cn" | |
| readonly SERVER_ID="X27W4GU-OTKEAAF-M24BSX6-ZOHTTOL-UP57YBW-GWMGRVK-SUF7ZR6-WKFEOQW" | |
| readonly SERVER_ADDRESS="tcp://cn.fatlj.cn:22000" | |
| readonly SERVER_HOSTKEY_SHA256="SHA256:SQ4IkEHxsbqQ0PifKrXPP1VGS3x3x8UFDpTcBYbNzms" | |
| fail() { | |
| printf '错误:%s\n' "$*" >&2 | |
| exit 1 | |
| } | |
| [[ $# -le 1 ]] || fail "用法:$0 [LOGICAL_DEVICE_NAME]" | |
| DEVICE_NAME=${1:-$(hostname -s)} | |
| [[ $DEVICE_NAME =~ ^[A-Za-z0-9._-]{1,64}$ ]] || fail "设备名只允许字母、数字、点、下划线和连字符" | |
| readonly DEVICE_NAME | |
| [[ $EUID -ne 0 ]] || fail "请以普通用户运行;脚本会在安装软件时自行调用 sudo" | |
| [[ -t 0 ]] || fail "需要交互输入密码。请用 bash <(curl -fsSL GIST_RAW_URL) 设备名 运行,不要使用 curl | bash" | |
| command -v systemctl >/dev/null || fail "当前系统不是 systemd 环境" | |
| install_packages() { | |
| command -v pacman >/dev/null || fail "此脚本仅支持 Arch Linux 及其衍生发行版" | |
| if ! command -v syncthing >/dev/null || ! command -v ssh >/dev/null; then | |
| sudo pacman -S --needed syncthing openssh | |
| fi | |
| command -v syncthing >/dev/null || fail "Syncthing 安装失败" | |
| command -v ssh >/dev/null || fail "OpenSSH 客户端安装失败" | |
| # 客户端只需要 ssh 命令连接服务器,不需要启动 sshd.service。 | |
| } | |
| pin_server_host_key() { | |
| local scan fingerprint | |
| install -d -m 700 "$HOME/.ssh" | |
| touch "$HOME/.ssh/known_hosts" | |
| chmod 600 "$HOME/.ssh/known_hosts" | |
| scan=$(ssh-keyscan -T 10 -t ed25519 "$SERVER_HOST" 2>/dev/null) || fail "无法取得服务器 SSH 主机密钥" | |
| fingerprint=$(printf '%s\n' "$scan" | ssh-keygen -lf - | awk 'NR==1 {print $2}') | |
| [[ $fingerprint == "$SERVER_HOSTKEY_SHA256" ]] || fail "服务器 SSH 指纹不匹配;拒绝连接" | |
| if ! ssh-keygen -F "$SERVER_HOST" -f "$HOME/.ssh/known_hosts" >/dev/null; then | |
| printf '%s\n' "$scan" >> "$HOME/.ssh/known_hosts" | |
| fi | |
| } | |
| has_line() { | |
| local needle=$1 | |
| grep -Fqx -- "$needle" | |
| } | |
| wait_for_syncthing() { | |
| for _ in $(seq 1 60); do | |
| if syncthing cli show system >/dev/null 2>&1; then | |
| return | |
| fi | |
| sleep 1 | |
| done | |
| fail "本机 Syncthing API 未在 60 秒内就绪" | |
| } | |
| get_device_id() { | |
| if syncthing device-id >/dev/null 2>&1; then | |
| syncthing device-id | |
| else | |
| syncthing --device-id | |
| fi | |
| } | |
| ensure_server_device() { | |
| if syncthing cli config devices list | has_line "$SERVER_ID"; then | |
| syncthing cli config devices "$SERVER_ID" name set server | |
| syncthing cli config devices "$SERVER_ID" untrusted set true | |
| if ! syncthing cli config devices "$SERVER_ID" dump-json | grep -Fq -- "$SERVER_ADDRESS"; then | |
| syncthing cli config devices "$SERVER_ID" addresses add "$SERVER_ADDRESS" | |
| fi | |
| else | |
| syncthing cli config devices add \ | |
| --device-id "$SERVER_ID" \ | |
| --name server \ | |
| --addresses "$SERVER_ADDRESS" \ | |
| --untrusted | |
| fi | |
| } | |
| ensure_folder() { | |
| local folder_id=$1 label=$2 path=$3 password=$4 | |
| install -d -m 700 "$path" | |
| if syncthing cli config folders list | has_line "$folder_id"; then | |
| syncthing cli config folders "$folder_id" label set "$label" | |
| syncthing cli config folders "$folder_id" path set "$path" | |
| syncthing cli config folders "$folder_id" type set sendreceive | |
| else | |
| syncthing cli config folders add \ | |
| --id "$folder_id" \ | |
| --label "$label" \ | |
| --path "$path" \ | |
| --type sendreceive | |
| fi | |
| if syncthing cli config folders "$folder_id" devices list | has_line "$SERVER_ID"; then | |
| syncthing cli config folders "$folder_id" devices "$SERVER_ID" encryption-password set "$password" | |
| else | |
| syncthing cli config folders "$folder_id" devices add \ | |
| --device-id "$SERVER_ID" \ | |
| --encryption-password "$password" | |
| fi | |
| } | |
| install_packages | |
| pin_server_host_key | |
| systemctl --user enable --now syncthing.service | |
| wait_for_syncthing | |
| MY_ID=$(get_device_id) | |
| printf '逻辑设备名:%s\n' "$DEVICE_NAME" | |
| printf '本机 Syncthing Device ID:%s\n' "$MY_ID" | |
| printf '\n服务器目前保存的是端到端加密副本,需要原来的文件夹加密密码。\n' | |
| read -r -s -p '请输入 obsidian 的加密密码:' OBSIDIAN_PASSWORD | |
| printf '\n' | |
| [[ -n $OBSIDIAN_PASSWORD ]] || fail "obsidian 加密密码不能为空" | |
| read -r -s -p '请输入 deft 的加密密码(直接回车表示与 obsidian 相同):' DEFT_PASSWORD | |
| printf '\n' | |
| if [[ -z $DEFT_PASSWORD ]]; then | |
| DEFT_PASSWORD=$OBSIDIAN_PASSWORD | |
| fi | |
| printf '\n正在通过 SSH 将本机登记到服务器;没有 SSH 密钥时会询问 root 密码。\n' | |
| ssh "$SERVER_SSH" /usr/local/sbin/syncthing-enroll-device "$MY_ID" "$DEVICE_NAME" | |
| ensure_server_device | |
| ensure_folder obsidian Obsidian "$HOME/syncthing/obsidian" "$OBSIDIAN_PASSWORD" | |
| ensure_folder wvlq9-mp3uf Deft "$HOME/syncthing/deft" "$DEFT_PASSWORD" | |
| unset OBSIDIAN_PASSWORD DEFT_PASSWORD | |
| printf '\n配置完成。Syncthing 将从公网服务器下载并解密数据:\n' | |
| printf ' obsidian → %s\n' "$HOME/syncthing/obsidian" | |
| printf ' deft → %s\n' "$HOME/syncthing/deft" | |
| printf '服务状态:systemctl --user status syncthing.service\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment