Пример #1
0
 def test_gather(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.gather([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.gather([self.sym1, self.sym2], axis=-1).shape, None)
         self.assertEqual(
             dragon.gather([self.sym3, self.sym2], axis=1).shape, (1, 1))
Пример #2
0
 def test_eltwise_loss(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.losses.l2_loss([self.sym1, self.sym1]).shape, ())
         self.assertEqual(
             dragon.losses.l2_loss([self.sym1, self.sym1],
                                   reduction='none').shape, None)
Пример #3
0
 def test_extract_patches(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.vision.extract_patches(self.sym1).shape, None)
         self.assertEqual(
             dragon.vision.extract_patches(self.sym4).shape,
             (self.sym4.shape[0], None, None, None))
Пример #4
0
 def test_conv_transpose(self):
     w = dragon.Tensor((3, 3, 3, 3))
     with dragon.graph_mode():
         self.assertEqual(
             dragon.nn.conv2d_transpose([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.nn.conv2d_transpose([self.sym3, self.sym1]).shape, None)
         self.assertEqual(
             dragon.nn.conv2d_transpose([self.sym3, w]).shape,
             (self.sym3.shape[0], w.shape[0], None, None))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_padding=self.shape1).shape,
             (w.shape[0], w.shape[0], None, None))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_padding=self.shape2).shape,
             (w.shape[0], w.shape[0], None, None))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_shape=self.shape1).shape,
             (w.shape[0], w.shape[0], None, None))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_shape=self.shape2).shape,
             (w.shape[0], w.shape[0], None, None))
Пример #5
0
 def test_pad(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.pad(self.sym1, pads=[(1, 1)]).shape, None)
         self.assertEqual(
             dragon.pad(self.sym3, pads=[(1, 1)]).shape, (3, None))
         self.assertEqual(
             dragon.pad(self.sym3, pads=[(1, 1), (1, 1)]).shape, (3, None))
Пример #6
0
 def test_tile(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.tile(self.sym1, repeats=self.shape1).shape, None)
         self.assertEqual(
             dragon.tile(self.sym2, repeats=self.shape1).shape,
             (None, ) * len(self.sym2.shape))
Пример #7
0
 def test_broadcast_to(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.broadcast_to(self.sym1, shape=self.shape1).shape, None)
         self.assertEqual(
             dragon.broadcast_to(self.sym2, shape=self.shape1).shape,
             (None, ) * len(self.sym2.shape))
Пример #8
0
 def test_conv(self):
     w = dragon.Tensor((3, 3, 3, 3))
     with dragon.graph_mode():
         self.assertEqual(
             dragon.nn.conv2d([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.nn.conv2d([self.sym4, w]).shape,
             (self.sym4.shape[0], w.shape[0], None, None))
         self.assertEqual(
             dragon.nn.conv2d([w, w],
                              kernel_shape=1,
                              out_channels=w.shape[0]).shape, w.shape)
         self.assertEqual(
             dragon.nn.conv2d([w, w], kernel_shape=1, padding='SAME').shape,
             w.shape)
         self.assertEqual(
             dragon.nn.conv2d_transpose([self.sym4, w],
                                        out_channels=w.shape[1]).shape,
             (self.sym4.shape[0], w.shape[1], None, None))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_padding=(2, 2),
                                        kernel_shape=1).shape,
             (w.shape[0], w.shape[1], w.shape[2] + 2, w.shape[3] + 2))
         self.assertEqual(
             dragon.nn.conv2d_transpose([w, w],
                                        output_shape=(4, 4),
                                        output_padding=(2, 2),
                                        kernel_shape=1).shape,
             (w.shape[0], w.shape[1], 6, 6))
Пример #9
0
 def test_flatten(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.flatten(self.sym1, axis=1).shape, None)
         self.assertEqual(
             dragon.flatten(self.sym4, axis=1, end_axis=3).shape, (1, None))
         self.assertEqual(
             dragon.flatten(self.sym4, axis=1, end_axis=-1).shape,
             (1, None))
Пример #10
0
 def test_reshape(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.reshape(self.sym2, shape=(0, 1)).shape, (1, 1))
         self.assertEqual(
             dragon.reshape(self.sym3, shape=(0, -1)).shape, (1, None))
         self.assertEqual(
             dragon.reshape(self.sym3, shape=(0, 1, 0)).shape, None)
Пример #11
0
 def test_slice(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.slice(self.sym1, starts=self.shape1,
                          sizes=self.shape1).shape, None)
         self.assertEqual(
             dragon.slice(self.sym2, starts=self.shape1,
                          sizes=self.shape1).shape, None)
