cudnn5 branch for tx2
This commit is contained in:
+8
-25
@@ -6,52 +6,35 @@ const char *c0_bin = "../tests/conv0.bin";
|
||||
const char *c0_bias_bin = "../tests/conv0.bias.bin";
|
||||
const char *c1_bin = "../tests/conv1.bin";
|
||||
const char *c1_bias_bin = "../tests/conv1.bias.bin";
|
||||
const char *c2_bin = "../tests/conv2.bin";
|
||||
const char *c2_bias_bin = "../tests/conv2.bias.bin";
|
||||
const char *d3_bin = "../tests/dense3.bin";
|
||||
const char *d3_bias_bin = "../tests/dense3.bias.bin";
|
||||
const char *d4_bin = "../tests/dense4.bin";
|
||||
const char *d4_bias_bin = "../tests/dense4.bias.bin";
|
||||
const char *d5_bin = "../tests/dense5.bin";
|
||||
const char *d5_bias_bin = "../tests/dense5.bias.bin";
|
||||
|
||||
int main() {
|
||||
|
||||
// Network layout
|
||||
tkDNN::Network net;
|
||||
tkDNN::dataDim_t dim(1, 1, 100, 100, 4);
|
||||
tkDNN::dataDim_t dim(1, 1, 10, 10, 1);
|
||||
tkDNN::Layer *l;
|
||||
l = new tkDNN::MulAdd (&net, dim, 2, -1);
|
||||
l = new tkDNN::Conv3d (&net, l->output_dim, 16, 8, 8, 2, 4, 4, 1, c0_bin, c0_bias_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_ELU);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_AVERAGE);
|
||||
l = new tkDNN::Conv3d (&net, l->output_dim, 16, 4, 4, 2, 2, 2, 1, c1_bin, c1_bias_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_ELU);
|
||||
l = new tkDNN::Conv3d (&net, l->output_dim, 24, 3, 3, 2, 1, 1, 1, c2_bin, c2_bias_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_ELU);
|
||||
l = new tkDNN::Flatten (&net, l->output_dim);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 256, d3_bin, d3_bias_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_ELU);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 32, d4_bin, d4_bias_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_RELU);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 2, d5_bin, d5_bias_bin);
|
||||
|
||||
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);
|
||||
|
||||
// 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
|
||||
printDeviceVector(dim.tot(), data);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-27
@@ -11,26 +11,12 @@ from weights_exporter import *
|
||||
|
||||
def dense_model():
|
||||
model = Sequential()
|
||||
model.add(Reshape((100, 100, 4, 1), input_shape=(100, 100, 4)))
|
||||
model.add(Lambda(lambda x: 2*x - 1.,
|
||||
batch_input_shape=(1, 100, 100, 4), # 100by100by2
|
||||
output_shape=(100, 100, 4, 1))) # 100by100by2
|
||||
model.add(Convolution3D(16, kernel_size=(8, 8, 2), subsample=(4, 4, 1), border_mode="valid",
|
||||
bias_initializer="random_uniform"))
|
||||
model.add(ELU())
|
||||
model.add(AveragePooling3D(pool_size=(2, 2, 1)))
|
||||
model.add(Convolution3D(16, kernel_size=(4, 4, 2), subsample=(2, 2, 1), border_mode="valid",
|
||||
bias_initializer="random_uniform"))
|
||||
model.add(ELU())
|
||||
model.add(Convolution3D(24, kernel_size=(3, 3, 2), subsample=(1, 1, 1), border_mode="valid",
|
||||
bias_initializer="random_uniform"))
|
||||
model.add(ELU())
|
||||
model.add(Flatten())
|
||||
model.add(Dense(256, bias_initializer="random_uniform"))
|
||||
model.add(ELU())
|
||||
model.add(Dense(32, activation="relu", bias_initializer="random_uniform"))
|
||||
model.add(Dense(2, bias_initializer="random_uniform"))
|
||||
|
||||
model.add(Reshape((10, 10, 1), input_shape=(10, 10)))
|
||||
model.add(Convolution2D(2, (4, 4), subsample=(2, 2),
|
||||
bias_initializer='random_uniform', activation="relu"))
|
||||
model.add(Convolution2D(4, (2, 2), subsample=(1, 1),
|
||||
bias_initializer='random_uniform', activation="relu"))
|
||||
sgd = keras.optimizers.Adam(lr=1e-4, decay=1e-8)
|
||||
model.compile(optimizer=sgd, loss="mse")
|
||||
return model
|
||||
@@ -41,14 +27,10 @@ if __name__ == '__main__':
|
||||
|
||||
model = dense_model()
|
||||
wg = model.get_weights()
|
||||
export_conv3d("conv0", wg[0], wg[1])
|
||||
export_conv3d("conv1", wg[2], wg[3])
|
||||
export_conv3d("conv2", wg[4], wg[5])
|
||||
export_dense ("dense3", wg[6], wg[7])
|
||||
export_dense ("dense4", wg[8], wg[9])
|
||||
export_dense ("dense5", wg[10], wg[11])
|
||||
export_conv2d("conv0", wg[0], wg[1])
|
||||
export_conv2d("conv1", wg[2], wg[3])
|
||||
|
||||
grid = np.random.rand(100, 100,4)
|
||||
grid = np.random.rand(10,10)
|
||||
X = grid[None,:,:]
|
||||
i = np.array(grid.flatten(), dtype=np.float32)
|
||||
print i
|
||||
@@ -58,4 +40,4 @@ if __name__ == '__main__':
|
||||
r = model.predict( X, batch_size=1)
|
||||
print np.shape(r)
|
||||
print "Result: ", r
|
||||
print "Result shape: ", np.shape(r)
|
||||
print "Result shape: ", np.shape(r)
|
||||
|
||||
Reference in New Issue
Block a user