Skip to content

Instantly share code, notes, and snippets.

View zh3389's full-sized avatar
🇨🇳

zhanghao zh3389

🇨🇳
View GitHub Profile
@zh3389
zh3389 / 数据均衡.py
Last active February 7, 2021 09:01
用于对训练模型的数据 进行数据均衡操作.
# -*- encoding:utf-8 -*-
"""
@作者:Mr.zhang
@文件名:Data_replication_equalization.py
@时间:20-6-03 上午10:54
@文档说明:
1. 使用pandas包
2. 对csv文件的数据做数据均衡
3. 通过复制的方式均衡数据
"""
@zh3389
zh3389 / Dockerfile.sh
Last active February 8, 2021 05:26
dockerfile build example 打包镜像示例
FROM python:3.6.12-slim as builder
MAINTAINER zhanghao <zhanghao_3389@163.com>
RUN apt update \
&& apt install -y ffmpeg libsm6 libxext6
ENV EXTERNAL_PYPI_SERVER=https://mirrors.aliyun.com/pypi/simple/
ENV MIRROR=mirrors.aliyun.com
ENV PATH="/opt/venv/bin:$PATH"
@zh3389
zh3389 / 启动 tensorflow serving CPU.sh
Last active February 8, 2021 05:27
用于启动tensorflow pb模型的serving服务
docker run -it -p 8501:8501 \
-v "$(pwd)/save_model:/models/docker_test" \
-e MODEL_NAME=docker_test tensorflow/serving
@zh3389
zh3389 / 启动 tensorflow serving GPU.sh
Last active February 8, 2021 05:27
用于启动tensorflow pb模型的serving服务
docker run --runtime=nvidia -it -p 8501:8501 \
-v "$(pwd)/save_model:/models/docker_test" \
-e MODEL_NAME=docker_test tensorflow/serving:latest-gpu
@zh3389
zh3389 / Tensorflow serving 查看pb接口详情.sh
Created February 8, 2021 03:47
查看部署到tensorflow serving的pb模型的接口详细情况
saved_model_cli show --dir saved_model/0 --tag_set serve --signature_def serving_default
@zh3389
zh3389 / kerasSaveModelToPB.py
Last active February 8, 2021 03:56
用于keras保存可部署的pb格式的模型
import keras
import os
import tensorflow as tf
from tensorflow.python.util import compat
from keras import backend as K
def export_savedmodel(model):
'''
传入keras model会自动保存为pb格式
'''
@zh3389
zh3389 / tensorflowSaveModelToPB.py
Last active February 8, 2021 05:30
tensorflow sample_save 保存模型示例
import tensorflow as tf
# The export path contains the name and the version of the model
tf.keras.backend.set_learning_phase(0) # Ignore dropout at inference
model = tf.keras.models.load_model('./inception.h5') # 需要加载的模型路径
export_path = '../my_image_classifier/1' # 将要导出模型的路径
# Fetch the Keras session and save the model
# The signature definition is defined by the input and output tensors
# And stored with the default serving key
@zh3389
zh3389 / docker进入镜像.sh
Last active February 8, 2021 05:25
docker使用命令进入没有守护程序的镜像
docker run --rm -it --entrypoint bash nmtwizard/opennmt-tf
docker run -v $PWD:/root/data --rm -it --entrypoint bash nmtwizard/opennmt-tf
from concurrent.futures import ThreadPoolExecutor
def run(msg):
pass
data = list()
with ThreadPoolExecutor() as executor:
for _ in tqdm(executor.map(run, data), total=len(data)):
pass
import fnmatch, os
def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result