| 47 | */ |
| 48 | |
| 49 | bool Convolution::InferShape(const std::vector<TShape>& ishape, std::vector<TShape>& oshape, int layout) |
| 50 | { |
| 51 | if(ishape.size() < 2){ |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | const TShape& input_shape = ishape[0]; |
| 56 | const TShape& weight_shape = ishape[1]; |
| 57 | |
| 58 | if(input_shape.GetDim().size() != 4 || weight_shape.GetDim().size() != 4){ |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | int input_n = input_shape.GetN(); |
| 63 | int input_c = input_shape.GetC(); |
| 64 | int input_h = input_shape.GetH(); |
| 65 | int input_w = input_shape.GetW(); |
| 66 | |
| 67 | int output_c = weight_shape.GetN(); |
| 68 | int weight_c = weight_shape.GetC(); |
| 69 | int weight_h = weight_shape.GetH(); |
| 70 | int weight_w = weight_shape.GetW(); |
| 71 | |
| 72 | if((input_c != weight_c * param_.group) || (output_c != param_.output_channel) || (param_.kernel_h != weight_h) || |
| 73 | (param_.kernel_w != weight_w)) |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | param_.input_channel = input_c; |
| 79 | |
| 80 | if(param_.pad_h0 < 0) |
| 81 | { |
| 82 | int n = (input_h - 1) / param_.stride_h + 1; |
| 83 | int total_len = (n - 1) * param_.stride_h + param_.kernel_h; |
| 84 | int pad_num = total_len - input_h; |
| 85 | |
| 86 | if(param_.pad_h0 == -1) // TF or SAME_UPPER in ONNX |
| 87 | { |
| 88 | param_.pad_h0 = pad_num / 2; |
| 89 | param_.pad_h1 = pad_num - pad_num / 2; |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | // SAME_LOWER in ONNX |
| 94 | param_.pad_h0 = pad_num - pad_num / 2; |
| 95 | param_.pad_h1 = pad_num / 2; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if(param_.pad_w0 < 0) |
| 100 | { |
| 101 | int n = (input_w - 1) / param_.stride_w + 1; |
| 102 | int total_len = (n - 1) * param_.stride_w + param_.kernel_w; |
| 103 | int pad_num = total_len - input_w; |
| 104 | |
| 105 | if(param_.pad_w0 == -1) // TF or SAME_UPPER in ONNX |
| 106 | { |