Skip to content

Instantly share code, notes, and snippets.

View detrin's full-sized avatar
⚙️

Daniel Herman detrin

⚙️
View GitHub Profile
@detrin
detrin / client.py
Created August 7, 2021 20:04
Serve ML model with Flask REST API - 4
import requests
test_data = [
[8.0, 390.0, 190.0, 3850.0, 8.5, 70.0, 0.0, 0.0, 1.0],
[8.0, 360.0, 215.0, 4615.0, 14.0, 70.0, 0.0, 0.0, 1.0],
[8.0, 304.0, 193.0, 4732.0, 18.5, 70.0, 0.0, 0.0, 1.0],
[4.0, 113.0, 95.0, 2228.0, 14.0, 71.0, 0.0, 1.0, 0.0],
[6.0, 232.0, 100.0, 2634.0, 13.0, 71.0, 0.0, 0.0, 1.0],
]
@detrin
detrin / app.py
Created August 7, 2021 19:54
Serve ML model with Flask REST API - 3
import sys
from flask import Flask, request, jsonify
import traceback
import pandas as pd
import numpy as np
import json
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing
@detrin
detrin / train_model.py
Created August 7, 2021 19:34
Serve ML model with Flask REST API - 2
normalizer = preprocessing.Normalization(axis=-1)
normalizer.adapt(np.array(train_features))
model = keras.Sequential(
[
normalizer,
layers.Dense(64, activation="relu"),
layers.Dense(64, activation="relu"),
layers.Dense(1),
]
@detrin
detrin / fetch_data.py
Created August 7, 2021 19:24
Serve ML model with Flask REST API - 1
url = "http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data"
column_names = [
"MPG",
"Cylinders",
"Displacement",
"Horsepower",
"Weight",
"Acceleration",
"Model Year",
"Origin",
@detrin
detrin / main.py
Created August 5, 2021 14:11
Testing selenium with chromium-chromedriver on Raspberry Pi
from pyvirtualdisplay import Display
from selenium import webdriver
import time
import numpy as np
display = Display(visible=0, size=(1920, 1080))
display.start()
options = webdriver.ChromeOptions()
options.add_argument("--kiosk")
import numpy as np
import math
from mayavi import mlab
mlab.clf()
x, y, z = np.mgrid[-3:3:50j, -3:3:50j, -3:3:50j]
# Plot a sphere of radius 1
values = x * x + y * y + z * z - np.sqrt(3)
mlab.contour3d(x, y, z, values, contours=20, colormap="jet", opacity=0.5)
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
theta = np.linspace(0, 8 * np.pi, 120)
w = np.linspace(-0.25, 0.25, 8)
w, theta = np.meshgrid(w, theta)
@detrin
detrin / test.py
Created October 21, 2019 08:17
Matplotlib test
import numpy as np
import matplotlib.pyplot as plt
import random
from matplotlib import rc
rc('font',**{'family':'serif','serif':['Helvetica']})
rc('text', usetex=True)
start, stop, step = 1, 10, 0.4
data_x = [x for x in np.arange(start, stop, step)]
@detrin
detrin / python_parallel_computing.py
Last active September 27, 2019 12:24
Python2.7 parallel computing
# -*- coding: utf-8 -*-
import random
import time
from concurrent.futures import ProcessPoolExecutor, as_completed
from multiprocessing import Pool
import numpy
from tqdm import tqdm