Skip to content

Instantly share code, notes, and snippets.

@mjdietzx
mjdietzx / reduce_lr_keras_issue.py
Last active April 8, 2018 02:27
Standalone script based of example in keras for issue
'''Trains a simple convnet on the MNIST dataset.
Gets to 99.25% test accuracy after 12 epochs
(there is still a lot of margin for parameter tuning).
16 seconds per epoch on a GRID K520 GPU.
'''
from __future__ import print_function
import numpy as np
np.random.seed(1337) # for reproducibility
import collections
import json
def duplicates():
#
# organize raw Rekognition `boto3.client('rekognition').get_face_search()` response for debugging this issue
#
with open('duplicated_index_bug.json', 'r') as f: # https://s3.us-east-2.amazonaws.com/brayniac-waya-ai/duplicated_index_bug.json
@mjdietzx
mjdietzx / rekognition_video_face_search_uncertainty.py
Last active April 11, 2018 02:27
Utilize uncertainty for improved person-tracking/face-matching performance in Rekognition video face search
import collections
def sort_raw_rekognition_results(results):
indices = collections.defaultdict(list) # unique people detected in video to a `list` of their `PersonMatch` objects
timestamps = collections.defaultdict(list) # `lists` maintain order so we can keep track of people and their indices
timestamps_indices = collections.defaultdict(list)
for p in self.results['Persons']:
@mjdietzx
mjdietzx / uport.js
Last active May 1, 2018 09:06
uPort in browser
<script src="https://unpkg.com/uport-connect/dist/uport-connect.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
function uport() {
try {
const u = new window.uportconnect.Connect('blockimmo', {
clientId: '2ohEPzgzsh7gm68BUcHQMkfaQs8BA4ysatY',
network: 'rinkeby',
@mjdietzx
mjdietzx / main.py
Last active July 13, 2018 04:46
AWS Lambda pytorch deep learning lambda function (ResNet-18 pre-trained on ImageNet)
import io
import boto3
import PIL.Image
import torch
from torch.utils import model_zoo
import torchvision
s3_client = boto3.client('s3')
@mjdietzx
mjdietzx / dynamic_ec2.py
Created September 16, 2018 09:11
spin up an ec2 instance and tear it down upon completion from AWS lambda
ec2_client = boto3.client('ec2')
user_data = """#!/bin/bash
sudo apt-get update
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python3 get-pip.py
sudo pip3 install boto3
sudo apt-get install -y libgtk2.0-dev
sudo pip3 install opencv-python
echo "{}" >> {}
@mjdietzx
mjdietzx / ResNeXt_gan.py
Last active February 14, 2020 18:10
Keras/tensorflow implementation of GAN architecture where generator and discriminator networks are ResNeXt.
from keras import layers
from keras import models
import tensorflow as tf
#
# generator input params
#
rand_dim = (1, 1, 2048) # dimension of the generator's input tensor (gaussian noise)
@mjdietzx
mjdietzx / pytorch-lambda-deploy.sh
Last active April 9, 2020 13:49
AWS Lambda pytorch deep learning deployment package (building pytorch and numpy from source on EC2 Amazon Linux AMI)
#
# written for Amazon Linux AMI
# creates an AWS Lambda deployment package for pytorch deep learning models (Python 3.6.1)
# assumes lambda function defined in ~/main.py
# deployment package created at ~/waya-ai-lambda.zip
#
#
# install python 3.6.1
#
@mjdietzx
mjdietzx / improved_wGAN_loss.py
Last active January 7, 2021 05:02
tensorflow implementation of Wasserstein distance with gradient penalty
"""
wGAN implemented on top of tensorflow as described in: [Wasserstein GAN](https://arxiv.org/pdf/1701.07875.pdf)
with improvements as described in: [Improved Training of Wasserstein GANs](https://arxiv.org/pdf/1704.00028.pdf).
"""
import tensorflow as tf
#
@mjdietzx
mjdietzx / gh_release_bamboo.sh
Last active March 29, 2021 15:19
Create and add pre-built artifacts to a GitHub release from CI server using the GitHub releases API.
#!/bin/bash
# creates a GitHub release (draft) and adds pre-built artifacts to the release
# after running this script user should manually check the release in GitHub, optionally edit it, and publish it
# args: :version_number (the version number of this release), :body (text describing the contents of the tag)
# example usage: ./gh_release_bamboo.sh "1.0.0" "Release notes: ..."
# => name: nRF5-ble-driver_<platform_name>_1.0.0_compiled-binaries.zip example: nRF5-ble-driver_win-64_2.0.1_compiled-binaries.zip
# to ensure that bash is used: https://answers.atlassian.com/questions/28625/making-a-bamboo-script-execute-using-binbash