Skip to content

Instantly share code, notes, and snippets.

View naxty's full-sized avatar

naxty

  • oxolo
  • Karlsruhe, Germany
View GitHub Profile
@naxty
naxty / apply_sobel.py
Created February 14, 2017 05:16
Opencv2 method to apply sobel to an image (Edge Detection)
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pickle
# Read in an image and grayscale it
image = mpimg.imread('signs_vehicles_xygrad.png')
@naxty
naxty / apply_magnitude.py
Created February 14, 2017 05:28
Edge detection with sobelx and sobely.
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pickle
# Read in an image
image = mpimg.imread('signs_vehicles_xygrad.png')
@naxty
naxty / color.py
Created February 14, 2017 10:06
Opencv different color input
import cv2
import matplotlib
matplotlib.image.imread() #RGB image,
cv2.imread() # BGR image.
hls = cv2.cvtColor(im, cv2.COLOR_RGB2HLS) #HLS
@naxty
naxty / multiple_plots.py
Created February 14, 2017 12:23
Multiple plots inside one graph
import matplotlib.pyplot as plt
f, (ax1, ax2) = plt.subplots(ncols=1, nrows=2, figsize=(24, 9))
f.tight_layout()
ax1.imshow(gradx, cmap='gray')
ax1.set_title('Gradx', fontsize=50)
ax2.imshow(grady, cmap='gray')
ax2.set_title('Grady', fontsize=50)
plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)
f.savefig('grads.png') # save the figure to file
plt.close(f)
@naxty
naxty / sk_hog.py
Created March 7, 2017 15:25
Histogram of Oriented Gradients
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
import cv2
import glob
from skimage.feature import hog
# Read in our vehicles and non-vehicles
images = glob.glob('*.jpeg')
cars = []
@naxty
naxty / args.py
Created October 9, 2017 13:00
Python argument parser
import argparse
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-p", "--path", required=True, help="Path of the files")
args = vars(arg_parser.parse_args())
@naxty
naxty / linear_regession_scikit.py
Created August 6, 2019 11:03
Train a simple linear regression.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(boston_housing.data, boston_housing.target, test_size=0.2, random_state=0)
model = LinearRegression()
model.fit(X_train, y_train)
@naxty
naxty / pydantic_example_housing_features.py
Created August 6, 2019 11:08
Example of using pydantic for features.
from pydantic import BaseModel
class HousingFeatures(BaseModel):
CRIM: float
ZN: float
INDUS: float
CHAS: float
NOX: float
RM: float
AGE: float
@naxty
naxty / fast_api_post_request.py
Created August 6, 2019 11:09
Example of fast api post request
from fastapi import APIRouter, Depends
api = APIRouter()
@api.post("/predict", response_model=PredictionResult)
def post_predict(
housing_features: HousingFeatures,
authenticated: bool = Depends(security.validate_request),
):
assert authenticated == True
return predict(housing_features)
@naxty
naxty / onnx_runtime_prediction.py
Last active August 6, 2019 11:58
Running a prediction with onnx runtime.
import onnxruntime as rt
import numpy
sess = rt.InferenceSession("boston_housting.onnx")
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
prediction = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]