Skip to content

Instantly share code, notes, and snippets.

View wronk's full-sized avatar

Mark Wronkiewicz wronk

  • Southern California
View GitHub Profile
@wronk
wronk / TF_servingPost_export_estimator_2.py
Created February 13, 2019 21:34
TF Serving blog post: export estimator after directory reorg
# The below function will be renamed to `estimator.export_saved_model` in TF 2.0
estimator.export_savedmodel(export_dir, serving_input_receiver_fn=serving_input_receiver_fn)
@wronk
wronk / TF_servingPost_send_inference_payload.py
Created February 13, 2019 19:42
TF Serving blog post: sending payload
# Send prediction request
r = requests.post(server_endpoint, data=payload)
print(json.loads(r.content)['predictions'])
@wronk
wronk / TF_servingPost_payload_format.json
Created February 13, 2019 19:40
TF Serving blog post: json payload example format
{
"instances": [
{
"image_bytes": {"b64": "iVBO...Oxs6"}
},
{
"image_bytes": {"b64": "0KGg...Pyg8"}
},
{
"image_bytes": {"b64": "AABr...EKA0"}
@wronk
wronk / TF_servingPost_inference_payload.py
Created February 13, 2019 19:38
TF Serving blog post: sending payloads for inference
import json
import base64
import requests
# Modify the name of your model (`hv_grid` here) to match what you used in Section 2
server_endpoint = 'http://localhost:8501/v1/models/hv_grid:predict'
img_fpaths = ['path/to/my_image_1.png', 'path/to/my_image_2.png']
# Load and Base64 encode images
data_samples = []
@wronk
wronk / TF_servingPost_docker_image.sh
Created February 13, 2019 19:36
TF Serving blog post: Docker image
######################################
# Pseudocode for creating Docker image
# Get the Docker TF Serving image we'll use as a foundation to build our custom image
docker pull tensorflow/serving
# Start up this TF Docker image as a container named `serving_base`
docker run -d --name serving_base tensorflow/serving
# Copy the Estimator from our local folder to the Docker container
@wronk
wronk / TF_servingPost_export_estimator.py
Created February 13, 2019 19:33
TF Serving blog post: creating and saving TF estimator object
# Define a place to save your compiled model
export_dir = '/path/to/my_exported_models/001'
# Define a path to your trained keras model and load it in as a `tf.keras.models.Model`
# If you just trained your model, you may already have it in memory and can skip the below 2 lines
model_save_fpath = '/path/to/my_model.h5'
keras_model = tf.keras.models.load_model(model_save_fpath)
# Create an Estimator object
estimator_save_dir = '/path/to/save/estimator'
@wronk
wronk / TF_servingPost_serving_receiver_fn.py
Created February 13, 2019 19:27
TF Serving blog post: serving receiver function
import os
import os.path as op
import tensorflow as tf
HEIGHT, WIDTH, CHANNELS = 256, 256, 3
def serving_input_receiver_fn():
"""Convert string encoded images (like base64 strings) into preprocessed tensors"""
@wronk
wronk / python_environment_setup.md
Last active November 27, 2023 16:18
Setting up your python development environment (with pyenv, virtualenv, and virtualenvwrapper)

Overview of Python Virtual Environments

This guide is targetted at intermediate or expert users who want low-level control over their Python environments.

When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. This helps keep each workflow in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. The guide here covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like conda). See the Using the workflow section to view the end result.


h/t @sharkinsspatial for linking me to the perfect cartoon

@wronk
wronk / Tutorial_EC2_with_Python.ipynb
Last active July 17, 2017 19:26
A basic tutorial on getting an Amazon EC2 instance running with Python for cloud computing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wronk
wronk / vertexColors_v1.py
Created October 28, 2015 22:11
vertexColors_v1.py
"""
vertexColors_v1.py
@author: wronk
Script meant to be run within blender to load source estimate data and create a series of images
(one for each time point) that can be converted into a movie. This requires that the brain surface
first be loaded into blender.
"""
# Blender specific libraries: