Skip to content

Instantly share code, notes, and snippets.

View applenob's full-sized avatar
🏋️‍♂️
Focusing

Javen_陈俊文 applenob

🏋️‍♂️
Focusing
View GitHub Profile
@applenob
applenob / pool.py
Created August 20, 2020 06:12 — forked from fordguo/pool.py
A simple python object pool with thread safe
#-*- coding:utf-8 -*-
import Queue
from contextlib import contextmanager
class ObjectPool(object):
"""A simple object pool with thread safe"""
def __init__(self,objectFn,*args,**kwargs):
super(ObjectPool, self).__init__()
self.objectFn = objectFn
self.objectCls = None
@applenob
applenob / distributed_estimator.py
Created August 14, 2020 03:15 — forked from frnsys/distributed_estimator.py
example of a custom tensorflow estimator with distributed training
"""
Tensorflow estimator API example
References:
- <https://www.tensorflow.org/guide/custom_estimators>
- <https://github.com/tensorflow/models/blob/master/samples/core/get_started/custom_estimator.py>
- <https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/distribute/README.md>
"""
import numpy as np
import tensorflow as tf
@applenob
applenob / pb_viewer.py
Created August 12, 2020 10:30 — forked from jubjamie/pb_viewer.py
Load .pb into Tensorboard
import tensorflow as tf
from tensorflow.python.platform import gfile
with tf.Session() as sess:
model_filename ='PATH_TO_PB.pb'
with gfile.FastGFile(model_filename, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
g_in = tf.import_graph_def(graph_def)
LOGDIR='/logs/tests/1/'
train_writer = tf.summary.FileWriter(LOGDIR)
@applenob
applenob / API_request.py
Created August 19, 2019 08:30 — forked from abehmiel/API_request.py
Basic Python API request
import requests
headers = {"token": "API TOKEN"}
params = {"something": "SOMETHING"}
response = requests.get("https://www.something.com", headers=headers, params=params)
json_data = response.json()
status = response.status_code
@applenob
applenob / beamsearch.py
Created April 7, 2019 09:08 — forked from udibr/beamsearch.py
beam search for Keras RNN
# variation to https://github.com/ryankiros/skip-thoughts/blob/master/decoding/search.py
def keras_rnn_predict(samples, empty=empty, rnn_model=model, maxlen=maxlen):
"""for every sample, calculate probability for every possible label
you need to supply your RNN model and maxlen - the length of sequences it can handle
"""
data = sequence.pad_sequences(samples, maxlen=maxlen, value=empty)
return rnn_model.predict(data, verbose=0)
def beamsearch(predict=keras_rnn_predict,
@applenob
applenob / tf_serving.sh
Created January 7, 2019 02:33 — forked from jarutis/tf_serving.sh
Install Tensorflow Serving on Centos 7 (CPU)
sudo su
# Java
yum -y install java-1.8.0-openjdk-devel
# Build Esentials (minimal)
yum -y install gcc gcc-c++ kernel-devel make automake autoconf swig git unzip libtool binutils
# Extra Packages for Enterprise Linux (EPEL) (for pip, zeromq3)
yum -y install epel-release
@applenob
applenob / setup-zeromq.sh
Created December 18, 2018 09:23 — forked from katopz/setup-zeromq.sh
Setup zeromq in Ubuntu 16.04
#!/usr/bin/bash
# Download zeromq
# Ref http://zeromq.org/intro:get-the-software
wget https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz
# Unpack tarball package
tar xvzf zeromq-4.2.2.tar.gz
# Install dependency