Skip to content

Instantly share code, notes, and snippets.

View ankkhedia's full-sized avatar

Ankit Khedia ankkhedia

  • Amazon
  • Palo Alto
View GitHub Profile
Column name Description
No row number
year year of data in this row
month month of data in this row
day day of data in this row
hour hour of data in this row
pm2.5 PM2.5 concentration
DEWP Dew Point
TEMP Temperature
PRES Pressure
## Loading required packages
library("readr")
library("dplyr")
library("mxnet")
library("abind")
mx.set.seed(1234)
## Preprocessing steps
## generating synthetic data
def get_feature(model,aligned):
input_blob = np.expand_dims(aligned, axis=0)
data = mx.nd.array(input_blob)
db = mx.io.DataBatch(data=(data,))
model.forward(db, is_train=False)
# Normalise embedding obtained from forward pass to unit vector
embedding = model.get_outputs()[0].squeeze()
embedding /= embedding.norm()
return embedding
## Download the images
img1 = mx.test_utils.download(url='https://s3.amazonaws.com/onnx-model-zoo/arcface/player1.jpg')
img2 = mx.test_utils.download(url='https://s3.amazonaws.com/onnx-model-zoo/arcface/player2.jpg')
## Start preprocessing of images
# runs preprocessing steps on the images
# prepare the face detector model
det_threshold = [0.6, 0.7, 0.8]
mtcnn_path = os.path.join(os.path.dirname('__file__'), 'mtcnn-model')
detector = MtcnnDetector(model_folder=mtcnn_path, ctx=ctx, num_worker=1, accurate_landmark = True, threshold=det_threshold)
# pass the images through face detector model to get bounding box for faces and align the faces
@ankkhedia
ankkhedia / loading_model.py
Last active February 20, 2019 02:05
Gist for medium blogpost
def get_model(ctx, model):
image_size = (112,112)
# Import ONNX model
sym, arg_params, aux_params = import_model(model)
# Define and binds parameters to the network
model = mx.mod.Module(symbol=sym, context=ctx, label_names = None)
#Bind method requires name of the input('data' in this case) and shape of the input for the model
model.bind(data_shapes=[('data', (1, 3, image_size[0], image_size[1]))])
model.set_params(arg_params, aux_params)
return model
@ankkhedia
ankkhedia / download.py
Last active July 9, 2018 22:28
Gist for medium blogpost
import mxnet as mx
##Download helper scripts
mx.test_utils.download(url='https://raw.githubusercontent.com/onnx/models/master/models/face_recognition/ArcFace/mtcnn_detector.py')
mx.test_utils.download(url='https://raw.githubusercontent.com/onnx/models/master/models/face_recognition/ArcFace/helper.py')
## Download ArcFace model
mx.test_utils.download(url='https://s3.amazonaws.com/onnx-model-zoo/arcface/resnet100/resnet100.onnx')
## Download pretrained MTCNN face detector model
for i in range(4):