|
| 1 | +/* Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +==============================================================================*/ |
| 15 | + |
| 16 | +import * as conv_util from './conv_util'; |
| 17 | + |
| 18 | +describe('conv_util computeConvInfo', () => { |
| 19 | + it('1x1 conv over 1x1 array with same pad', () => { |
| 20 | + const inShape: [number, number, number] = [1, 1, 1]; |
| 21 | + const convInfo = conv_util.computeConvInfo(inShape, 1, 1, 1, 1, 1, 'same'); |
| 22 | + expect(convInfo.outShape).toEqual([1, 1, 1]); |
| 23 | + }); |
| 24 | + |
| 25 | + it('2x2 conv over 3x3 array with same pad', () => { |
| 26 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 27 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 2, 1, 1, 1, 'same'); |
| 28 | + expect(convInfo.outShape).toEqual([3, 3, 1]); |
| 29 | + // Should produce non-even padding with extra pixel at the right/bottom. |
| 30 | + expect(convInfo.padInfo.left).toBe(0); |
| 31 | + expect(convInfo.padInfo.right).toBe(1); |
| 32 | + expect(convInfo.padInfo.top).toBe(0); |
| 33 | + expect(convInfo.padInfo.bottom).toBe(1); |
| 34 | + }); |
| 35 | + |
| 36 | + it('2x2 conv over 3x3 array with same pad', () => { |
| 37 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 38 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 2, 1, 1, 1, 'same'); |
| 39 | + expect(convInfo.outShape).toEqual([3, 3, 1]); |
| 40 | + }); |
| 41 | + |
| 42 | + it('2x2 conv over 3x3 array with valid pad', () => { |
| 43 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 44 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 2, 1, 1, 1, 'valid'); |
| 45 | + expect(convInfo.outShape).toEqual([2, 2, 1]); |
| 46 | + }); |
| 47 | + |
| 48 | + it('2x2 conv over 3x3 array with valid pad with stride 2', () => { |
| 49 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 50 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 2, 1, 2, 2, 'valid'); |
| 51 | + expect(convInfo.outShape).toEqual([1, 1, 1]); |
| 52 | + }); |
| 53 | + |
| 54 | + it('2x2 conv over 3x3 array with valid pad with stride 2', () => { |
| 55 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 56 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 2, 1, 2, 2, 'valid'); |
| 57 | + expect(convInfo.outShape).toEqual([1, 1, 1]); |
| 58 | + }); |
| 59 | + |
| 60 | + it('2x1 conv over 3x3 array with valid pad with stride 1', () => { |
| 61 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 62 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 1, 1, 1, 1, 'valid'); |
| 63 | + expect(convInfo.outShape).toEqual([2, 3, 1]); |
| 64 | + }); |
| 65 | + |
| 66 | + it('2x1 conv over 3x3 array with valid pad with strides h=2, w=1', () => { |
| 67 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 68 | + const convInfo = conv_util.computeConvInfo(inShape, 2, 1, 1, 2, 1, 'valid'); |
| 69 | + expect(convInfo.outShape).toEqual([1, 3, 1]); |
| 70 | + }); |
| 71 | + |
| 72 | + it('1x2 conv over 3x3 array with valid pad with stride 1', () => { |
| 73 | + const inShape: [number, number, number] = [3, 3, 1]; |
| 74 | + const convInfo = conv_util.computeConvInfo(inShape, 1, 2, 1, 1, 1, 'valid'); |
| 75 | + expect(convInfo.outShape).toEqual([3, 2, 1]); |
| 76 | + }); |
| 77 | +}); |
0 commit comments