Skip to content

Instantly share code, notes, and snippets.

View metal3d's full-sized avatar
Electrifying my brain

Patrice Ferlet metal3d

Electrifying my brain
View GitHub Profile
@metal3d
metal3d / threadpool.py
Last active December 15, 2017 04:04
ThreadPool is an asynchrone Pool thread that doesn't block when adding a thread to Queue.
# -*- encoding: utf-8 -*-
""" threadpool module, export ThreadPool class that is a non blocking
Thread Queue. Most important is that ThreadPool.add_task runs
asychroniousally. This method doesn't block process.
Example:
p = ThreadPool(2)
p.add_task(f1, arg1, arg2, test=False)
p.add_task(f1, arg2, arg3, test=False)
p.add_task(f1, arg4, arg5, test=True)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// Proposes to draw gonum plot on Jupyter using
// the fantastic lgo kernel
package jplot
// You may save that file in $GOPATH/src/jplot/jplot.go
import (
"bytes"
"github.com/yunabe/lgo/core"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@metal3d
metal3d / predictor.py
Created June 7, 2018 09:16
Sagmaker prediction
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import json_serializer
# get the name in SageMaker interface and put it there
endpoint = 'name of your endpoint'
# you can use other serializer, or none if you are able
# to get data in binary format
predictor = RealTimePredictor(endpoint, serializer=json_serializer)
@metal3d
metal3d / estimator.py
Last active June 7, 2018 09:45
Sagemaker estimator
import sagemaker as sage
import boto3
from sagemaker import get_execution_role
role = get_execution_role()
sess = sage.Session()
account = sess.boto_session.client('sts').get_caller_identity()['Account']
region = sess.boto_session.region_name # or setup the region by hand
@metal3d
metal3d / function.yaml
Created September 10, 2018 11:47
Simple Keras model loader and prediction handler for Nuclio
apiVersion: "nuclio.io/v1beta1"
kind: "Function"
spec:
runtime: "python:3.6"
handler: main:handler
minReplicas: 1
maxReplicas: 1
build:
baseImage: python:3.6-jessie
@metal3d
metal3d / make_prediction.py
Last active November 28, 2018 12:33
Keras make prediction on image sequence
from IPython.display import HTML, display
import cv2 as cv
import os
import matplotlib.pyplot as plt
def make_prediction(model, movie, nframe, classes, shape=(224, 224), nchan=3):
video = cv.VideoCapture(movie)
frames = []
while True:
grabbed, frame = video.read()
import tensorflow as tf
import numpy as np
from IPython.display import clear_output, Image, display, HTML
def strip_consts(graph_def, max_const_size=32):
"""Strip large constant values from graph_def."""
strip_def = tf.GraphDef()
for n0 in graph_def.node:
n = strip_def.node.add()
n.MergeFrom(n0)
@metal3d
metal3d / TF - graph exemple.ipynb
Last active January 20, 2019 16:37
Tensorflow basics
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.