Пример #12
0
 def test_init_ops(self):
     init_funcs_v1 = [
         dragon.fill, dragon.ones, dragon.random.glorot_normal,
         dragon.random.glorot_uniform, dragon.random.normal,
         dragon.random.uniform, dragon.random.truncated_normal, dragon.zeros
     ]
     init_funcs_v2 = [
         dragon.ones_like, dragon.random.normal_like,
         dragon.random.uniform_like, dragon.zeros_like
     ]
     for func in init_funcs_v1:
         with dragon.graph_mode():
             self.assertEqual(func(shape=self.shape1).shape, None)
     for func in init_funcs_v2:
         with dragon.graph_mode():
             self.assertEqual(func(self.sym1).shape, None)
             self.assertEqual(func(self.sym2).shape, self.sym2.shape)
Пример #13
0
 def test_gemm(self):
     w = dragon.Tensor((3, 2))
     with dragon.graph_mode():
         self.assertEqual(dragon.math.gemm([self.sym1, w]).shape, None)
         self.assertEqual(
             dragon.math.gemm([self.sym1, w], axis=1).shape, (None, 2))
         self.assertEqual(
             dragon.math.gemm([self.sym1, self.sym1]).shape, None)
Пример #14
0
 def test_concat(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.concat([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.concat([self.sym1, self.sym2]).shape, (None, ))
         self.assertEqual(
             dragon.concat([self.sym2, self.sym3], axis=0).shape, (2, ))
         self.assertEqual(
             dragon.concat([self.sym2, self.sym3], axis=1).shape, None)
Пример #15
0
 def test_reshape(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.reshape(self.sym1, shape=self.shape1).shape, None)
         self.assertEqual(
             dragon.reshape(self.sym2, shape=self.shape1).shape, None)
         self.assertEqual(
             dragon.reshape(self.sym2, shape=self.shape2).shape,
             (None, ) * len(self.shape2))
Пример #16
0
 def test_index_select(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.index_select(self.sym1, self.sym1).shape, None)
         self.assertEqual(
             dragon.index_select(self.sym1, self.sym2, axis=-1).shape, None)
         self.assertEqual(
             dragon.index_select(self.sym3, self.sym2, axis=1).shape,
             (1, 1))
Пример #17
0
 def test_gather_elements(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.gather_elements([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.gather_elements([self.sym1, self.sym2], axis=0).shape,
             self.sym2.shape)
         self.assertEqual(
             dragon.gather_elements([self.sym1, self.sym3], axis=1).shape,
             self.sym3.shape)
Пример #18
0
 def test_stack(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.stack([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.stack([self.sym3, self.sym2]).shape, (2, 1, None))
         self.assertEqual(
             dragon.stack([self.sym3, self.sym3]).shape, (2, 1, None))
         self.assertEqual(
             dragon.stack([self.sym3, self.sym3], axis=-1).shape,
             (1, None, 2))
Пример #19
0
 def test_roi_pool(self):
     rois = dragon.Tensor((2, 5))
     func = functools.partial(dragon.vision.roi_pool,
                              pooled_h=7,
                              pooled_w=7)
     with dragon.graph_mode():
         self.assertEqual(func([self.sym1, rois]).shape, None)
         self.assertEqual(func([self.sym4, rois]).shape, (2, None, 7, 7))
         self.assertEqual(
             func([self.sym4, self.sym1]).shape, (None, None, 7, 7))
Пример #20
0
 def test_transpose(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.transpose(self.sym1).shape, None)
         self.assertEqual(
             dragon.transpose(self.sym1, perm=self.shape1).shape, None)
         self.assertEqual(
             dragon.transpose(self.sym2).shape, self.sym2.shape[::-1])
         self.assertEqual(
             dragon.transpose(self.sym2, perm=self.shape1).shape,
             (None, ) * len(self.sym2.shape))
Пример #21
0
 def test_reduce(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.math.sum(self.sym1).shape, ())
         self.assertEqual(dragon.math.sum(self.sym1, axis=0).shape, None)
         self.assertEqual(
             dragon.math.sum(self.sym1, keepdims=True).shape, ())
         self.assertEqual(dragon.math.sum(self.sym2, axis=0).shape, ())
         self.assertEqual(dragon.math.sum(self.sym2, axis=1).shape, (1, ))
         self.assertEqual(
             dragon.math.sum(self.sym2, axis=0, keepdims=True).shape, (1, ))
Пример #22
0
 def test_predicative(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.math.is_inf(self.sym1).shape, self.sym1.shape)
         self.assertEqual(
             dragon.math.is_inf(self.sym3).shape, self.sym3.shape)
         self.assertEqual(
             dragon.math.is_nan(self.sym1).shape, self.sym1.shape)
         self.assertEqual(
             dragon.math.is_nan(self.sym3).shape, self.sym3.shape)
Пример #23
0
 def test_linspace(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.linspace(start=1, stop=5, num=3).shape, (3, ))
         self.assertEqual(
             dragon.linspace(start=(1, 2), stop=(3, 4), num=3,
                             axis=1).shape, (2, 3))
         self.assertEqual(
             dragon.linspace(start=(1, 2), stop=(3, 4), num=3,
                             axis=0).shape, (3, 2))
Пример #24
0
 def test_channel_norm(self):
     func = functools.partial(dragon.nn.channel_norm,
                              mean=(1., 1., 1.),
                              std=(1., 1., 1.))
     with dragon.graph_mode():
         self.assertEqual(func(self.sym1).shape, None)
         self.assertEqual(func(self.sym1, perm=self.shape1).shape, None)
         self.assertEqual(func(self.sym2).shape, self.sym2.shape)
         self.assertEqual(
             func(self.sym2, perm=self.shape1).shape,
             (None, ) * len(self.sym2.shape))
Пример #25
0
 def test_gemm(self):
     w = dragon.Tensor((3, 2), symbolic=True)
     with dragon.graph_mode():
         self.assertEqual(dragon.math.gemm([self.sym1, w]).shape, None)
         self.assertEqual(
             dragon.math.gemm([self.sym3, w], transpose_a=True).shape,
             (None, 2))
         self.assertEqual(
             dragon.math.gemm([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.math.gemm([w, self.sym1], transpose_b=True).shape, None)
Пример #26
0
 def test_unique(self):
     with dragon.graph_mode():
         self.assertEqual(dragon.unique(self.sym1).shape, (None, ))
         self.assertEqual(
             dragon.unique(self.sym1, return_counts=True)[1].shape,
             (None, ))
         self.assertEqual(
             dragon.unique(self.sym1, return_inverse=True)[1].shape, None)
         self.assertEqual(
             dragon.unique(self.sym1,
                           return_inverse=True,
                           return_counts=True)[1].shape, None)
Пример #27
0
 def test_softmax_loss(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.losses.sparse_softmax_cross_entropy(
                 [self.sym1, self.sym1]).shape, ())
         self.assertEqual(
             dragon.losses.sparse_softmax_cross_entropy(
                 [self.sym1, self.sym1], reduction='none').shape, None)
         self.assertEqual(
             dragon.losses.sparse_softmax_cross_entropy(
                 [self.sym3, self.sym1], reduction='none').shape,
             (self.sym3.shape[0], ))
Пример #28
0
 def test_repeat(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.repeat(self.sym1, axis=None, repeats=2).shape, (None, ))
         self.assertEqual(
             dragon.repeat(self.sym1, axis=0, repeats=2).shape, None)
         self.assertEqual(
             dragon.repeat(self.sym2, axis=None, repeats=2).shape, (2, ))
         self.assertEqual(
             dragon.repeat(self.sym3, axis=0, repeats=2).shape, (2, None))
         self.assertEqual(
             dragon.repeat(self.sym3, axis=1, repeats=2).shape, (1, None))
Пример #29
0
 def test_binary_ops(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.math.add([self.sym1, self.sym1]).shape, None)
         self.assertEqual(
             dragon.math.add([self.sym2, self.sym2]).shape, (1, ))
         self.assertEqual(
             dragon.math.add([self.sym2, self.sym3]).shape, (1, None))
         self.assertEqual(
             dragon.math.add([self.sym3, self.sym2]).shape, (1, None))
         self.assertEqual(
             dragon.math.equal([self.sym1, self.sym1]).shape, None)
Пример #30
0
 def test_broadcast(self):
     with dragon.graph_mode():
         self.assertEqual(
             dragon.broadcast_to(self.sym1, shape=(1, )).shape, None)
         self.assertEqual(
             dragon.broadcast_to(self.sym2, shape=(1, 2)).shape, (1, 2))
         self.assertEqual(
             dragon.broadcast_to(self.sym3, shape=(2, )).shape,
             self.sym3.shape[:-1] + (2, ))
         self.assertEqual(
             dragon.broadcast_to(self.sym3, shape=(-1, 2, 2)).shape,
             (1, 2, 2))