conv3d working

This commit is contained in:
Francesco Gatti
2017-06-29 09:06:29 +00:00
parent ffdb70abee
commit a04c3eaf88
3 changed files with 17 additions and 14 deletions
+4 -2
View File
@@ -14,12 +14,14 @@ Activation::Activation(Network *net, dataDim_t input_dim, tkdnnActivationMode_t
checkCUDNN( cudnnSetTensor4dDescriptor(srcTensorDesc, checkCUDNN( cudnnSetTensor4dDescriptor(srcTensorDesc,
net->tensorFormat, net->tensorFormat,
net->dataType, net->dataType,
input_dim.n, input_dim.c, input_dim.n*input_dim.l,
input_dim.c,
input_dim.h, input_dim.w) ); input_dim.h, input_dim.w) );
checkCUDNN( cudnnSetTensor4dDescriptor(dstTensorDesc, checkCUDNN( cudnnSetTensor4dDescriptor(dstTensorDesc,
net->tensorFormat, net->tensorFormat,
net->dataType, net->dataType,
input_dim.n, input_dim.c, input_dim.n*input_dim.l,
input_dim.c,
input_dim.h, input_dim.w) ); input_dim.h, input_dim.w) );
} }
+8 -7
View File
@@ -13,12 +13,13 @@ from weights_exporter import *
def dense_model(): def dense_model():
model = Sequential() model = Sequential()
model.add(Reshape((10, 10, 1), input_shape=(10, 10))) model.add(Reshape((10, 10, 4, 1), input_shape=(10, 10, 4)))
model.add(Convolution2D(2, (4, 4), subsample=(2, 2), model.add(Convolution3D(2, (4, 4, 2), subsample=(2, 2, 1), activation="relu",
bias_initializer='random_uniform'))
model.add(Convolution3D(4, (2, 2, 2), subsample=(1, 1, 1),
bias_initializer='random_uniform')) bias_initializer='random_uniform'))
model.add(ELU()) model.add(ELU())
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) sgd = keras.optimizers.Adam(lr=1e-4, decay=1e-8)
model.compile(optimizer=sgd, loss="mse") model.compile(optimizer=sgd, loss="mse")
return model return model
@@ -29,10 +30,10 @@ if __name__ == '__main__':
model = dense_model() model = dense_model()
wg = model.get_weights() wg = model.get_weights()
export_conv2d("conv0", wg[0], wg[1]) export_conv3d("conv0", wg[0], wg[1])
export_conv2d("conv1", wg[2], wg[3]) export_conv3d("conv1", wg[2], wg[3])
grid = np.random.rand(10,10) grid = np.random.rand(10,10,4)
X = grid[None,:,:] X = grid[None,:,:]
i = np.array(grid.flatten(), dtype=np.float32) i = np.array(grid.flatten(), dtype=np.float32)
print i print i
+5 -5
View File
@@ -13,11 +13,11 @@ int main() {
// Network layout // Network layout
tkDNN::Network net; tkDNN::Network net;
tkDNN::dataDim_t dim(1, 1, 10, 10); tkDNN::dataDim_t dim(1, 1, 10, 10, 4);
tkDNN::Conv2d c0 (&net, dim, 2, 4, 4, 2, 2, c0_bin, c0_bias_bin); tkDNN::Conv3d c0 (&net, dim, 2, 4, 4, 2, 2, 2, 1, c0_bin, c0_bias_bin);
tkDNN::Activation a0 (&net, c0.output_dim, tkDNN::ACTIVATION_ELU); tkDNN::Activation a0 (&net, c0.output_dim, tkDNN::ACTIVATION_RELU);
tkDNN::Conv2d c1 (&net, a0.output_dim, 4, 2, 2, 1, 1, c1_bin, c1_bias_bin); tkDNN::Conv3d c1 (&net, a0.output_dim, 4, 2, 2, 2, 1, 1, 1, c1_bin, c1_bias_bin);
tkDNN::Activation a1 (&net, c1.output_dim, tkDNN::ACTIVATION_RELU); tkDNN::Activation a1 (&net, c1.output_dim, tkDNN::ACTIVATION_ELU);
// Load input // Load input
value_type *data; value_type *data;