由这篇文章启发:知乎

ENV:

DEPENDENCY:

absl-py==1.4.0
astor==0.8.1
astunparse==1.6.3
bert-tensorflow==1.0.1
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.0.1
flatbuffers==23.1.21
gast==0.2.2
google-auth==2.16.2
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.52.0
h5py==3.8.0
idna==3.4
importlib-metadata==6.0.0
keras==2.8.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
libclang==15.0.6.1
Markdown==3.4.1
MarkupSafe==2.1.2
numpy==1.19.5
oauthlib==3.2.2
opt-einsum==3.3.0
protobuf==3.19.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.28.2
requests-oauthlib==1.3.1
rsa==4.9
six==1.16.0
tensorboard==1.15.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==1.15.0
tensorflow-estimator==1.15.1
tensorflow-io-gcs-filesystem==0.31.0
termcolor==2.2.0
typing-extensions==4.5.0
urllib3==1.26.14
Werkzeug==2.2.3
wrapt==1.15.0
zipp==3.15.0

CMD:

Train

python3.7 run_classifier.py \
  --task_name=spam \
  --do_train=true \
  --do_eval=true \
  --do_save=true \
  --save_dir=/root/model \
  --data_dir=/root/bertdemo-master \
  --vocab_file=/root/chinese_L-12_H-768_A-12/vocab.txt \
  --bert_config_file=/root/chinese_L-12_H-768_A-12/bert_config.json \
  --init_checkpoint=/root/chinese_L-12_H-768_A-12/bert_model.ckpt \
  --max_seq_length=128 \
  --train_batch_size=32 \
  --learning_rate=2e-5 \
  --num_train_epochs=3.0 \
  --output_dir=/root/output

Model Serving

Install tensorflow-model-server

echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list
curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install tensorflow-model-server

Run model serving

tensorflow_model_server \
  --port=8500 \
  --rest_api_port=8501 \
  --model_name='spam' \
  --model_base_path="/root/model"

HTTP test

http://localhost:8501/v1/models/spam:predict

最后修改:2023 年 03 月 05 日
如果觉得我的文章对你有用,请随意赞赏