Skip to content

Instantly share code, notes, and snippets.

@dolaameng
dolaameng / README.MD
Created June 5, 2018 11:54
classification for peta

Use PETA Dataset for Gender Detection

Steps

  1. Download dataset from here
  2. Uncompress the dataset to PETA, it should contain 10 subfolders like this
drwxrwxr-x 3 dola dola 4096 Oct 20  2014 3DPeS
drwxrwxr-x 3 dola dola 4096 Oct 20  2014 CAVIAR4REID
drwxrwxr-x 3 dola dola 4096 Oct 20  2014 CUHK
drwxrwxr-x 3 dola dola 4096 Oct 20  2014 GRID
@dolaameng
dolaameng / urllib-request_basicAuth.py
Created January 24, 2018 13:38 — forked from kaito834/urllib-request_basicAuth.py
Python 3.x snippet code for Basic Authentication HTTP request by urllib.request
#!/usr/bin/env python
#
# I tested by Python 3.4.3 on Windows 8.1
# Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
import urllib.request
import getpass
# If you access to url below via Proxy,
# set environment variable 'http_proxy' before execute this.
@dolaameng
dolaameng / tf_serve_understanding.py
Last active November 15, 2017 07:24
tensorflow saved_model, `tags` is the `key` to the metagraph
import tensorflow as tf
import numpy as np
# graph
tf.reset_default_graph()
x = tf.placeholder(tf.float32, [], name='x')
y = tf.multiply(x, 2, name='y')
z = tf.add(x, 1, name='z')
# signature

TensorFlow Serving in 10 minutes!

TensorFlow SERVING is Googles' recommended way to deploy TensorFlow models. Without proper computer engineering background, it can be quite intimidating, even for people who feel comfortable with TensorFlow itself. Few things that I've found particularly hard were:

  • Tutorial examples have C++ code (which I don't know)
  • Tutorials have Kubernetes, gRPG, Bezel (some of which I saw for the first time)
  • It needs to be compiled. That process takes forever!

After all, it worked just fine. Here I present an easiest possible way to deploy your models with TensorFlow Serving. You will have your self-built model running inside TF-Serving by the end of this tutorial. It will be scalable, and you will be able to query it via REST.

@dolaameng
dolaameng / mnist_estimator.py
Created October 19, 2017 03:34 — forked from peterroelants/mnist_estimator.py
Example using TensorFlow Estimator, Experiment & Dataset on MNIST data.
"""Script to illustrate usage of tf.estimator.Estimator in TF v1.3"""
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data as mnist_data
from tensorflow.contrib import slim
from tensorflow.contrib.learn import ModeKeys
from tensorflow.contrib.learn import learn_runner
# Show debugging output
@dolaameng
dolaameng / Eigen Cheat sheet
Created July 24, 2017 05:36 — forked from gocarlos/Eigen Cheat sheet
Cheat sheet for the linear algebra library Eigen: http://eigen.tuxfamily.org/
// A simple quickref for Eigen. Add anything that's missing.
// Main author: Keir Mierle
#include <Eigen/Dense>
Matrix<double, 3, 3> A; // Fixed rows and cols. Same as Matrix3d.
Matrix<double, 3, Dynamic> B; // Fixed rows, dynamic cols.
Matrix<double, Dynamic, Dynamic> C; // Full dynamic. Same as MatrixXd.
Matrix<double, 3, 3, RowMajor> E; // Row major; default is column-major.
Matrix3f P, Q, R; // 3x3 float matrix.
@dolaameng
dolaameng / variable_rnn_torch.py
Last active December 31, 2021 05:19
Variable Length Sequence for RNN in pytorch Example
import torch
import torch.nn as nn
from torch.autograd import Variable
batch_size = 3
max_length = 3
hidden_size = 2
n_layers =1
# container
def color_hist(img, nbins=32, bins_range=(0, 256)):
# Compute the histogram of the color channels separately
channel1_hist = np.histogram(img[:,:,0], bins=nbins, range=bins_range)
channel2_hist = np.histogram(img[:,:,1], bins=nbins, range=bins_range)
channel3_hist = np.histogram(img[:,:,2], bins=nbins, range=bins_range)
# Concatenate the histograms into a single feature vector
hist_features = np.concatenate((channel1_hist[0], channel2_hist[0], channel3_hist[0]))
# Return the individual histograms, bin_centers and feature vector
return hist_features
@dolaameng
dolaameng / save_restore_tf_model.py
Last active January 29, 2017 13:23
save/restore models in tf 0.12
######################################## train and save model in train.py
# input, output, hyperparameter as placeholders, e.g.
x = tf.placeholder(tf.float32, (None, 32, 32, 3), name="x")
y = tf.placeholder(tf.int32, (None), name="y")
keep_prob = tf.placeholder(tf.float32, name="keep_prob")
# build model
yhat, loss = build_whatevermodel(x)
train_op = whateveroptimizer.minimize(loss)
@dolaameng
dolaameng / neural_doodle.py
Created September 6, 2016 15:13
Keras neural_doodle result
'''Neural doodle with Keras
Script usage:
```
python neural_doodle.py nb_colors path_to_style_image.png path_to_style_mask.png \
[optional_path_to_content_image] \
path_to_your_doodle.png prefix_for_results
```
Examples: