early-access version 1432
This commit is contained in:
6
externals/ffmpeg/tests/dnn/.gitignore
vendored
Executable file
6
externals/ffmpeg/tests/dnn/.gitignore
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
/dnn-layer-conv2d-test
|
||||
/dnn-layer-depth2space-test
|
||||
/dnn-layer-maximum-test
|
||||
/dnn-layer-pad-test
|
||||
/dnn-layer-mathbinary-test
|
||||
/dnn-layer-mathunary-test
|
16
externals/ffmpeg/tests/dnn/Makefile
vendored
Executable file
16
externals/ffmpeg/tests/dnn/Makefile
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
DNNTESTPROGS += dnn-layer-pad
|
||||
DNNTESTPROGS += dnn-layer-conv2d
|
||||
DNNTESTPROGS += dnn-layer-depth2space
|
||||
DNNTESTPROGS += dnn-layer-mathbinary
|
||||
DNNTESTPROGS += dnn-layer-maximum
|
||||
DNNTESTPROGS += dnn-layer-mathunary
|
||||
|
||||
DNNTESTOBJS := $(DNNTESTOBJS:%=$(DNNTESTSDIR)%) $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test.o)
|
||||
DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF))
|
||||
-include $(wildcard $(DNNTESTOBJS:.o=.d))
|
||||
|
||||
$(DNNTESTPROGS): %$(EXESUF): %.o $(FF_STATIC_DEP_LIBS)
|
||||
$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avformat) $(EXTRALIBS-avutil) $(EXTRALIBS-swresample) $(EXTRALIBS)
|
||||
|
||||
testclean::
|
||||
$(RM) $(addprefix $(DNNTESTSDIR)/,$(CLEANSUFFIXES) *-test$(EXESUF))
|
240
externals/ffmpeg/tests/dnn/dnn-layer-conv2d-test.c
vendored
Executable file
240
externals/ffmpeg/tests/dnn/dnn-layer-conv2d-test.c
vendored
Executable file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Guo Yejun
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_conv2d.h"
|
||||
|
||||
#define EPSON 0.00001
|
||||
|
||||
static int test_with_same_dilate(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
|
||||
y = tf.layers.conv2d(x, 2, 3, activation=tf.nn.tanh, padding='same', dilation_rate=(2, 2), bias_initializer=tf.keras.initializers.he_normal())
|
||||
data = np.random.rand(1, 5, 6, 3);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
|
||||
weights = dict([(var.name, sess.run(var)) for var in tf.trainable_variables()])
|
||||
kernel = weights['conv2d/kernel:0']
|
||||
kernel = np.transpose(kernel, [3, 0, 1, 2])
|
||||
print("kernel:")
|
||||
print(kernel.shape)
|
||||
print(list(kernel.flatten()))
|
||||
|
||||
bias = weights['conv2d/bias:0']
|
||||
print("bias:")
|
||||
print(bias.shape)
|
||||
print(list(bias.flatten()))
|
||||
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print("input:")
|
||||
print(data.shape)
|
||||
print(list(data.flatten()))
|
||||
|
||||
print("output:")
|
||||
print(output.shape)
|
||||
print(list(output.flatten()))
|
||||
*/
|
||||
|
||||
ConvolutionalParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*5*6*3] = {
|
||||
0.7012556460308194, 0.4233847954643357, 0.19515900664313612, 0.16343083004926495, 0.5758261611052848, 0.9510767434014871, 0.11014085055947687,
|
||||
0.906327053637727, 0.8136794715542507, 0.45371764543639526, 0.5768443343523952, 0.19543668786046986, 0.15648326047898609, 0.2099500241141279,
|
||||
0.17658777090552413, 0.059335724777169196, 0.1729991838469117, 0.8150514704819208, 0.4435535466703049, 0.3752188477566878, 0.749936650421431,
|
||||
0.6823494635284907, 0.10776389679424747, 0.34247481674596836, 0.5147867256244629, 0.9063709728129032, 0.12423605800856818, 0.6064872945412728,
|
||||
0.5891681538551459, 0.9865836236466314, 0.9002163879294677, 0.003968273184274618, 0.8628374809643967, 0.1327176268279583, 0.8449799925703798,
|
||||
0.1937671869354366, 0.41524410152707425, 0.02038786604756837, 0.49792466069597496, 0.8881874553848784, 0.9683921035597336, 0.4122972568010813,
|
||||
0.843553550993252, 0.9588482762501964, 0.5190350762645546, 0.4283584264145317, 0.09781496073714646, 0.9501058833776156, 0.8665541760152776,
|
||||
0.31669272550095806, 0.07133074675453632, 0.606438007334886, 0.7007157020538224, 0.4827996264130444, 0.5167615606392761, 0.6385043039312651,
|
||||
0.23069664707810555, 0.058233497329354456, 0.06323892961591071, 0.24816458893245974, 0.8646369065257812, 0.24742185893094837, 0.09991225948167437,
|
||||
0.625700606979606, 0.7678541502111257, 0.6215834594679912, 0.5623003956582483, 0.07389123942681242, 0.7659100715711249, 0.486061471642225,
|
||||
0.9947455699829012, 0.9094911797643259, 0.7644355876253265, 0.05384315321492239, 0.13565394382783613, 0.9810628204953316, 0.007386389078887889,
|
||||
0.226182754156241, 0.2609021390764772, 0.24182802076928933, 0.13264782451941648, 0.2035816485767682, 0.005504188177612557, 0.7014619934040155,
|
||||
0.956215988391991, 0.5670398541013633, 0.9809764721750784, 0.6886338100487461, 0.5758152317218274, 0.7137823176776179
|
||||
};
|
||||
float expected_output[1*5*6*2] = {
|
||||
-0.9480655, -0.7169147, -0.9404794, -0.5567385, -0.8991124, -0.8306558, -0.94487447, -0.8932543, -0.88238764, -0.7301602,
|
||||
-0.8974813, -0.7026703, -0.8858988, -0.53203243, -0.92881465, -0.5648504, -0.8871471, -0.7000097, -0.91754407, -0.79684794,
|
||||
-0.760465, -0.117928326, -0.88302773, -0.8975289, -0.70615053, 0.19231977, -0.8318776, -0.386184, -0.80698484, -0.8556624,
|
||||
-0.7336671, -0.6168619, -0.7658234, -0.63449603, -0.73314047, -0.87502456, -0.58158904, -0.4184259, -0.52618927, -0.13613208,
|
||||
-0.5093187, -0.21027721, -0.39455596, -0.44507834, -0.22269244, -0.73400885, -0.77655095, -0.74408925, -0.57313335, -0.15333457,
|
||||
-0.74620694, -0.34858236, -0.42586932, -0.5240488, 0.1634339, -0.2447881, -0.57927346, -0.62732303, -0.82287043, -0.8474058
|
||||
};
|
||||
float *output;
|
||||
float kernel[2*3*3*3] = {
|
||||
0.26025516, 0.16536498, -0.24351254, 0.33892477, -0.34005195, 0.35202783, 0.34056443, 0.01422739, 0.13799345, 0.29489166,
|
||||
0.2781723, 0.178585, 0.22122234, 0.044115514, 0.13134438, 0.31705368, 0.22527462, -0.021323413, 0.115134746, -0.18216397,
|
||||
-0.21197563, -0.027848959, -0.01704529, -0.12401503, -0.23415318, -0.12661739, -0.35338148, 0.20049328, -0.076153606,
|
||||
-0.23642601, -0.3125769, -0.025851756, -0.30006272, 0.050762743, 0.32003498, 0.3052225, -0.0017385483, 0.25337684, -0.25664508,
|
||||
0.27846587, -0.3112659, 0.2066065, 0.31499845, 0.113178134, 0.09449363, -0.11828774, -0.12671001, -0.36259216, 0.2710235,
|
||||
-0.19676702, 0.023612618, -0.2596915, -0.34949252, -0.108270735
|
||||
};
|
||||
float bias[2] = { -1.6574852, -0.72915393 };
|
||||
|
||||
params.activation = TANH;
|
||||
params.has_bias = 1;
|
||||
params.biases = bias;
|
||||
params.dilation = 2;
|
||||
params.input_num = 3;
|
||||
params.kernel = kernel;
|
||||
params.kernel_size = 3;
|
||||
params.output_num = 2;
|
||||
params.padding_method = SAME;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 5;
|
||||
operands[0].dims[2] = 6;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_conv2d(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_with_valid(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
|
||||
y = tf.layers.conv2d(x, 2, 3, activation=tf.nn.tanh, padding='valid', bias_initializer=tf.keras.initializers.he_normal())
|
||||
data = np.random.rand(1, 5, 6, 3);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
|
||||
weights = dict([(var.name, sess.run(var)) for var in tf.trainable_variables()])
|
||||
kernel = weights['conv2d/kernel:0']
|
||||
kernel = np.transpose(kernel, [3, 0, 1, 2])
|
||||
print("kernel:")
|
||||
print(kernel.shape)
|
||||
print(list(kernel.flatten()))
|
||||
|
||||
bias = weights['conv2d/bias:0']
|
||||
print("bias:")
|
||||
print(bias.shape)
|
||||
print(list(bias.flatten()))
|
||||
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print("input:")
|
||||
print(data.shape)
|
||||
print(list(data.flatten()))
|
||||
|
||||
print("output:")
|
||||
print(output.shape)
|
||||
print(list(output.flatten()))
|
||||
*/
|
||||
|
||||
ConvolutionalParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*5*6*3] = {
|
||||
0.26126657468269665, 0.42762216215337556, 0.7466274030131497, 0.802550266787863, 0.3709323443076644, 0.5919817068197668, 0.49274512279324967,
|
||||
0.7170132295090351, 0.0911793215410649, 0.5134213878288361, 0.670132600785118, 0.49417034512633484, 0.03887389460089885, 0.436785102836845,
|
||||
0.1490231658611978, 0.6413606121498127, 0.8595987991375995, 0.9132593077586231, 0.7075959004873255, 0.17754995944845464, 0.5212507214937141,
|
||||
0.35379732738215475, 0.25205107358505296, 0.3928792840544273, 0.09485294189485782, 0.8685115437448666, 0.6489046799288605, 0.509253797582924,
|
||||
0.8993255536791972, 0.18740056466602373, 0.34237617336313986, 0.3871438962989183, 0.1488532571774911, 0.5187002331293636, 0.8137098818752955,
|
||||
0.521761863717401, 0.4622312310118274, 0.29038411334638825, 0.16194915718170566, 0.5175999923925211, 0.8852230040101133, 0.0218263385047206,
|
||||
0.08482355352852367, 0.3463638568376264, 0.28627127120619733, 0.9553293378948409, 0.4803391055970835, 0.841635695030805, 0.3556828280031952,
|
||||
0.06778527221541808, 0.28193560357091596, 0.8399957619031576, 0.03305536359456385, 0.6625039162109645, 0.9300552020023897, 0.8551529138204146,
|
||||
0.6133216915522418, 0.222427800857393, 0.1315422686800336, 0.6189144989185527, 0.5346184916866876, 0.8348888624532548, 0.6544834567840291,
|
||||
0.2844062293389934, 0.28780026600883324, 0.5372272015684924, 0.6250226011503823, 0.28119106062279453, 0.49655812908420094, 0.6451488959145951,
|
||||
0.7362580606834843, 0.44815578616664087, 0.6454760235835586, 0.6794062414265861, 0.045378883014935756, 0.9008388543865096, 0.7949752851269782,
|
||||
0.4179928876222264, 0.28733419007048644, 0.996902319501908, 0.5690851338677467, 0.9511814013279738, 0.025323788678181636, 0.5594359732604794,
|
||||
0.1213732595086251, 0.7172624313368294, 0.6759328959074691, 0.07252138454885071, 0.17557735158403442, 0.5988895455048769
|
||||
};
|
||||
float expected_output[1*3*4*2] = {
|
||||
-0.556947, -0.42143887, -0.092070885, 0.27404794, -0.41886684, 0.0862887, -0.25001016, -0.342721, 0.020730592, 0.04016919, -0.69839877,
|
||||
-0.06136704, 0.14186388, -0.11655602, -0.23489095, -0.3845829, -0.19017771, 0.1595885, -0.18308741, -0.3071209, -0.5848686, -0.22509028,
|
||||
-0.6023201, -0.14448485
|
||||
};
|
||||
float *output;
|
||||
float kernel[2*3*3*3] = {
|
||||
-0.25291282, 0.22402048, 0.028642118, -0.14615723, -0.27362752, -0.34801802, -0.2759148, 0.19594926, -0.25029412, 0.34606284, 0.10376671,
|
||||
-0.1015394, 0.23616093, 0.2134214, 0.35285157, 0.05893758, 0.0024731457, -0.17143056, 0.35758412, 0.2186206, -0.28384736, -0.21206513,
|
||||
-0.20871592, 0.27070445, 0.25878823, 0.11136332, -0.33737376, 0.08353335, -0.34290665, 0.041805506, -0.09738535, 0.3284936, -0.16838405,
|
||||
-0.032494456, -0.29193437, 0.033259362, -0.09272635, -0.2802651, -0.28648436, 0.3542878, 0.2432127, -0.24551713, 0.27813476, 0.21024024,
|
||||
-0.013690501, -0.1350077, -0.07826337, -0.34563828, 0.3220685, -0.07571727, 0.19420576, 0.20783454, 0.18738335, 0.16672492
|
||||
};
|
||||
float bias[2] = { -0.4773722, -0.19620377 };
|
||||
|
||||
params.activation = TANH;
|
||||
params.has_bias = 1;
|
||||
params.biases = bias;
|
||||
params.dilation = 1;
|
||||
params.input_num = 3;
|
||||
params.kernel = kernel;
|
||||
params.kernel_size = 3;
|
||||
params.output_num = 2;
|
||||
params.padding_method = VALID;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 5;
|
||||
operands[0].dims[2] = 6;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_conv2d(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_with_valid())
|
||||
return 1;
|
||||
if (test_with_same_dilate())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
102
externals/ffmpeg/tests/dnn/dnn-layer-depth2space-test.c
vendored
Executable file
102
externals/ffmpeg/tests/dnn/dnn-layer-depth2space-test.c
vendored
Executable file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Guo Yejun
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native.h"
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_depth2space.h"
|
||||
|
||||
#define EPSON 0.00001
|
||||
|
||||
static int test(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[1, None, None, 4])
|
||||
y = tf.depth_to_space(x, 2)
|
||||
data = np.random.rand(1, 5, 3, 4);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print("input:")
|
||||
print(data.shape)
|
||||
print(list(data.flatten()))
|
||||
|
||||
print("output:")
|
||||
print(output.shape)
|
||||
print(list(output.flatten()))
|
||||
*/
|
||||
|
||||
DepthToSpaceParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*5*3*4] = {
|
||||
0.09771065121566602, 0.6336807372403175, 0.5142416549709786, 0.8027206567330333, 0.2154276025069397, 0.12112878462616772, 0.913936596765778,
|
||||
0.38881443647542646, 0.5850447615898835, 0.9311499327398275, 0.3613660929428246, 0.5420722002125493, 0.6002131190230359, 0.44800665702299525,
|
||||
0.7271322557896777, 0.3869293511885826, 0.5144404769364138, 0.6910844856987723, 0.6142102742269762, 0.6249991371621018, 0.45663376215836626,
|
||||
0.19523477129943423, 0.2483895888532045, 0.64326768256278, 0.5485877602998981, 0.45442067849873546, 0.529374943304256, 0.30439850391811885,
|
||||
0.11961343361340993, 0.2909643484561082, 0.9810970344127848, 0.8886928489786549, 0.6112237084436409, 0.8852482695156674, 0.9110868043114374,
|
||||
0.21242780027585217, 0.7101536973207572, 0.9709717457443375, 0.2702666770969332, 0.7718295953780221, 0.3957005164588574, 0.24383544252475453,
|
||||
0.040143453532367035, 0.26358051835323115, 0.013130251443791319, 0.3016550481482074, 0.03582340459943956, 0.718025513612361, 0.09844204177633753,
|
||||
0.04433767496953056, 0.6221895044119757, 0.6190414032940228, 0.8963550834625371, 0.5642449700064629, 0.2482982014723497, 0.17824909294583013,
|
||||
0.024401882408643272, 0.21742800875253465, 0.6794724473181843, 0.4814830479242237
|
||||
};
|
||||
float expected_output[1*10*6*1] = {
|
||||
0.097710654, 0.63368076, 0.2154276, 0.12112878, 0.58504474, 0.93114996, 0.51424164, 0.80272067, 0.9139366, 0.38881445,
|
||||
0.3613661, 0.5420722, 0.6002131, 0.44800666, 0.5144405, 0.6910845, 0.45663378, 0.19523478, 0.72713226, 0.38692936,
|
||||
0.61421025, 0.62499917, 0.24838959, 0.6432677, 0.54858774, 0.4544207, 0.11961343, 0.29096434, 0.6112237, 0.88524824,
|
||||
0.52937496, 0.3043985, 0.98109704, 0.88869286, 0.9110868, 0.2124278, 0.7101537, 0.97097176, 0.3957005, 0.24383545,
|
||||
0.013130251, 0.30165505, 0.27026668, 0.7718296, 0.040143453, 0.26358053, 0.035823405, 0.7180255, 0.09844204,
|
||||
0.044337675, 0.8963551, 0.564245, 0.024401883, 0.21742801, 0.6221895, 0.6190414, 0.2482982, 0.17824909, 0.67947245, 0.48148304
|
||||
};
|
||||
float *output;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 5;
|
||||
operands[0].dims[2] = 3;
|
||||
operands[0].dims[3] = 4;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
params.block_size = 2;
|
||||
dnn_execute_layer_depth2space(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return test();
|
||||
}
|
209
externals/ffmpeg/tests/dnn/dnn-layer-mathbinary-test.c
vendored
Executable file
209
externals/ffmpeg/tests/dnn/dnn-layer-mathbinary-test.c
vendored
Executable file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright (c) 2020
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_mathbinary.h"
|
||||
#include "libavutil/avassert.h"
|
||||
|
||||
#define EPSON 0.00005
|
||||
|
||||
static float get_expected(float f1, float f2, DNNMathBinaryOperation op)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case DMBO_SUB:
|
||||
return f1 - f2;
|
||||
case DMBO_ADD:
|
||||
return f1 + f2;
|
||||
case DMBO_MUL:
|
||||
return f1 * f2;
|
||||
case DMBO_REALDIV:
|
||||
return f1 / f2;
|
||||
case DMBO_MINIMUM:
|
||||
return (f1 < f2) ? f1 : f2;
|
||||
default:
|
||||
av_assert0(!"not supported yet");
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
static int test_broadcast_input0(DNNMathBinaryOperation op)
|
||||
{
|
||||
DnnLayerMathBinaryParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*1*2*3] = {
|
||||
-3, 2.5, 2, -2.1, 7.8, 100
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.bin_op = op;
|
||||
params.input0_broadcast = 1;
|
||||
params.input1_broadcast = 0;
|
||||
params.v = 7.28;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 1;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_math_binary(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
|
||||
float expected_output = get_expected(params.v, input[i], op);
|
||||
if (fabs(output[i] - expected_output) > EPSON) {
|
||||
printf("op %d, at index %d, output: %f, expected_output: %f (%s:%d)\n",
|
||||
op, i, output[i], expected_output, __FILE__, __LINE__);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_broadcast_input1(DNNMathBinaryOperation op)
|
||||
{
|
||||
DnnLayerMathBinaryParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*1*2*3] = {
|
||||
-3, 2.5, 2, -2.1, 7.8, 100
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.bin_op = op;
|
||||
params.input0_broadcast = 0;
|
||||
params.input1_broadcast = 1;
|
||||
params.v = 7.28;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 1;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_math_binary(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
|
||||
float expected_output = get_expected(input[i], params.v, op);
|
||||
if (fabs(output[i] - expected_output) > EPSON) {
|
||||
printf("op %d, at index %d, output: %f, expected_output: %f (%s:%d)\n",
|
||||
op, i, output[i], expected_output, __FILE__, __LINE__);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_no_broadcast(DNNMathBinaryOperation op)
|
||||
{
|
||||
DnnLayerMathBinaryParams params;
|
||||
DnnOperand operands[3];
|
||||
int32_t input_indexes[2];
|
||||
float input0[1*1*2*3] = {
|
||||
-3, 2.5, 2, -2.1, 7.8, 100
|
||||
};
|
||||
float input1[1*1*2*3] = {
|
||||
-1, 2, 3, -21, 8, 10.0
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.bin_op = op;
|
||||
params.input0_broadcast = 0;
|
||||
params.input1_broadcast = 0;
|
||||
|
||||
operands[0].data = input0;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 1;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = input1;
|
||||
operands[1].dims[0] = 1;
|
||||
operands[1].dims[1] = 1;
|
||||
operands[1].dims[2] = 2;
|
||||
operands[1].dims[3] = 3;
|
||||
operands[2].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
input_indexes[1] = 1;
|
||||
dnn_execute_layer_math_binary(operands, input_indexes, 2, ¶ms);
|
||||
|
||||
output = operands[2].data;
|
||||
for (int i = 0; i < sizeof(input0) / sizeof(float); i++) {
|
||||
float expected_output = get_expected(input0[i], input1[i], op);
|
||||
if (fabs(output[i] - expected_output) > EPSON) {
|
||||
printf("op %d, at index %d, output: %f, expected_output: %f (%s:%d)\n",
|
||||
op, i, output[i], expected_output, __FILE__, __LINE__);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test(DNNMathBinaryOperation op)
|
||||
{
|
||||
if (test_broadcast_input0(op))
|
||||
return 1;
|
||||
|
||||
if (test_broadcast_input1(op))
|
||||
return 1;
|
||||
|
||||
if (test_no_broadcast(op))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test(DMBO_SUB))
|
||||
return 1;
|
||||
|
||||
if (test(DMBO_ADD))
|
||||
return 1;
|
||||
|
||||
if (test(DMBO_MUL))
|
||||
return 1;
|
||||
|
||||
if (test(DMBO_REALDIV))
|
||||
return 1;
|
||||
|
||||
if (test(DMBO_MINIMUM))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
81
externals/ffmpeg/tests/dnn/dnn-layer-mathunary-test.c
vendored
Executable file
81
externals/ffmpeg/tests/dnn/dnn-layer-mathunary-test.c
vendored
Executable file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2020
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_mathunary.h"
|
||||
#include "libavutil/avassert.h"
|
||||
|
||||
#define EPS 0.00001
|
||||
|
||||
static float get_expected(float f, DNNMathUnaryOperation op)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
case DMUO_ABS:
|
||||
return (f >= 0) ? f : -f;
|
||||
default:
|
||||
av_assert0(!"not supported yet");
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
static int test(DNNMathUnaryOperation op)
|
||||
{
|
||||
DnnLayerMathUnaryParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*1*2*3] = {
|
||||
-3, 2.5, 2, -2.1, 7.8, 100};
|
||||
float *output;
|
||||
|
||||
params.un_op = op;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 1;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_math_unary(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(input) / sizeof(float); ++i) {
|
||||
float expected_output = get_expected(input[i], op);
|
||||
if(fabs(output[i] - expected_output) > EPS) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int agrc, char **argv)
|
||||
{
|
||||
if (test(DMUO_ABS))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
71
externals/ffmpeg/tests/dnn/dnn-layer-maximum-test.c
vendored
Executable file
71
externals/ffmpeg/tests/dnn/dnn-layer-maximum-test.c
vendored
Executable file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Guo Yejun
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_maximum.h"
|
||||
|
||||
#define EPSON 0.00001
|
||||
|
||||
static int test(void)
|
||||
{
|
||||
DnnLayerMaximumParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*1*2*3] = {
|
||||
-3, 2.5, 2, -2.1, 7.8, 100
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.val.y = 2.3;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 1;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_maximum(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
|
||||
float expected_output = input[i] > params.val.y ? input[i] : params.val.y;
|
||||
if (fabs(output[i] - expected_output) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
239
externals/ffmpeg/tests/dnn/dnn-layer-pad-test.c
vendored
Executable file
239
externals/ffmpeg/tests/dnn/dnn-layer-pad-test.c
vendored
Executable file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Guo Yejun
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "libavfilter/dnn/dnn_backend_native_layer_pad.h"
|
||||
|
||||
#define EPSON 0.00001
|
||||
|
||||
static int test_with_mode_symmetric(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
|
||||
y = tf.pad(x, [[0, 0], [2, 3], [3, 2], [0, 0]], 'SYMMETRIC')
|
||||
data = np.arange(48).reshape(1, 4, 4, 3);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print(list(data.flatten()))
|
||||
print(list(output.flatten()))
|
||||
print(data.shape)
|
||||
print(output.shape)
|
||||
*/
|
||||
|
||||
LayerPadParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*4*4*3] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
|
||||
};
|
||||
float expected_output[1*9*9*3] = {
|
||||
18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 18.0, 19.0, 20.0, 6.0, 7.0, 8.0, 3.0,
|
||||
4.0, 5.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 6.0, 7.0, 8.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 9.0, 10.0, 11.0, 6.0, 7.0, 8.0, 18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
|
||||
21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 18.0, 19.0, 20.0, 30.0, 31.0, 32.0, 27.0, 28.0, 29.0, 24.0, 25.0, 26.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 33.0,
|
||||
34.0, 35.0, 30.0, 31.0, 32.0, 42.0, 43.0, 44.0, 39.0, 40.0, 41.0, 36.0, 37.0, 38.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 45.0, 46.0, 47.0, 42.0, 43.0,
|
||||
44.0, 42.0, 43.0, 44.0, 39.0, 40.0, 41.0, 36.0, 37.0, 38.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 45.0, 46.0, 47.0, 42.0, 43.0, 44.0, 30.0, 31.0, 32.0,
|
||||
27.0, 28.0, 29.0, 24.0, 25.0, 26.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 33.0, 34.0, 35.0, 30.0, 31.0, 32.0, 18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0,
|
||||
13.0, 14.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 18.0, 19.0, 20.0
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.mode = LPMP_SYMMETRIC;
|
||||
params.paddings[0][0] = 0;
|
||||
params.paddings[0][1] = 0;
|
||||
params.paddings[1][0] = 2;
|
||||
params.paddings[1][1] = 3;
|
||||
params.paddings[2][0] = 3;
|
||||
params.paddings[2][1] = 2;
|
||||
params.paddings[3][0] = 0;
|
||||
params.paddings[3][1] = 0;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 4;
|
||||
operands[0].dims[2] = 4;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int test_with_mode_reflect(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[3, None, None, 3])
|
||||
y = tf.pad(x, [[1, 2], [0, 0], [0, 0], [0, 0]], 'REFLECT')
|
||||
data = np.arange(36).reshape(3, 2, 2, 3);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print(list(data.flatten()))
|
||||
print(list(output.flatten()))
|
||||
print(data.shape)
|
||||
print(output.shape)
|
||||
*/
|
||||
|
||||
LayerPadParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[3*2*2*3] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
|
||||
};
|
||||
float expected_output[6*2*2*3] = {
|
||||
12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
|
||||
12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0,
|
||||
35.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.mode = LPMP_REFLECT;
|
||||
params.paddings[0][0] = 1;
|
||||
params.paddings[0][1] = 2;
|
||||
params.paddings[1][0] = 0;
|
||||
params.paddings[1][1] = 0;
|
||||
params.paddings[2][0] = 0;
|
||||
params.paddings[2][1] = 0;
|
||||
params.paddings[3][0] = 0;
|
||||
params.paddings[3][1] = 0;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 3;
|
||||
operands[0].dims[1] = 2;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int test_with_mode_constant(void)
|
||||
{
|
||||
// the input data and expected data are generated with below python code.
|
||||
/*
|
||||
x = tf.placeholder(tf.float32, shape=[1, None, None, 3])
|
||||
y = tf.pad(x, [[0, 0], [1, 0], [0, 0], [1, 2]], 'CONSTANT', constant_values=728)
|
||||
data = np.arange(12).reshape(1, 2, 2, 3);
|
||||
|
||||
sess=tf.Session()
|
||||
sess.run(tf.global_variables_initializer())
|
||||
output = sess.run(y, feed_dict={x: data})
|
||||
|
||||
print(list(data.flatten()))
|
||||
print(list(output.flatten()))
|
||||
print(data.shape)
|
||||
print(output.shape)
|
||||
*/
|
||||
|
||||
LayerPadParams params;
|
||||
DnnOperand operands[2];
|
||||
int32_t input_indexes[1];
|
||||
float input[1*2*2*3] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
|
||||
};
|
||||
float expected_output[1*3*2*6] = {
|
||||
728.0, 728.0, 728.0, 728.0, 728.0, 728.0, 728.0, 728.0, 728.0, 728.0, 728.0,
|
||||
728.0, 728.0, 0.0, 1.0, 2.0, 728.0, 728.0, 728.0, 3.0, 4.0, 5.0, 728.0, 728.0,
|
||||
728.0, 6.0, 7.0, 8.0, 728.0, 728.0, 728.0, 9.0, 10.0, 11.0, 728.0, 728.0
|
||||
};
|
||||
float *output;
|
||||
|
||||
params.mode = LPMP_CONSTANT;
|
||||
params.constant_values = 728;
|
||||
params.paddings[0][0] = 0;
|
||||
params.paddings[0][1] = 0;
|
||||
params.paddings[1][0] = 1;
|
||||
params.paddings[1][1] = 0;
|
||||
params.paddings[2][0] = 0;
|
||||
params.paddings[2][1] = 0;
|
||||
params.paddings[3][0] = 1;
|
||||
params.paddings[3][1] = 2;
|
||||
|
||||
operands[0].data = input;
|
||||
operands[0].dims[0] = 1;
|
||||
operands[0].dims[1] = 2;
|
||||
operands[0].dims[2] = 2;
|
||||
operands[0].dims[3] = 3;
|
||||
operands[1].data = NULL;
|
||||
|
||||
input_indexes[0] = 0;
|
||||
dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms);
|
||||
|
||||
output = operands[1].data;
|
||||
for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) {
|
||||
if (fabs(output[i] - expected_output[i]) > EPSON) {
|
||||
printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]);
|
||||
av_freep(&output);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
av_freep(&output);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (test_with_mode_symmetric())
|
||||
return 1;
|
||||
|
||||
if (test_with_mode_reflect())
|
||||
return 1;
|
||||
|
||||
if (test_with_mode_constant())
|
||||
return 1;
|
||||
}
|
Reference in New Issue
Block a user