|
15 | 15 | * ============================================================================= |
16 | 16 | */ |
17 | 17 |
|
18 | | -import { GPGPUProgram } from './gpgpu_math'; |
| 18 | +import {GPGPUProgram} from './gpgpu_math'; |
19 | 19 |
|
20 | 20 | export class CropAndResizeProgram implements GPGPUProgram { |
21 | 21 | variableNames = ['Image', 'Boxes', 'BoxInd']; |
22 | 22 | outputShape: number[] = []; |
23 | 23 | userCode: string; |
24 | 24 |
|
25 | 25 | constructor( |
26 | | - imageShape: [number, number, number, number], boxShape: [number, number], |
27 | | - cropSize: [number, number], method: 'bilinear' | 'nearest', |
28 | | - extrapolationValue: number) { |
| 26 | + imageShape: [number, number, number, number], boxShape: [number, number], |
| 27 | + cropSize: [number, number], method: 'bilinear'|'nearest', |
| 28 | + extrapolationValue: number) { |
29 | 29 | const [batch, imageHeight, imageWidth, depth] = imageShape; |
30 | | - const [numBoxes,] = boxShape; |
| 30 | + const [numBoxes, ] = boxShape; |
31 | 31 | const [cropHeight, cropWidth] = cropSize; |
32 | 32 | this.outputShape = [numBoxes, cropHeight, cropWidth, depth]; |
33 | 33 | const methodId = method === 'bilinear' ? 1 : 0; |
34 | 34 |
|
35 | 35 | const [inputHeightFloat, inputWidthFloat] = |
36 | | - [`${imageHeight - 1}.0`, `${imageWidth - 1}.0`]; |
| 36 | + [`${imageHeight - 1}.0`, `${imageWidth - 1}.0`]; |
37 | 37 |
|
38 | 38 | const [heightRatio, heightScale, inY] = cropHeight > 1 ? |
39 | | - [ |
40 | | - `${(imageHeight-1)/(cropHeight-1)}`, |
41 | | - '(y2-y1) * height_ratio', |
42 | | - `y1*${inputHeightFloat} + float(y)*(height_scale)`, |
43 | | - ] : |
44 | | - [ |
45 | | - '0.0', |
46 | | - '0.0', |
47 | | - `0.5 * (y1+y2) * ${inputHeightFloat}`, |
48 | | - ]; |
| 39 | + [ |
| 40 | + `${(imageHeight - 1) / (cropHeight - 1)}`, |
| 41 | + '(y2-y1) * height_ratio', |
| 42 | + `y1*${inputHeightFloat} + float(y)*(height_scale)`, |
| 43 | + ] : |
| 44 | + [ |
| 45 | + '0.0', |
| 46 | + '0.0', |
| 47 | + `0.5 * (y1+y2) * ${inputHeightFloat}`, |
| 48 | + ]; |
49 | 49 | const [widthRatio, widthScale, inX] = cropWidth > 1 ? |
50 | | - [ |
51 | | - `${(imageWidth-1)/(cropWidth-1)}`, |
52 | | - '(x2-x1) * width_ratio', |
53 | | - `x1*${inputWidthFloat} + float(x)*(width_scale)`, |
54 | | - ] : |
55 | | - [ |
56 | | - '0.0', |
57 | | - '0.0', |
58 | | - `0.5 * (x1+x2) * ${inputWidthFloat}`, |
59 | | - ]; |
| 50 | + [ |
| 51 | + `${(imageWidth - 1) / (cropWidth - 1)}`, |
| 52 | + '(x2-x1) * width_ratio', |
| 53 | + `x1*${inputWidthFloat} + float(x)*(width_scale)`, |
| 54 | + ] : |
| 55 | + [ |
| 56 | + '0.0', |
| 57 | + '0.0', |
| 58 | + `0.5 * (x1+x2) * ${inputWidthFloat}`, |
| 59 | + ]; |
60 | 60 |
|
61 | 61 | // Reference implementation |
62 | 62 | // tslint:disable-next-line:max-line-length |
|
0 commit comments