Daniel Haehn PRO
Hi, I am a biomedical imaging and visualization researcher who investigates how computational methods can accelerate biological and medical research.
Functions, Classes
Arrays, Vectors
Templates
GIBBS Cluster
Cython
Run our C++ code in Python using Cython
and compare timing against NumPy
Analyze a bunch of numbers and calculate min, max, mean, stddev.
void test_get_min_float() {
std::vector<float> somevalues;
somevalues.push_back(1.1);
somevalues.push_back(2.31);
somevalues.push_back(3.4);
somevalues.push_back(-241.44);
assert(get_min_float(somevalues)==-241.44);
std::cout << "Test OK!" << std::endl;
}
Never got executed!
void test_get_min_float() {
std::vector<float> somevalues;
somevalues.push_back(1.1);
somevalues.push_back(2.31);
somevalues.push_back(3.4);
somevalues.push_back(-241.44);
float diff = std::abs( -241.44 ) - std::abs( get_min_float(somevalues) );
assert(diff < 0.0005);
std::cout << "Test OK!" << std::endl;
}
Check if we have a very small difference between two floats..
We can not just compare floats..
float onevalue = 0.33333333333333;
float secondvalue = 1/3;
if (onevalue == secondvalue) {
// cancel life-support
// ...
}
Developer is in charge of precision..
All languages do this more or less problematically!
Software Development Models
Predictive
Adaptive
As rigid as possible as flexible as needed
Cython!
Calling C++ from Python
Why?
Python code might be slow
More soon...
but not today...
Lex Fridman
Artificial General Intelligence
MNIST
Lex Fridman
Supervised Learning
9
Convolutional Neural Network
cat
Convolutional Neural Network
Keras
Easier!
GIBBS Cluster
conda install keras-gpu
conda install pytorch
conda install pillow
1. Load Data
2. Setup Network
3. Train Network
4. Predict!
4 Steps
Data
Training
Testing
2
Label
?
Label
But we know the answer!
X_train
y_train
X_test
y_test
Setup Network
NUMBER_OF_CLASSES = 10
model = keras.models.Sequential()
model.add(keras.layers.Conv2D(32, kernel_size=(3, 3),
activation='relu',
input_shape=first_image.shape))
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
model.add(keras.layers.Dropout(0.25))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(128, activation='relu'))
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.Dense(NUMBER_OF_CLASSES, activation='softmax'))
NUMBER_OF_CLASSES = 10
MNIST
NUMBER_OF_CLASSES = 2
Cats vs. Dogs
Setup Network
NUMBER_OF_CLASSES = 10
model = keras.models.Sequential()
model.add(keras.layers.Conv2D(32, kernel_size=(3, 3),
activation='relu',
input_shape=first_image.shape))
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))
model.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
model.add(keras.layers.Dropout(0.25))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(128, activation='relu'))
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.Dense(NUMBER_OF_CLASSES, activation='softmax'))
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
Train Network
9
Training Data
Then we check how well the network predicts the testing data!
?
Loss
should go down!
Repeated.. (1 run is called an epoch)
Predict!
Testing Data
0 0 0
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
Measure how well the CNN does...
Let's code!!
By Daniel Haehn
Hi, I am a biomedical imaging and visualization researcher who investigates how computational methods can accelerate biological and medical research.