|
|
|
@ -21,6 +21,7 @@ import numpy as np
|
|
|
|
|
import paddle.fluid.core as core
|
|
|
|
|
from op_test import OpTest
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
from paddle.fluid import Program, program_guard
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def adaptive_start_index(index, input_size, output_size):
|
|
|
|
@ -1275,5 +1276,25 @@ class TestPool2dAPI_Error(unittest.TestCase):
|
|
|
|
|
self.assertRaises(ValueError, run_5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDygraphPool2DAPIError(unittest.TestCase):
|
|
|
|
|
def test_errors(self):
|
|
|
|
|
with program_guard(Program(), Program()):
|
|
|
|
|
# the input of Pool2D must be Variable.
|
|
|
|
|
data1 = np.random.random((3, 32, 32, 5)).astype('float32')
|
|
|
|
|
pool2d = fluid.dygraph.Pool2D(
|
|
|
|
|
pool_size=2,
|
|
|
|
|
pool_type='max',
|
|
|
|
|
pool_stride=1,
|
|
|
|
|
global_pooling=False)
|
|
|
|
|
self.assertRaises(TypeError, pool2d, data1)
|
|
|
|
|
|
|
|
|
|
# the input dtype of Pool2D must be uint8 or int8 or float16 or float32 or float64
|
|
|
|
|
# uint8 and int8 only can be set on mkldnn
|
|
|
|
|
# float16 only can be set on GPU place
|
|
|
|
|
data2 = fluid.layers.data(
|
|
|
|
|
name='x1', shape=[3, 32, 32, 5], dtype="int32")
|
|
|
|
|
self.assertRaises(TypeError, pool2d, data2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|