MCPcopy Create free account
hub / github.com/OAID/Tengine / InferShape

Method InferShape

operator/operator/fully_connected.cpp:29–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace TEngine {
28
29bool FullyConnected::InferShape(const std::vector<TEngine::TShape>& ishape, std::vector<TEngine::TShape>& oshape,
30 int layout)
31{
32 const TShape& input = ishape[0];
33 const TShape& weight = ishape[1];
34
35 std::vector<int> dim;
36
37 int n = weight.Shape(0);
38 int k = weight.Shape(1);
39
40 int m = input.Shape(0);
41 int input_k = input.Shape(1);
42
43 if(input.GetDim().size() == 2)
44 {
45 dim = {m, n};
46 }
47 else if(input.GetDim().size() == 3)
48 {
49 input_k *= input.Shape(2);
50 if(layout == TENGINE_LAYOUT_NHWC)
51 dim = {m, 1, n};
52 else
53 dim = {m, n, 1};
54 }
55 else if(input.GetDim().size() == 4)
56 {
57 input_k *= input.Shape(2) * input.Shape(3);
58 if(layout == TENGINE_LAYOUT_NHWC)
59 dim = {m, 1, 1, n};
60 else
61 dim = {m, n, 1, 1};
62 }
63 else
64 return false;
65
66 if(k != input_k)
67 return false;
68
69 TShape shape;
70
71 shape.SetDim(dim);
72 shape.SetDataLayout(layout);
73
74 oshape[0] = shape;
75
76 return true;
77}
78
79float FullyConnected::GetFops(const std::vector<TShape>& inputs, const std::vector<TShape>& outputs)
80{

Callers

nothing calls this directly

Calls 4

ShapeMethod · 0.80
SetDimMethod · 0.80
SetDataLayoutMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected