1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge pull request #20442 from JulieBar:gru_layer

* Add initialization and inference for GRU layer

* fix issues found on review
This commit is contained in:
Julia Bareeva
2021-08-07 10:07:37 +03:00
committed by GitHub
parent ba539eb9aa
commit e1cafa3834
6 changed files with 326 additions and 0 deletions
+29
View File
@@ -596,6 +596,35 @@ TEST(Layer_LSTM_Test_Accuracy_with_, HiddenParams)
normAssert(h_t_reference, outputs[0]);
}
TEST(Layer_GRU_Test_Accuracy_with_, Pytorch)
{
Mat Wx = blobFromNPY(_tf("gru.W.npy"));
Mat Wh = blobFromNPY(_tf("gru.R.npy"));
Mat b = blobFromNPY(_tf("gru.B.npy"));
Mat h0 = blobFromNPY(_tf("gru.h0.npy"));
Wx = Wx.reshape(1, Wx.size[0] * Wx.size[1]);
Wh = Wh.reshape(1, Wh.size[0] * Wh.size[1]);
h0 = h0.reshape(1, h0.size[0] * h0.size[1]);
b = b.reshape(1, b.size[0]);
LayerParams gruParams;
gruParams.blobs.resize(4);
gruParams.blobs[0] = Wh;
gruParams.blobs[1] = Wx;
gruParams.blobs[2] = b;
gruParams.blobs[3] = h0;
gruParams.set("bidirectional", false);
Ptr<GRULayer> layer = GRULayer::create(gruParams);
Mat inp = blobFromNPY(_tf("gru.input.npy"));
std::vector<Mat> inputs(1, inp), outputs;
runLayer(layer, inputs, outputs);
Mat h_t_reference = blobFromNPY(_tf("gru.output.npy"));
normAssert(h_t_reference, outputs[0]);
}
TEST(Layer_RNN_Test_Accuracy_with_, CaffeRecurrent)
{
Ptr<RNNLayer> layer = RNNLayer::create(LayerParams());