Skip to content

Instantly share code, notes, and snippets.

View alecGraves's full-sized avatar
🌵

Alec Graves alecGraves

🌵
View GitHub Profile
@alecGraves
alecGraves / keras_setup_instructions.md
Last active April 9, 2024 06:09
How to Install Python, Keras and Tensorflow (with GPU) on Windows or Ubuntu

What?

Python, Keras, and Tensorflow have made neural networks easy and accessable to everyone. I personally have had a lot of trouble finding a nice and easy guide detailing how to set up all three on a system. This guide contains simple, step-by-step instructions on how to install these three things.

1. Anaconda

Anaconda is a python package manager that does a lot of stuff for you. It contains many packages including pip, numpy, scipy, etc.

Step one is to install it. Do that by going here, downloading the package for your OS, and installing it.

@alecGraves
alecGraves / install_tensorflow_xu4.sh
Last active May 31, 2017 01:25
Install tensorflow from sources on arm
echo -n | openssl s_client -connect services.gradle.org:443 | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/cert.crt && \
sudo keytool -import -trustcacerts -keystore /usr/lib/jvm/default-java/jre/lib/security/cacerts \
-keyalg rsa -storepass changeit -noprompt -alias mycert -file /tmp/cert.crt && \
rm /tmp/cert.crt
@alecGraves
alecGraves / fscore.py
Created June 9, 2017 23:14
Fscore2 Metric for Keras
import keras.backend as K
def FScore2(y_true, y_pred):
'''
The F score, beta=2
'''
B2 = K.variable(4)
OnePlusB2 = K.variable(5)
pred = K.round(y_pred)
tp = K.sum(K.cast(K.less(K.abs(pred - K.clip(y_true, .5, 1.)), 0.01), 'float32'), -1)
@alecGraves
alecGraves / Student.h
Created August 24, 2017 04:29
Tiny Student Struct for MTRE 2610
struct Student {
int n, c[9], g[9];
void SetGrades(int *C, char *G, int N){
for (int i(0); i < N; ++i){
AddGrade(C[i], G[i]);
}
}
void AddGrade(int C, char G){
c[n] = C;
g[n++] = G;
@alecGraves
alecGraves / Rational.h
Last active August 24, 2017 15:27
Tiny Rational Class MTRE 2610
#include <cstdio>
class Rational{
int n, d; //numerator, denominator
int gcf(int x, int y, int z){ return y&&(z=x%y) ? gcf(y,z,0) : y;}
void r(){int f=gcf(n, d, 0); n/=f; d/=f;} //reduce
public:
Rational operator+(Rational R){return Rational(n*R.d+d*R.n, d*R.d);}
Rational operator-(Rational R){return Rational(n*R.d-d*R.n, d*R.d);}
Rational operator*(Rational R){return Rational(n*R.n, d*R.d);}
Rational operator/(Rational R){return Rational(n*R.d, d*R.n);}
@alecGraves
alecGraves / ti84pce.inc
Created September 11, 2017 04:02
ti-84 inc
;TI-84 Plus CE Include File
;Various Parts Contributed by
;- BrandonW
;- calc84
;- MateoConLechuga
;- Runer112
;- tr1p1ea
;- Kerm Martian
;- Texas Instruments (ti83plus.inc)
@alecGraves
alecGraves / resnet.m
Created November 1, 2017 15:51
matlab function for building resnet with nn toolbox
function net = resnet(input_shape)
%RESNET Creates a resnet model with imput_size
n = imageInputLayer(input_shape,'Name','input');
n = layerGraph(n);
n = bottleneck(256, ['bottleneck_' char(string(1))], n)
end
function graph = bottleneck(depth, name, graph)
head = graph.Layers(end).Name;
const int MPIN = 2; //motor pwm out pin
const int DPIN = A0; // voltage distance sensor pin
float steady_state_error;
float voltage;
float target;
float accumulate;
void setup()
{
import tensorflow as tf
from tensorflow.contrib.layers.python.layers import initializers
slim = tf.contrib.slim
'''
============================================================================
ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation
============================================================================
Based on the paper: https://arxiv.org/pdf/1606.02147.pdf
'''
import tensorflow as tf
def prelu(x, scope, decoder=False):
'''
Performs the parametric relu operation. This implementation is based on:
https://stackoverflow.com/questions/39975676/how-to-implement-prelu-activation-in-tensorflow
For the decoder portion, prelu becomes just a normal prelu
INPUTS:
- x(Tensor): a 4D Tensor that undergoes prelu
- scope(str): the string to name your prelu operation's alpha variable.