Skip to content

Instantly share code, notes, and snippets.

@mjdietzx
mjdietzx / bird_buddy_prompt.txt
Created November 30, 2024 19:37
Iterating a prompt to be used with grok to analyze bird buddy images
As an expert ornithologist AI, analyze the provided close-up image of a bird (or birds) from the perspective of the Bird Buddy Smart Bird Feeder. Return the following information in JSON format. Always return a list of entries, with one entry per bird detected:
species_common_name: Common name of the bird species.
species_scientific_name: Scientific name of the bird (genus and species).
age: Estimated age category. One of: fledgling, juvenile, adult, unknown.
gender: Determined gender if possible. One of: male, female, unknown.
health_status: Indicate its health states if possible. One or more of: "Salmonellosis", "Avian Pox", "Conjunctivitis", "Baldness", "Scaly Leg Mite Infestation", "Injured", "Feather Mites and Lice", "Parasites", "Beak Deformities", "Bumblefoot", "Molting", "Healthy", "Unknown".
behavior: Observed behavior (e.g., feeding, perching, preening).
info: One or two descriptive sentences about this particular bird, highlighting its unique features or any interesting insights.
food: Indicate th
@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 / 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 / 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']:
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 / 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 / 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 / download_image.py
Last active February 16, 2025 04:33
Download image from url and save as file
import io
from PIL import Image # https://pillow.readthedocs.io/en/4.3.x/
import requests # http://docs.python-requests.org/en/master/
# example image url: https://m.media-amazon.com/images/S/aplus-media/vc/6a9569ab-cb8e-46d9-8aea-a7022e58c74a.jpg
def download_image(url, image_file_path):
r = requests.get(url, timeout=4.0)
if r.status_code != requests.codes.ok:
@mjdietzx
mjdietzx / cross_entropy_loss.py
Created August 3, 2017 20:27
Cross entropy loss pytorch implementation
import torch
from torch import autograd
from torch import nn
class CrossEntropyLoss(nn.Module):
"""
This criterion (`CrossEntropyLoss`) combines `LogSoftMax` and `NLLLoss` in one single class.
NOTE: Computes per-element losses for a mini-batch (instead of the average loss over the entire mini-batch).
@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
#