-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
echo "build test Model" | ||
cd test | ||
python test_model.py | ||
cd .. | ||
cd mnist | ||
python mnist_model.py | ||
cd .. | ||
echo "export weights" | ||
python weights_exporter.py test/net.h5 --output test/layers | ||
python caffe_weights_exporter.py mnist/lenet.prototxt mnist/lenet.caffemodel --output mnist/layers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
# mail: admin@9crk.com | ||
# author: 9crk.from China.ShenZhen | ||
# time: 2017-03-22 | ||
|
||
import caffe | ||
import numpy as np | ||
import cv2 | ||
import sys | ||
import Image | ||
import matplotlib.pyplot as plt | ||
|
||
model = 'lenet.prototxt'; | ||
weights = 'lenet.caffemodel'; | ||
net = caffe.Net(model,weights,caffe.TEST); | ||
caffe.set_mode_gpu() | ||
img = np.array(np.random.rand(28,28), dtype=np.float32) | ||
#revert the image,and normalize it to 0-1 range | ||
|
||
print "INPUT: ", img | ||
img.tofile("input.bin", format="f") | ||
print "SHAPE: ", np.shape(img) | ||
out = net.forward_all(data=np.asarray([img])) | ||
|
||
out = out[out.keys()[0]] | ||
print out | ||
print np.shape(out) | ||
out.tofile("output.bin", format="f") | ||
#print out['prob'][0] | ||
#print out['prob'][0].argmax() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include<iostream> | ||
#include "tkdnn.h" | ||
|
||
const char *input_bin = "../tests/mnist/input.bin"; | ||
const char *c0_bin = "../tests/mnist/layers/Convolution0.bin"; | ||
const char *c0_bias_bin = "../tests/mnist/layers/Convolution0.bias.bin"; | ||
const char *c1_bin = "../tests/mnist/layers/Convolution1.bin"; | ||
const char *c1_bias_bin = "../tests/mnist/layers/Convolution1.bias.bin"; | ||
const char *d2_bin = "../tests/mnist/layers/InnerProduct2.bin"; | ||
const char *d2_bias_bin = "../tests/mnist/layers/InnerProduct2.bias.bin"; | ||
const char *d3_bin = "../tests/mnist/layers/InnerProduct3.bin"; | ||
const char *d3_bias_bin = "../tests/mnist/layers/InnerProduct3.bias.bin"; | ||
const char *output_bin = "../tests/mnist/output.bin"; | ||
|
||
int main() { | ||
|
||
// Network layout | ||
tkDNN::Network net; | ||
tkDNN::dataDim_t dim(1, 1, 28, 28, 1); | ||
tkDNN::Layer *l; | ||
l = new tkDNN::Conv2d (&net, dim, 20, 5, 5, 1, 1, c0_bin, c0_bias_bin); | ||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX); | ||
l = new tkDNN::Conv2d (&net, l->output_dim, 50, 5, 5, 1, 1, c1_bin, c1_bias_bin); | ||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX); | ||
l = new tkDNN::Dense (&net, l->output_dim, 500, d2_bin, d2_bias_bin); | ||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU); | ||
l = new tkDNN::Dense (&net, l->output_dim, 10, d3_bin, d3_bias_bin); | ||
l = new tkDNN::Softmax (&net, l->output_dim); | ||
|
||
// Load input | ||
value_type *data; | ||
value_type *input_h; | ||
readBinaryFile(input_bin, dim.tot(), &input_h, &data); | ||
|
||
printDeviceVector(dim.tot(), data); | ||
dim.print(); //print initial dimension | ||
|
||
TIMER_START | ||
|
||
// Inference | ||
data = net.infer(dim, data); | ||
|
||
TIMER_STOP | ||
dim.print(); | ||
|
||
// Print result | ||
std::cout<<"\n======= RESULT =======\n"; | ||
printDeviceVector(dim.tot(), data); | ||
|
||
// Print real test | ||
std::cout<<"\n==== CHECK RESULT ====\n"; | ||
value_type *out; | ||
value_type *out_h; | ||
readBinaryFile(output_bin, dim.tot(), &out_h, &out); | ||
printDeviceVector(dim.tot(), out); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include<iostream> | ||
#include "tkdnn.h" | ||
|
||
const char *input_bin = "../tests/test/input.bin"; | ||
const char *c0_bin = "../tests/test/layers/conv0.bin"; | ||
const char *c0_bias_bin = "../tests/test/layers/conv0.bias.bin"; | ||
const char *c1_bin = "../tests/test/layers/conv1.bin"; | ||
const char *c1_bias_bin = "../tests/test/layers/conv1.bias.bin"; | ||
const char *d2_bin = "../tests/test/layers/dense2.bin"; | ||
const char *d2_bias_bin = "../tests/test/layers/dense2.bias.bin"; | ||
const char *output_bin = "../tests/test/output.bin"; | ||
|
||
int main() { | ||
|
||
// Network layout | ||
tkDNN::Network net; | ||
tkDNN::dataDim_t dim(1, 1, 10, 10, 1); | ||
tkDNN::Layer *l; | ||
l = new tkDNN::Conv2d (&net, dim, 2, 4, 4, 2, 2, c0_bin, c0_bias_bin); | ||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU); | ||
l = new tkDNN::Conv2d (&net, l->output_dim, 4, 2, 2, 1, 1, c1_bin, c1_bias_bin); | ||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU); | ||
l = new tkDNN::Flatten (&net, l->output_dim); | ||
l = new tkDNN::Dense (&net, l->output_dim, 4, d2_bin, d2_bias_bin); | ||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU); | ||
|
||
// Load input | ||
value_type *data; | ||
value_type *input_h; | ||
readBinaryFile(input_bin, dim.tot(), &input_h, &data); | ||
|
||
printDeviceVector(dim.tot(), data); | ||
dim.print(); //print initial dimension | ||
|
||
TIMER_START | ||
|
||
// Inference | ||
data = net.infer(dim, data); dim.print(); | ||
|
||
|
||
TIMER_STOP | ||
|
||
// Print result | ||
std::cout<<"\n======= RESULT =======\n"; | ||
printDeviceVector(dim.tot(), data); | ||
|
||
// Print real test | ||
std::cout<<"\n==== CHECK RESULT ====\n"; | ||
value_type *out; | ||
value_type *out_h; | ||
readBinaryFile(output_bin, dim.tot(), &out_h, &out); | ||
printDeviceVector(dim.tot(), out); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters