Skip to content

Commit

Permalink
Add NCHW support for resizebilinear (#2205)
Browse files Browse the repository at this point in the history
* add nchw support for resizebilinear

* fix style

* fixed indent

* test cover more cases

* remove double code and python interface

* add doc
  • Loading branch information
yangw1234 committed Jan 22, 2018
1 parent daf81c2 commit 0610cd8
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 68 deletions.
58 changes: 58 additions & 0 deletions docs/docs/APIGuide/Layers/Convolution-Layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2209,4 +2209,62 @@ val output = module.forward(input)

[com.intel.analytics.bigdl.tensor.DenseTensor of size 1x2x4x4x4]

```

---
## ResizeBilinear ##

**Scala:**
```scala
val module = ResizeBilinear(outputHeight, outputWidth,
alignCorners=false, dataFormat = DataFormat.NCHW)
```
**Python:**
```python
m = ResizeBilinear(outputHeight, outputWidth,
alignCorners=False, dataFormat="NCHW")
```

Resize the input image with bilinear interpolation. The input image must be a float tensor with
NHWC or NCHW layout.

**Scala example:**
```scala

scala>
import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric.NumericFloat
import com.intel.analytics.bigdl.nn._
import com.intel.analytics.bigdl.tensor._

val module = ResizeBilinear(4, 4)
val input = Tensor(1, 1, 2, 2).range(1, 4)
val output = module.forward(input)

> output
(1,1,.,.) =
1.0 1.5 2.0 2.0
2.0 2.5 3.0 3.0
3.0 3.5 4.0 4.0
3.0 3.5 4.0 4.0

[com.intel.analytics.bigdl.tensor.DenseTensor$mcF$sp of size 1x1x4x4]

```

**Python example:**
```python
from bigdl.nn.layer import *
import numpy as np

module = ResizeBilinear(4, 4)
input = np.arange(1, 5).reshape(1, 1, 2, 2)
output = module.forward(input)
print output
```
The output is
```python
[[[[ 1. 1.5 2. 2. ]
[ 2. 2.5 3. 3. ]
[ 3. 3.5 4. 4. ]
[ 3. 3.5 4. 4. ]]]]
```
10 changes: 6 additions & 4 deletions pyspark/bigdl/nn/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5085,17 +5085,19 @@ def __init__(self, cells, bigdl_type="float"):
class ResizeBilinear(Layer):
"""
Resize the input image with bilinear interpolation. The input image must be a float tensor with
NHWC layout
NHWC or NCHW layout
:param output_height: output height
:param output_width: output width
:param align_corner: align corner or not
:param data_format: the data format of the input image, NHWC or NCHW
>>> resizeBilinear = ResizeBilinear(10, 20, False)
>>> resizeBilinear = ResizeBilinear(10, 20, False, "NCHW")
creating: createResizeBilinear
"""
def __init__(self, output_height, output_width, align_corner, bigdl_type="float"):
super(ResizeBilinear, self).__init__(None, bigdl_type, output_height, output_width, align_corner)
def __init__(self, output_height, output_width, align_corner=False, data_format="NCHW", bigdl_type="float"):
super(ResizeBilinear, self).__init__(None, bigdl_type, output_height,
output_width, align_corner, data_format)

class GaussianSampler(Layer):
"""
Expand Down
Loading

0 comments on commit 0610cd8

Please sign in to comment.