Skip to content

Instantly share code, notes, and snippets.

View tawnkramer's full-sized avatar

Tawn Kramer tawnkramer

  • San Diego, CA
View GitHub Profile
'''
Author: Tawn Kramer
Date: June 22, 2017
Brief:
This will crop the set of images in a LISA sign data set, resize to a constant dimension,
and save out a pickle file. You can download the data here:
http://cvrr.ucsd.edu/LISA/lisa-traffic-sign-dataset.html
The output of this data set is a pickle file. Consideering the output is 15Mb while the input is 7GB,
'''
from the CarND-Alexnet-Feature-Extraction project
https://github.com/udacity/CarND-Alexnet-Feature-Extraction
This is modified to set the number of classes dynamically from the loaded data.
'''
import pickle
import time
import tensorflow as tf
from sklearn.model_selection import train_test_split

on your pi

wget https://raw.githubusercontent.com/tawnkramer/donkey/dev-mainline/donkeycar/parts/controllers/joystick.py
cp joystick.py ~/d2/

now edit ~/d2/manage.py

near the top, add a

@tawnkramer
tawnkramer / img_fifo.py
Last active September 12, 2017 16:14
A FIFO of N previous images into a single N channel image, after converting each to grayscale.
class ImgFIFO:
"""
Stack N previous images into a single N channel image, after converting each to grayscale.
The most recent image is the last channel, and pushes previous images towards the front.
"""
def __init__(self, num_channels=3):
self.img_arr = None
self.num_channels = num_channels
def run(self, img_arr):
import os
import sys
import glob
import json
import shutil
def go(src_path, dest_path):
print('adding tub', src_path, 'to', dest_path)
src_files = glob.glob(os.path.join(src_path, '*.jpg'))
dest_files = glob.glob(os.path.join(dest_path, '*.jpg'))
@tawnkramer
tawnkramer / keras_imu.py
Created November 6, 2017 20:21
donkey keras imu integration
import os
import numpy as np
import keras
import donkeycar as dk
from donkeycar.parts.keras import KerasPilot
class KerasIMU(KerasPilot):
def __init__(self, model=None, num_outputs=None, *args, **kwargs):
super(KerasIMU, self).__init__(*args, **kwargs)
self.model = default_imu(2)
def imu_rnn_lstm(seq_length, num_outputs, imu_vec_size=6):
from keras.layers import Input, Dense
from keras.models import Model
from keras.layers import Convolution2D, MaxPooling2D, Reshape, BatchNormalization
from keras.layers import Activation, Dropout, Flatten, Cropping2D, Lambda
from keras.layers.merge import concatenate
from keras.layers import LSTM
img_in = Input(batch_shape=(seq_length, 120,160,3), name='img_in')
imu_in = Input(batch_shape=(seq_length, imu_vec_size), name="imu_in")
@tawnkramer
tawnkramer / train.py
Last active November 28, 2017 19:50
Script to train a keras model. Uses the data written by the donkey v2.2 tub writer, but faster training with proper sampling of distribution over tubs. You can drop this in your ~/d2 dir. Basic usage should feel familiar: python train.py --model models/mypilot
#!/usr/bin/env python3
"""
Scripts to train a keras model using tensorflow.
Uses the data written by the donkey v2.2 tub writer,
but faster training with proper sampling of distribution over tubs.
Has settings for continuous training that will look for new files as it trains.
Modify send_model_to_pi is you wish continuous training to update your pi as it builds.
You can drop this in your ~/d2 dir.
Basic usage should feel familiar: python train.py --model models/mypilot
You might need to do a: pip install scikit-learn
"""A demo to classify opencv camera stream with google coral tpu device."""
import argparse
import io
import time
import numpy as np
import cv2
import edgetpu.classification.engine
'''
# Install and setup:
# sudo update && sudo apt install pigpio python3-pigpio
# sudo systemctl start pigpiod
'''
import os
import donkeycar as dk
from donkeycar.parts.controller import PS3JoystickController
from donkeycar.parts.actuator import PWMSteering, PWMThrottle