A neural network implementation in Julia
- Construct a neural network with any number of layers
- Only binary classification (for now)
- Support for training on GPU
- Julia 1.3
- TimerOutputs
- IJulia (for jupyter notebooks given in the
Examples
directory)
For GPU support, the following are required (make sure that their tests are passing):
- CuArrays (tested with v1.7.3)
- CUDAnative (tested with v2.10.2)
- CUDAdrv (optional, tested with v6.0.0)
Check out the examples for complete end-to-end training and testing examples.
-
As of now, this has not been made into a Julia package. So you will have to include the
NeuralNetwork.jl
file to use it (also, there will be some JIT overhead during the first use). Download the files in this repo and import the functions by using (make sure to use the complete relative or absolute instead of just"NeuralNetwork.jl"
):include("NeuralNetwork.jl")
-
Load your training and testing data in the form of
Float32
arrays (the outputs Y can beInt
also). -
Use the
neural_network_dense
function to train the Neural Network. See the help section for more info -?neural_network_dense
should provide the docs. Here is an example usage:parameters, activations = neural_network_dense(train_X, train_Y, [12288, 10, 1], 1000, 0.001)
[12288, 10, 1]
is the number of neurons in each layer,1000
is the number of steps to train for and0.001
is the learning rate. -
Get predictions and accuracy using the
predict
function. Again, check out the help page for more details -?predict
. Example usage:predicts, accuracy = predict(test_X, test_Y, parameters, activations)
-
(Optional) To see the time taken for each step in the Neural Network, use
print_timer(to)
-
include("NeuralNetworkGPU.jl")
-
Import the necessary packages -
using CuArrays, CUDAnative, CUDAdrv
-
Convert the training data to
CuArray
s:train_X = CuArray(train_X) train_Y = CuArray(train_Y)
-
Use the same
neural_network_dense
andpredict
functions -
That's it! (All the optmization for GPU is internal, take a look at NeuralNetworkGPU.jl)
- Multi-class classification
- Custom GPU kernels for activation functions on GPU