| 27 | namespace TEngine { |
| 28 | |
| 29 | bool Deconvolution::InferShape(const std::vector<TShape>& ishape, std::vector<TShape>& oshape, int layout) |
| 30 | |
| 31 | { |
| 32 | const TShape& input_shape = ishape[0]; |
| 33 | //const TShape& weight_shape = ishape[1]; |
| 34 | int input_n = input_shape.GetN(); |
| 35 | int input_h = input_shape.GetH(); |
| 36 | int input_w = input_shape.GetW(); |
| 37 | |
| 38 | //int output_c = weight_shape.Shape(1); |
| 39 | if(param_.pad_h0 < 0) |
| 40 | { |
| 41 | int n = (input_h - 1) / param_.stride_h + 1; |
| 42 | int total_len = (n - 1) * param_.stride_h + param_.kernel_h; |
| 43 | int pad_num = total_len - input_h; |
| 44 | |
| 45 | if(param_.pad_h0 == -1) // TF or SAME_UPPER in ONNX |
| 46 | { |
| 47 | param_.pad_h0 = pad_num / 2; |
| 48 | param_.pad_h1 = pad_num - pad_num / 2; |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | // SAME_LOWER in ONNX |
| 53 | param_.pad_h0 = pad_num - pad_num / 2; |
| 54 | param_.pad_h1 = pad_num / 2; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if(param_.pad_w0 < 0) |
| 59 | { |
| 60 | int n = (input_w - 1) / param_.stride_w + 1; |
| 61 | int total_len = (n - 1) * param_.stride_w + param_.kernel_w; |
| 62 | int pad_num = total_len - input_w; |
| 63 | |
| 64 | if(param_.pad_w0 == -1) // TF or SAME_UPPER in ONNX |
| 65 | { |
| 66 | param_.pad_w0 = pad_num / 2; |
| 67 | param_.pad_w1 = pad_num - pad_num / 2; |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | // SAME_LOWER in ONNX |
| 72 | param_.pad_w0 = pad_num - pad_num / 2; |
| 73 | param_.pad_w1 = pad_num / 2; |
| 74 | } |
| 75 | } |
| 76 | int kernel_extent_w = param_.dilation_w * (param_.kernel_w - 1) + 1; |
| 77 | int kernel_extent_h = param_.dilation_h * (param_.kernel_h - 1) + 1; |
| 78 | |
| 79 | int output_h = (input_h - 1) * param_.stride_h + kernel_extent_h - param_.pad_h0 - param_.pad_h1; |
| 80 | int output_w = (input_w - 1) * param_.stride_w + kernel_extent_w - param_.pad_w0 - param_.pad_w1; |
| 81 | |
| 82 | // std::vector<int> dim = {input_n, param_.num_output, output_h, output_w}; |
| 83 | |
| 84 | TShape result; |
| 85 | |
| 86 | if(layout == TENGINE_LAYOUT_NHWC) |
nothing calls this directly
no test coverage detected